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); endendD= imfill(B,'holes');K=G | DBB=imclearborder(K);CC=im2bw(BB);figureimshow(CC)bw3 = imopen(CC, ones(20,20));figureimshow(bw3)[centers,radii] = imfindcircles(bw3, [20 300], 'Sensitivity', .8);viscircles(centers, radii, 'DrawBackgroundCircle', false)end
Best Answer