How to plot cirlces around this spots..?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have this image of blood cells. I want to draw circles around it..
The code is :
im = imread('image.jpg');
im = im(:,:,3);
minR=34; maxR=40; thresh=0.33; delta=12;
origim = im;
if length(size(im))>2
im = rgb2gray(im);
end
maxR2 = 2*maxR;
hough = zeros(size(im,1)+maxR2, size(im,2)+maxR2, maxR-minR+1);
[X Y] = meshgrid(0:maxR2, 0:maxR2);
Rmap = round(sqrt((X-maxR).^2 + (Y-maxR).^2));
Rmap(Rmap<minR | Rmap>maxR) = 0;
edgeim = edge(im, 'canny', [0.1 0.2]);
[Ey Ex] = find(edgeim);
[Cy Cx R] = find(Rmap);
for i = 1:length(Ex);
Index = sub2ind(size(hough), Cy+Ey(i)-1, Cx+Ex(i)-1, R-minR+1);
hough(Index) = hough(Index)+1;
end
twoPi = 0.9*2*pi;
circles = zeros(0,4);
for radius = minR:maxR
slice = hough(:,:,radius-minR+1);
twoPiR = twoPi*radius;
slice(slice<twoPiR*thresh) = 0;
[y x count] = find(slice)
circles = [circles; [x-maxR, y-maxR, radius*ones(length(x),1), count/twoPiR]];
end
circles = sortrows(circles,-4);
i = 1;
while i<size(circles,1)
j = i+1;
while j<=size(circles,1)
if sum(abs(circles(i,1:3)-circles(j,1:3))) <= delta
circles(j,:) = [];
else
j = j+1;
end
end
i = i+1;
end
if nargout==0 % Draw circles
figure, imshow(origim), hold on;
for i = 1:size(circles,1)
x = circles(i,1)-circles(i,3);
y = circles(i,2)-circles(i,3);
w = 2*circles(i,3);
rectangle('Position', [x y w w], 'EdgeColor', 'red', 'Curvature', [1 1]);
end
hold off;
end
But it is not working.. Can anyone help to solve this..? please help..
2 commentaires
Star Strider
le 6 Août 2014
Image processing isn’t an area of my expertise, but your image is.
What do you mean by ‘spots’? You have one polymorphonuclear leukocyte, and a large number of largely abnormal erythrocytes. The small ‘spots’ within the red cells are Howell-Jolly bodies (remnant DNA normally eliminated in the spleen), and the red cells that do not contain them are spherocytes (smaller than normal red cells lacking the normal central concavity).
Do you want to identify the red cells (and estimate their sizes), the Howell-Jolly bodies, or something else?
Réponses (2)
Dasharath Gulvady
le 5 Août 2014
Modifié(e) : Dasharath Gulvady
le 5 Août 2014
Nimisha, By executing your code, I could see that the resulting "circles" is a 0-by-1 empty matrix. It looks like the issue is with the values of the variables “thresh”,” minR”, “maxR” which are hardcoded. Refer to my comments below for one of the for-loops, where I think the issue is:
for radius = minR:maxR
slice = hough(:,:,radius-minR+1); % why is minR hard coded?
twoPiR = twoPi*radius ;
% values in "slice" are small compared to the value "twoPiR*thresh". Hence the resulting "slice" will contain all zeros.
slice(slice<twoPiR*thresh) = 0;
% Since "slice" has all zeros, x and y are empty matrices
[y x count] = find(slice);
% Since x and y are empty matrices, "circles" is an empty matrix
circles = [circles; [x-maxR, y-maxR, radius*ones(length(x),1), count/twoPiR]];
%circles
end
I would suggest taking a look at the hard coded values at the beginning of your code and change them appropriately. Since the code is pretty big, feel free to add some comments in your code which would help in understanding what exactly you are trying to achieve and how you are doing it.
0 commentaires
Image Analyst
le 6 Août 2014
Modifié(e) : Image Analyst
le 6 Août 2014
Have you tried imfindcircles? Here is Brett's demo: http://www.mathworks.com/matlabcentral/fileexchange/34365-findcirclesgui (Brett works at The Mathworks)
But what do you REALLY want to do? I'm sure drawing circles it not it - that's not useful. Do you want the count, the average equivalent circular diameter, the area fraction, or what??? How about doing color segmentation like I show you in my File Exchange. Or maybe you want to do something like this: http://www.mathworks.com/products/demos/image/color_seg_k/ipexhistology.html
2 commentaires
Image Analyst
le 7 Août 2014
Just attach the script with the paper clip icon, or else read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!