图像处理大作业(用霍夫变换检测硬币及统计硬币个数,并设计GUI界面)

2023-10-30

实现所给硬币图像中的硬币检测及计数

要求完成功能:自行查找、阅读有关的采用Hough变换来检测图像中圆的资料,设计实现所给图像中圆形的检测,要求检测出图像中硬币个数以及各个硬币的直径。

本题难度系数:★★★★

GUI界面设计参考:MATLAB学习笔记(十一)——MATLAB图形用户界面设计

https://www.cnblogs.com/BlueMountain-HaggenDazs/p/4307777.html

我采用了霍夫变换对所给图形进行了检测和统计个数:

原图如下:

检测后的效果:

全部matlab代码如下:

Hough.m文件:

function varargout = Hough(varargin)
% HOUGH MATLAB code for Hough.fig
%      HOUGH, by itself, creates a new HOUGH or raises the existing
%      singleton*.
%
%      H = HOUGH returns the handle to a new HOUGH or the handle to
%      the existing singleton*.
%
%      HOUGH('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in HOUGH.M with the given input arguments.
%
%      HOUGH('Property','Value',...) creates a new HOUGH or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Hough_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Hough_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Hough
% Last Modified by GUIDE v2.5 10-Jan-2019 20:43:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Hough_OpeningFcn, ...
                   'gui_OutputFcn',  @Hough_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Hough is made visible.
function Hough_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Hough (see VARARGIN)

% Choose default command line output for Hough
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Hough wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Hough_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%打开文件
global img
[filename, pathname]= ...
    uigetfile({'*.*';'*.bmp';'*.tif';'*.png';'*.jpg'},'select picture');
str= [pathname filename];
img= imread(str);
axes(handles.axes1);
imshow(img);

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global img;
global Gray;
 img=imresize(img,0.5);
[m,n,l] = size(img);
if l == 3
    Gray = rgb2gray(img);    %如果为彩色图 则转化为灰度图
else
    Gray=img;
end
axes(handles.axes1);
imshow(Gray);

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Gray;
global BW1;
BW1=im2bw(Gray,graythresh(Gray));   %转化为二值图像
axes(handles.axes2);
imshow(BW1)


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global BW1;
BW1=imopen(BW1,strel('disk',3));  %转化为二值图像
axes(handles.axes2);
imshow(BW1)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global BW1;
BW1=imfill(~BW1,'holes');  %填充图像空洞   
axes(handles.axes2);
imshow(BW1)


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%sobel算子边缘检测
global BW1;
BW1 = edge(BW1,'sobel');  
axes(handles.axes2);
imshow(BW1)


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global BW1;
global para;
%hough检测
step_r = str2num(get(handles.edit1, 'String'));
step_angle = str2num(get(handles.edit2, 'String'));
minr =str2num(get(handles.edit3, 'String'));
maxr = str2num(get(handles.edit4, 'String')); 
thresh = str2num(get(handles.edit5, 'String'));

[Hough_Space,Hough_Circle,para] = hough_circle(BW1,step_r,step_angle,minr,maxr,thresh);  
axes(handles.axes2);
imshow(Hough_Circle);


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global para;
global circleParaXYR;
circleParaXYR=para;  
%通过位置求圆心和半径
[r,c]=size(circleParaXYR);
for i=1:r
    a='handles.edit';
    b=5+i;
    c=[a num2str(b)];
    d=[a num2str(5+r+1)];
  set(eval(c),'string',['(' num2str(floor(circleParaXYR(i,1))) ',' num2str(floor(circleParaXYR(i,2))) ')', num2str(2*floor(circleParaXYR(i,3)))]);
  set(eval(d),'string',num2str(r));
end
 

% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%标出圆  
global img;
global circleParaXYR;
axes(handles.axes2);
imshow(img);
hold on;  
 plot(circleParaXYR(:,2), circleParaXYR(:,1), 'r+');  
 for k = 1 : size(circleParaXYR, 1)  
  t=0:0.01*pi:2*pi;  
  x=cos(t).*circleParaXYR(k,3)+circleParaXYR(k,2);y=sin(t).*circleParaXYR(k,3)+circleParaXYR(k,1);  
  plot(x,y,'r-');  
 end  



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit11_Callback(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit11 as text
%        str2double(get(hObject,'String')) returns contents of edit11 as a double


% --- Executes during object creation, after setting all properties.
function edit11_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit12_Callback(hObject, eventdata, handles)
% hObject    handle to edit12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit12 as text
%        str2double(get(hObject,'String')) returns contents of edit12 as a double


% --- Executes during object creation, after setting all properties.
function edit12_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function m_file_Callback(hObject, eventdata, handles)
% hObject    handle to m_file (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function m_file_save_Callback(hObject, eventdata, handles)
% hObject    handle to m_file_save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%保存文件
[FileName,PathName] = uiputfile({'*.jpg','JPEG(*.jpg)';
                                 '*.bmp','Bitmap(*.bmp)';
                                 '*.gif','GIF(*.gif)';
                                 '*.*',  'All Files (*.*)'},'Save Picture','Untitled');
if FileName==0
    return;
else
    h=getframe(handles.axes2);
    imwrite(h.cdata,[PathName,FileName]);
    warndlg('保存成功','保存成功');
end

hough_circle.m文件:

function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p)  
  
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
% input  
% BW:二值图像;  
% step_r:检测的圆半径步长  
% step_angle:角度步长,单位为弧度  
% r_min:最小圆半径  
% r_max:最大圆半径  
% p:阈值,0,1之间的数 通过调此值可以得到图中圆的圆心和半径  
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
% output  
% hough_space:参数空间,h(a,b,r)表示圆心在(a,b)半径为r的圆上的点数  
% hough_circl:二值图像,检测到的圆  
% para:检测到的圆的圆心、半径  
  
circleParaXYR=[];  
para=[];  
  
[m,n] = size(BW);  
size_r = round((r_max-r_min)/step_r)+1;%四舍五入  
size_angle = round(2*pi/step_angle);  
  
hough_space = zeros(m,n,size_r);  
  
[rows,cols] = find(BW);%查找非零元素的行列坐标  
ecount = size(rows);%非零坐标的个数  
  
% Hough变换  
% 将图像空间(x,y)对应到参数空间(a,b,r)  
  
% a = x-r*cos(angle)  
% b = y-r*sin(angle)  
  
for i=1:ecount  
    for r=1:size_r %半径步长数  
        for k=1:size_angle %按一定弧度把圆几等分  
            a = round(rows(i)-(r_min+(r-1)*step_r)*cos(k*step_angle));  
            b = round(cols(i)-(r_min+(r-1)*step_r)*sin(k*step_angle));  
            if(a>0&a<=m&b>0&b<=n)  
            hough_space(a,b,r) = hough_space(a,b,r)+1;%h(a,b,r)的坐标,圆心和半径  
            end  
        end  
    end  
end  
  
  
% 搜索超过阈值的聚集点。对于多个圆的检测,阈值要设的小一点!通过调此值,可以求出所有圆的圆心和半径  
max_para = max(max(max(hough_space)));%返回值就是这个矩阵的最大值  
index = find(hough_space>=max_para*p);%一个矩阵中,想找到其中大于max_para*p数的位置  
length = size(index);%符合阈值的个数  
hough_circle = false(m,n);  
%hough_circle = zeros(m,n);  
%通过位置求半径和圆心。  
for i=1:ecount  
    for k=1:length  
        par3 = floor(index(k)/(m*n))+1;  
        par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;  
        par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;  
        if((rows(i)-par1)^2+(cols(i)-par2)^2<(r_min+(par3-1)*step_r)^2+5&...  
                (rows(i)-par1)^2+(cols(i)-par2)^2>(r_min+(par3-1)*step_r)^2-5)  
              hough_circle(rows(i),cols(i)) = true;   %检测的圆  
        end  
    end  
end                 
  
% 从超过峰值阈值中得到  
for k=1:length  
    par3 = floor(index(k)/(m*n))+1;%取整  
    par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;  
    par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;  
    circleParaXYR = [circleParaXYR;par1,par2,par3];  
    hough_circle(par1,par2)= true; %这时得到好多圆心和半径,不同的圆的圆心处聚集好多点,这是因为所给的圆不是标准的圆  
    %fprintf(1,'test1:Center %d %d \n',par1,par2);  
end  
  
%集中在各个圆的圆心处的点取平均,得到针对每个圆的精确圆心和半径!  
while size(circleParaXYR,1) >= 1  
    num=1;  
    XYR=[];  
    temp1=circleParaXYR(1,1);  
    temp2=circleParaXYR(1,2);  
    temp3=circleParaXYR(1,3);  
    c1=temp1;  
    c2=temp2;  
    c3=temp3;  
    temp3= r_min+(temp3-1)*step_r;  
   if size(circleParaXYR,1)>1       
     for k=2:size(circleParaXYR,1)  
      if (circleParaXYR(k,1)-temp1)^2+(circleParaXYR(k,2)-temp2)^2 > temp3^2  
         XYR=[XYR;circleParaXYR(k,1),circleParaXYR(k,2),circleParaXYR(k,3)];  %保存剩下圆的圆心和半径位置  
      else    
      c1=c1+circleParaXYR(k,1);  
      c2=c2+circleParaXYR(k,2);  
      c3=c3+circleParaXYR(k,3);  
      num=num+1;  
      end   
    end  
   end   
      %fprintf(1,'sum %d %d radius %d\n',c1,c2,r_min+(c3-1)*step_r);  
      c1=round(c1/num);  
      c2=round(c2/num);  
      c3=round(c3/num);  
      c3=r_min+(c3-1)*step_r;  
      %fprintf(1,'num=%d\n',num)  
      %fprintf(1,'Center %d %d radius %d\n',c1,c2,c3);     
      para=[para;c1,c2,c3]; %保存各个圆的圆心和半径的值  
      circleParaXYR=XYR;  
end 

以上完整源码仅供参考,此次任务小组合作完成,所以博主对以上代码一些部分不是很了解,谢谢合作。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

图像处理大作业(用霍夫变换检测硬币及统计硬币个数,并设计GUI界面) 的相关文章

  • 图像梯度角计算

    我实际上是按照论文的说明进行操作的 输入应该是二进制 边缘 图像 输出应该是一个新图像 并根据论文中的说明进行了修改 我对指令的理解是 获取边缘图像的梯度图像并对其进行修改 并使用修改后的梯度创建一个新图像 因此 在 MATLAB Open
  • matlab 中的动画绘图

    我正在尝试创建一个三角形的动画图 最终结果应该是十个三角形 后面跟着两个更大的三角形 后面跟着一条直线 使用matlab文档 https de mathworks com help matlab ref drawnow html 我最终得到
  • 更新:随机将行添加到矩阵中,但遵循严格的规则

    以下是一个更大的矩阵的一部分 0 1 0000 1 0000 77 0000 100 0000 0 0 2500 0 1 0000 1 0000 72 0000 100 0000 0 2500 0 2500 0 1 0000 1 0000
  • 绘制布朗运动 matlab

    首先 我只想说我不太习惯使用matlab 但我需要一个作业 我应该创建一个 布朗运动 我的代码目前如下所示 clf hold on prompt Ge ett input size input prompt numParticles inp
  • 在矩阵中找到叉的最快方法

    定义 A i j 1 是十字的中点 如果元素A i 1 j 1A i 1 j 1A i j 1 1A i j 1 1 这些元素和中点一起形成矩阵 A 中的十字 其中 A 至少是一个 3 3 矩阵 并且i j 0 假设上图是 8 8 矩阵 A
  • MATLAB问题:在图块中引用变量的值[重复]

    这个问题在这里已经有答案了 可能的重复 matlab 绘图标题中的变量 https stackoverflow com questions 5629458 matlab variable in plot title 我想在图中引用 m 文件
  • 如何在Matlab中将图像从笛卡尔坐标更改为极坐标?

    我正在尝试将图像的像素从 x y 坐标转换为极坐标 但我遇到了问题 因为我想自己编写该函数 这是我到目前为止所做的代码 function newImage PolarCartRot read and show the image image
  • 图像处理方面的空间和时间表征有什么区别?

    我是学习图像处理的初学者 我对空间和时间表征的概念有点困惑 那么 对于空间表征来说 是不是像一张二维地图 包含了一些关于地图的统计信息呢 就时间特征而言 值是相对于时间的吗 这意味着什么以及我们为何关心 谢谢 当您在不同时间拍摄一系列图像时
  • 基本矩阵错误?

    我试图通过扫描从相机拍摄的两个图像 检测图像中的特征 匹配它们 创建基本矩阵 使用相机内在函数计算基本矩阵 然后分解它以找到旋转和翻译 这是matlab代码 I1 rgb2gray imread 1 png I2 rgb2gray imre
  • Matlab下降低图像质量

    问候 我正在尝试找到一种简单的方法来处理图像 以便将其质量从 8 位降低到 3 位 实现这一目标的最简单方法是什么 干杯 如果要线性缩放 只需将每个像素值除以 255 7 即 如果原始图像存储在矩阵 I 中 则让低分辨率图像 J I 255
  • 在 MATLAB 中验证输入的最佳实践

    在验证 MATLAB 函数中的输入时 什么时候使用 inputParser 比使用断言更好 或者还有其他更好的工具可用吗 我个人发现使用 inputParser 不必要地复杂 对于 Matlab 始终需要检查 3 项内容 存在 类型和范围
  • GO TO 语句 - Fortran 到 Matlab

    我一直在努力将此网格搜索代码从 Fortran 转换为 Matlab 但是我无法正确合并 GO TO 语句 我正在尝试使用 while 循环 但我认为我需要其他东西来结束搜索 任何帮助将不胜感激 vmax 1 0E 15 amax G 1
  • 计算向量的导数

    我有以下函数 维维亚尼曲线 Phi t cos t 2 cos t sin t sin t 只需检查它是否有效 s linspace 0 T 1000 plot3 cos s 2 cos s sin s sin s 如何推导函数Phi 可能
  • 使用网络计算机进行 Matlab 并行处理

    我熟悉matlabpool and parfor用法 但我仍然需要加快计算速度 我的 1GB 网络中有一台功能更强大的计算机 两台计算机都有 R2010b 并且具有相同的代码和路径 使用两台计算机进行并行计算的最简单方法是什么 我今天使用的
  • Matlab 错误:()-索引必须出现在索引表达式的最后

    我有这段代码 想要在制表符分隔的 txt 文件中写入一个数组 fid fopen oo txt wt for x 1 length s fprintf fid s t n s x 1 end fclose fid 但我收到此错误 Error
  • 从 3 个向量创建等值线图

    我正在尝试根据这些数据创建等高线图 pH D Tur 5 10 3 79 18918919 5 50 6 92 97297297 5 00 0 50 09009009 5 00 6 90 36036036 5 10 9 91 0810810
  • 如何在 MATLAB 中为 4 个子图创建一个通用图例?

    如何在 MATLAB 中为 4 个子图创建一个通用图例 如下所示 又快又脏 hSub subplot 3 1 1 plot 1 1 1 1 1 1 1 1 hLegend legend hello i am legend subplot 3
  • 如何使用神经网络保存 Sift 特征向量进行分类

    SIFT 特征的 Matlab 实现发现于http www cs ubc ca lowe keypoints http www cs ubc ca lowe keypoints 在 stackoverflow 的帮助下 我想将功能保存到 m
  • Matlab 中的多行匿名函数? [复制]

    这个问题在这里已经有答案了 是否可以在 Matlab 中创建多行匿名函数 没有合适的例子在文档中 http www mathworks com help matlab matlab prog anonymous functions html
  • ODE 时间 Matlab 与 R

    如果在 matlab 中使用可变时间步长求解器 例如 ODE45 我会定义输出的时间跨度 即times 0 50 matlab 将返回 0 到 50 之间不同时间步长的结果 然而在 R 中 我似乎必须定义我希望 ODE 返回结果的时间点 即

随机推荐

  • CSS —— 盒模型

    概念 CSS 盒模型本质上是一个盒子 盒子包裹着HTML 元素 盒子由四个属性组成 从内到外分别是 content 内容 padding 内填充 border 边框 外边距 margin 盒模型的分类 W3C 盒子模型 标准盒模型 IE盒子
  • Unity之性能分析特别篇

    Unity的性能优化大家一定很熟悉了 我在Unity4 5的时期 做过多款大型在线射击对战类网游 超大地形加载优化 对性能分析优化工作和在使用Profiler的过程中总结了一些经验 今天才有空分享出来 欢迎大家讨论 和提出不同的见解 给Un
  • 无法访问javax.servlet.ServletException

    使用Idea CE 创建了一个基于 Maven 构建的 Spring Boot 项目 在打包的时候提示 无法访问javax servlet ServletException 完整错误信息 ERROR Failed to execute go
  • Spring3学习笔记之(spring core之IoC容器基本原理)

    IoC容器的概念 IoC容器就是具有依赖注入功能的容器 IoC容器负责实例化 定位 配置应用程序中的对象及建立这些对象间的依赖 应用程序无需直接在代码中new相关的对象 应用程序由IoC容器进行组装 在Spring中BeanFactory是
  • C++ “error LNK1169: 找到一个或多个多重定义的符号”的解决方法

    原文链接 https blog csdn net m LeonWANG article details 37598807 这是一个链接时候检查到的错误 大概有下面两种情况会引起这个错误 第一种 1 变量定义 A h中声明了变量a 非类成员变
  • Kylin问题解决

    1 libLLVM 7 so不是符号链接 root t60 ldconfig v ldconfig usr lib64 libLLVM 7 so 不是符号链接 解 root t60 ln sf usr lib64 libLLVM 7 0 0
  • eKuiper 1.10.0 发布:定时规则和 EdgeX v3 适配

    经过为期两个月的开发 我们很高兴地宣布 eKuiper 1 10 0 现已正式发布 作为一个里程碑版本 eKuiper 1 10 0 升级了基础依赖的版本 如 Go 语言版本升级到 1 20 EdgeX 支持最新的大版本 Minnesota
  • layui自定义打印

    效果图如下 自定义内容导出 自定义表格导出 目录 一 自带的打印功能的实现 1 下载新的layui的js文件 2 添加toolbar参数 3 最终打印图标显示 4 点击打印图标 实现打印效果 5 隐藏打印功能 二 自定义打印内容的实现 1
  • nginx proxy_pass规则

    文章目录 nginx部分配置格式 proxy pass规则 1 proxy pass不带url情况 2 proxy pass带url情况 总结 以下附带一个简单的伪代码 新领悟 nginx部分配置格式 server listen 5000
  • 大数据从入门到精通(超详细版)之Hive的DQL操作,学不会算我输!!!

    前言 嗨 各位小伙伴 恭喜大家学习到这里 不知道关于大数据前面的知识遗忘程度怎么样了 又或者是对大数据后面的知识是否感兴趣 本文是 大数据从入门到精通 超详细版 的一部分 小伙伴们如果对此感谢兴趣的话 推荐大家按照大数据学习路径开始学习哦
  • 达梦实现高可用性的实现(failover功能/负载均衡/虚拟ip透明切换)

    达梦实现高可用性的实现 failover功能 负载均衡 虚拟ip透明切换 一 failover功能 基于守护进程和监视器两个内在工具实现 守护进程 监视器 数据守护和读写分离集群 共享存储集群 二 负载均衡 基于jdbc接口和客户端实现读写
  • XSS-Game level 11

    第十一关通过 Referer 利用事件绕过 先看源码 本关有三个参数 keyword 使用 htmlspecialchars 转译 并输出到页面 难度较大 第二个参数 t sort 使用 htmlspecialchars 转译后拼接到 va
  • Dubbo服务控制台Dubbo Admin配置

    Dubbo服务使用Zookeeper作为服务注册中心 Zookeeper对我们来讲是一个黑框 我们无法看到是否存在了什么提供者或消费者 阿里巴巴官方提供了一个Dubbo服务的管理平台Dubbo Admin 提供路由规则 动态配置 服务降级
  • 开源中国iOS客户端学习——(十二)用户登陆

    上一篇博客 开源中国iOS客户端学习 十一 AES加密 中提到将用户名和密码保存到了本地沙盒之中 在从本地读取用户名和密码 这是一个怎样的过程 cpp view plain copy void saveUserNameAndPwd NSSt
  • 《wireshark》怎么抓包

    wireshark是非常流行的网络封包分析软件 功能十分强大 可以截取各种网络封包 显示网络封包的详细信息 可能很多朋友还不知道wireshark怎么抓包 为此小编给大家带来了wireshark抓包教程 不知道的朋友一起来看看吧 iresh
  • leetcode zigzag C++ 争取每日一题,我还是太天真了/(ㄒoㄒ)/~~

    include
  • 数字信号谱估计方法对比仿真——估计自相关,周期图法,协方差法,burg算法,修正协方差法

    目录 一 理论基础 1 1自相关谱估计 1 2周期图法谱估计 1 3协方差法谱估计 1 4burg算法谱估计 1 5修正协方差谱估计 二 核心程序 三 仿真结论 一 理论基础 自相关谱估计 周期图法谱估计 协方差法谱估计 Burg算法谱估计
  • 如何在两天之内写出一篇学术论文:Pete Carr 教授的高效写作秘籍

    文章目录 一 前言 二 主要内容 三 总结 CSDN 叶庭云 https yetingyun blog csdn net 一 前言 随着科研的不断发展 研究论文已成为每位学者不可或缺的 利器 然而 撰写一篇既有深度又有广度的研究论文却是一项
  • leetcode99-恢复二叉搜索树(两个空间复杂度的解法)

    恢复二叉搜索树 题目 给你二叉搜索树的根节点 root 该树中的 恰好 两个节点的值被错误地交换 请在不改变其结构的情况下 恢复这棵树 示例 思路 嘶 递归递了加一起得两个点 笔试的题是 交换了若干个相邻结点的 恢复成一颗二叉搜索树 估计就
  • 图像处理大作业(用霍夫变换检测硬币及统计硬币个数,并设计GUI界面)

    实现所给硬币图像中的硬币检测及计数 要求完成功能 自行查找 阅读有关的采用Hough变换来检测图像中圆的资料 设计实现所给图像中圆形的检测 要求检测出图像中硬币个数以及各个硬币的直径 本题难度系数 GUI界面设计参考 MATLAB学习笔记