0
$\begingroup$

I am new to image processing and try to learn how to detect circles using the hough transform in Matlab. I have a shortcode that seems to contain no errors but when I run it I get the image but with no circle detected. I expect the code to detect the circle. Is there something wrong when I used imshow(I)? Here is the code

%Hough Transform for Circles
[I,map]=imread('screw.jpg');
colormap(map);
Io=rgb2gray(I); %change image to grayscale
Io=edge(Io,'canny'); %Canny filter

%image size
[rows,columns]=size(I);
a = 5;
r = 0.5;

%accumulator
acc=zeros(rows,columns);

%image
for x=1:columns
  for y=1:rows
    if(I(y,x)==0)
      for ang=0:360
        t=(ang*pi)/180;
        x0=round(x-a*cos(t));
        y0=round(y-r*sin(t));
        if(x0 && y0)
          acc(y0,x0)=acc(y0,x0)+1;
        end
      end
    end
  end

end
figure(1)
imshow(I), hold on;
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.