图像处理大作业(用霍夫变换检测硬币及统计硬币个数,并设计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界面) 的相关文章

  • 如何将条形图的 XtickLabels 向左移动?

    我目前正在尝试创建频率直方图 为此 我必须创建一个条形图 条形图之间没有空格 然而 这集中于XTickLabels在酒吧的中间 由于它是一个直方图 我希望数值位于每个条形之间的线上 以便它可以直观地指示间隔 本质上 我需要将所有刻度标签移至
  • 在 3d 空间中的两个平面之间进行插值

    我正在开发一种工具 可以让您在 3D 体积 上圈出 包围事物 我想通过标记 切片 1 和 3 并从该信息 填充 切片 2 来节省时间 两个简单的解决方案是 1 slice2 slice1 AND slice3 gets the overla
  • 在 MATLAB 中使用 FFT 的频率响应

    这是场景 使用频谱分析仪 我有输入值和输出值 样本数是32000采样率为2000样本 秒 输入是正弦波50 hz 输入为电流 输出为压力 单位 psi 我如何使用 MATLAB 根据这些数据计算频率响应 使用 MATLAB 中的 FFT 函
  • MATLAB中如何画水平线和垂直线?

    我目前正在尝试在 MATLAB 中绘制简单的垂直线和水平线 例如 我想绘制线 y 245 我该怎么做呢 MATLAB 根据您提供的向量逐点进行绘图 因此 要创建一条水平线 您需要改变x同时保持y对于垂直线恒定 反之亦然 xh 0 10 yh
  • 扩展 MATLAB 函数名称的最大长度

    我编写了一个 MATLAB 程序 可以动态创建自定义 MATLAB 函数 并使用以下命令在其他 MATLAB 实例中启动它们unix命令 我使用这个程序来自动化 fMRI 神经影像分析 使用 SPM8 for MATLAB 一切正常 但是
  • MATLAB 中最有效的矩阵求逆

    在 MATLAB 中计算某个方阵 A 的逆矩阵时 使用 Ai inv A should be the same as Ai A 1 MATLAB 通常会通知我这不是最有效的求逆方法 那么什么是更有效率的呢 如果我有一个方程系统 可能会使用
  • 如何使用matlab生成不同频率的正弦波?

    对于我的项目 我需要使用 matlab 生成一个正弦波 它有 100 000 个样本 并且频率在每 10 000 个样本后随机变化 采样率和频率可以根据方便而定 matlab中有没有函数可以生成这个 好的另一个例子 生成 5 个随机频率 r
  • 在 matlab 中求 3d 峰的体积

    现在我有一个带有峰值的 3D 散点图 我需要找到其体积 我的数据来自图像 因此 x 和 y 值表示 xy 平面上的像素位置 z 值是每个像素的像素值 这是我的散点图 scatter3 x y z 20 z filled 我试图找到数据峰值的
  • 句柄类和值类的区别

    我有一些 C 背景 想使用 Matlab 中的类 句柄和值类有什么区别 我知道如果我想定义一个带有重载运算符 例如 和 的矩阵类 我会使用值类 然而 有时 当我选择一个手柄类时 事情似乎只对我有用 MathWorks 提供了一些有关其用途的
  • 为什么旋转 3D 点云后顶点法线会翻转?

    我有两个人脸 3D 点云样本 蓝色点云表示目标面 红色点云表示模板 下图显示目标面和模板面在不同方向上对齐 目标面大致沿 x 轴 模板面大致沿 y 轴 Figure 1 The region around the nose is displ
  • 如何找到在matlab中重复的矩阵的每一行的索引?

    我想找到矩阵中所有有重复项的行的索引 例如 A 1 2 3 4 1 2 3 4 2 3 4 5 1 2 3 4 6 5 4 3 要返回的向量将是 1 2 4 很多类似的问题建议使用unique函数 我已经尝试过 但我能得到的最接近我想要的功
  • 如何在 Matlab 中对数组应用低通或高通滤波器?

    有没有一种简单的方法可以将低通或高通滤波器应用于 MATLAB 中的数组 我对 MATLAB 的强大功能 或数学的复杂性 有点不知所措 需要一个简单的函数或一些指导 因为我无法从文档或网络搜索中找到答案 看着那 这filter http w
  • Matlab没有优化以下内容吗?

    我有一个很长的向量 1xrv 和一个很长的向量w1xs 和一个矩阵Arxs 它是稀疏的 但维度非常大 我期望 Matlab 对以下内容进行优化 这样我就不会遇到内存问题 A v w 但看起来 Matlab 实际上是在尝试生成完整的v w矩阵
  • Matlab 和 Python 中的优化算法(dog-leg trust-region)

    我正在尝试使用 Matlab 和 Python 中的狗腿信赖域算法求解一组非线性方程 在Matlab中有fsolve https www mathworks com help optim ug fsolve html其中此算法是默认算法 而
  • 使用符号求解器仅求解某些变量

    我正在尝试在 MATLAB 中求解包含 3 个变量和 5 个常量的方程组 是否可以使用solve求解三个变量 同时保持常量为符号而不用数值替换它们 当您使用SOLVE http www mathworks com access helpde
  • 括号中的波形符字符

    在 MATLAB 中 以下代码执行什么操作 m func returning matrix 波浪号运算符 的作用是什么 在 Matlab 中 这意味着不要将函数中相应的输出参数分配到赋值的右侧 因此 如果func returning mat
  • matlab中类库的全局变量

    我有一些matlab声明的类 我如何声明所有类中都可见的常量 例如 这些常量可以是在所有类的方法中使用的物理常量 首先想到的是使用全局变量 还有更好的办法吗 最好在单独的文件中声明这些常量 包含常量的类是执行此操作的一种很好的干净方法 请参
  • 如何在 matlab 中创建由多个 3d 图像数据数组组成的数组

    我正在阅读 15 张图片imagedata imread imagename jpg 它的大小总是320 by 320 by 3 如何将数据放入数组中 使用 for for 循环 以便在访问新数组的第一个元素时获得输入的第一个图像的 RGB
  • MATLAB - 冲浪图数据结构

    我用两种不同的方法进行了计算 对于这些计算 我改变了 2 个参数 x 和 y 最后 我计算了每种变体的两种方法之间的 误差 现在我想根据结果创建 3D 曲面图 x gt on x axis y gt on y axis Error gt o
  • 在matlab中绘制给定区域内(两个圆之间)的向量场

    我想在 Matlab 中绘制下面的向量场 u cos x x 0 y y 0 v sin x x 0 y y 0 我可以在网格中轻松完成 例如 x 和 y 方向从 2 到 2 x 0 2 y 0 1 x y meshgrid 2 0 2 2

随机推荐

  • 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学习笔记