how to encircle the blue objects and separating them?
Afficher commentaires plus anciens
i am trying to separate the blue/violet object in the "testimage" and to count them. but the way i tried encircling the objects does not encircle the blue objects (may be its not exactly circular, that's why) see ("result"). if some one could help me to separate the connected object if possible like the desired(e) image i've attached.
testimage

if true
A=imread('testimage.jpg);
E=rgb2gray(A);
level = graythresh(E)
B= im2bw(E,level);
H=~B;
G= imfill(H,'holes');
C=double(B);
for i=1:size(C,1)-2
for j=1:size(C,2)-2
%Sobel mask for x-direction:
Gx=((2*C(i+2,j+1)+C(i+2,j)+C(i+2,j+2))-(2*C(i,j+1)+C(i,j)+C(i,j+2)));
%Sobel mask for y-direction:
Gy=((2*C(i+1,j+2)+C(i,j+2)+C(i+2,j+2))-(2*C(i+1,j)+C(i,j)+C(i+2,j)));
%The gradient of the image
%B(i,j)=abs(Gx)+abs(Gy);
B(i,j)=sqrt(Gx.^2+Gy.^2);
end
end
D= imfill(B,'holes');
K=G | D
BB=imclearborder(K);
CC=im2bw(BB);
figure
imshow(CC)
bw3 = imopen(CC, ones(20,20));figure
imshow(bw3)
[centers,radii] = imfindcircles(bw3, [20 300], 'Sensitivity', .8);
viscircles(centers, radii, 'DrawBackgroundCircle', false)
end
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 16 Août 2015
0 votes
You should use color segmentation followed by bwboundaries(). See my File Exchange for color segmentation tutorials. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 You should probably start with the HSV method. Post your adapted code when/if you run into problems.
5 commentaires
ahasan ratul
le 16 Août 2015
Modifié(e) : ahasan ratul
le 16 Août 2015
Image Analyst
le 16 Août 2015
I'm not sure I understand. You have light reddish background, rose colored objects, light purple objects, and dark purple objects. I don't see blue objects. What color objects did you threshold for? And you forgot to attach your code to make it easy for me to help you.
The delta E method asked you to freehand draw a sample in the image that you want to extract. If you don't want to do that, just identify thresholds in the HSV segmentation demo.
Have you tried the "Color Thresholder" app on the "Apps" tab?
ahasan ratul
le 16 Août 2015
Image Analyst
le 16 Août 2015
Where is the mask? Is it in the spatial domain of your original image? That won't work because the cells will be in different places in other images. Best is to just use fixed thresholds in the HSV color space. Here is your image looking down onto the HS plane:

If looks like you can get purple by thresholding at less than 0.1 or more than 0.7 and dark purple has an S of more than about 0.2 and light purple is between 0.05 and 0.2, or something around there.
hsvImage = rgb2hsv(rgbImage);
h = hsvImage(:,:,1);
s = hsvImage(:,:,2);
v = hsvImage(:,:,3);
h_mask = h < 0.1 | h > 0.7;
s_mask_darkPurple = s > 0.2; % or whatever works.
s_mask_lightPurple = s > 0.05 & s < 0.2; % or whatever works.
% Get overall mask
darkPurple = h_mask & s_mask_darkPurple;
lightPurple = h_mask & s_mask_lightPurple;
% Mask back in RGB color space
% Mask the image using bsxfun() function
maskedDarkPurple = bsxfun(@times, rgbImage, cast(darkPurple, class(rgbImage)));
maskedLightPurple = bsxfun(@times, rgbImage, cast(lightPurple, class(rgbImage)));
Image Analyst
le 17 Août 2015
OK, try the attached code. It does a decent job of getting the purple.
Catégories
En savoir plus sur Image Segmentation dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
