Hi am doing a project on detection of the optic disc from retinal images using circular hough transfrom.but i am not getting a proper output.a function call detecting the midpoint of the circle was wriiten and Bresenham line algorithm is used
Show older comments
for drawing the circles.to find the local maxima thresholding was used. here is my program
clear;
%Load image
temp = imread('C:\Users\user\Desktop\7.jpg');
%create new window
figure;
i=imresize(temp,[256 256],'nearest');
%show image in figure
imshow(i)
%rgb to grayconversion
gray=rgb2gray(i);figure,imshow(gray);
%create new image and do canny edge detection
bw = edge(gray,'canny', 0.3);
%create new figure
figure;
%show new image in new window
imshow(bw);
%define rmax and cmax as the width and height of the image
[rmax, cmax] = size(bw);
%define a list of radii to look for
radius = [26];
% Pre-allocate array
hough = zeros(rmax, cmax, size(radius,2));
zeroArray = zeros(rmax, cmax, size(radius,2));
for rad = 1:size(radius,2); % Loop over radii
for row = 1:rmax; % Loop over rows
for col = 1:cmax; % Loop over columns
if(bw(row,col) == 1 && row > radius(rad) && col>radius(rad) &&
col < cmax-radius(rad) && row<rmax-radius(rad))
circle = MidpointCircle(zeroArray(:, :, rad), radius(rad),
row, col, 1);
hough(:, :, rad) = hough(:, :, rad) + circle;
end;
end
end
end
%Create RGB image from grayscale
newImage = zeros(rmax, cmax, 3);
newImage(:,:,1) = gray;
newImage(:,:,2) =gray;
newImage(:,:,3) = gray;
%Normalize the images.
newImage = normalize(newImage);
hough = normalize(hough);
for rad = 1:size(radius,2);
%Output a figure for each radii with the accumulated data
figure;
output = hough(:,:,rad);
imshow(output);
for row = 1:rmax; % Loop over rows
for col = 1:cmax; % Loop over columns
% threshold the image and draw the solution if found.
if (output(row, col) > 0.5)
foundCircle = MidpointCircle(newImage(:,:,1), radius(rad),
row, col, 1);
newImage(:,:,1) = foundCircle;
end;
end;
end;
end;
% Display the result
figure;
imshow(newImage);
function prgm for finding midpoint
% MidtpointCircle.m
% Draws a circle in a discrete image.
function i = MidpointCircle(i, radius, xc, yc, value)
xc = int16(xc);
yc = int16(yc);
x = int16(0);
y = int16(radius);
d = int16(1 - radius);
i(xc, yc+y) = value;
i(xc, yc-y) = value;
i(xc+y, yc) = value;
i(xc-y, yc) = value;
while ( x < y - 1 )
x = x + 1;
if ( d < 0 )
d = d + x + x + 1;
else
y = y - 1;
a = x - y + 1;
d = d + a + a;
end
i( x+xc, y+yc) = value;
i( y+xc, x+yc) = value;
i( y+xc, -x+yc) = value;
i( x+xc, -y+yc) = value;
i(-x+xc, -y+yc) = value;
i(-y+xc, -x+yc) = value;
i(-y+xc, x+yc) = value;
i(-x+xc, y+yc) = value;
end
function program to normalize
% Normalizes the matrix, so that all the values will be
% included in the interval [0 1]
function result=normalize( matrix )
Nor = matrix - min( matrix(:) );
result = Nor / max( Nor(:) );
please help me with circular hough transform. i tried the functions given in mathworks for circular hough transform. but not getting output properly.
3 Comments
David Young
on 17 Oct 2011
Thanks for formatting. This looks very reasonable - please can you say what goes wrong when you run it. Do you get an error message, or are the circles detected in the wrong place?
Also, have a look at the circular HT functions on the file exchange - there are several that may help you.
gayathri
on 17 Oct 2011
usman ali
on 13 Mar 2015
can you pls send the input image for your coding
Answers (2)
gayathri
on 17 Oct 2011
0 votes
Fangjun Jiang
on 17 Oct 2011
The error is due to, well, "Subscripted assignment dimension mismatch".
Try this example to see it:
a=zeros(3,4);
a(:,1)=rand(5);
Put a break point at the line where the error happened, then check the size of the right hand variable and left hand variable.
size(foundCircle)
size(newImage(:,:,1))
Do they match?
Categories
Find more on ROI-Based Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!