count=1; bw2=bwlabel(closezn); CC2 = bwconncomp(bw2); %// Find connected components. L52 = labelmatrix(CC2); for objectidx2 = 1:CC2.NumObjects individualsilheouts2 = bsxfun(@times, closezn, L52 == objectidx2); %requires R2016b or later. earlier versions: maskedimage = bsxfun(@times, A, L == objectidx); [labeledImage2,numberofBlobs2] = bwlabel(individualsilheouts2,4); Aa=individualsilheouts2; s2= regionprops(Aa, 'Centroid'); Centroid2 = [s2.Centroid]; %xlop(1:2,objectidx2)=[s2.Centroid]; aax=size(Aa); if(count==1) check1=aax; %finalx1(1:2,xx)=xlop(1:2,xx); Centroid1cc = [s2.Centroid]; end if (check1==aax) % printf(1st connected component); %if (finalx1(1:2,xx)==xlop(1:2,xx)) if (Centroid1cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==2) check2=aax; Centroid2cc = [s2.Centroid]; end if(check2==aax) %printf(2nd CC); if (Centroid2cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==3) check3=aax; Centroid3cc = [s2.Centroid]; end if (check3==aax) %printf(3 CC); if (Centroid3cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==4) check4=aax; Centroid4cc = [s2.Centroid]; end if (check4==aax) %printf(4 CC); if (Centroid4cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==5) check5=aax; Centroid5cc = [s2.Centroid]; end if (check5==aax) %printf(5 CC); if (Centroid5cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==6) check6=aax; Centroid6cc = [s2.Centroid]; end if (check6==aax) %printf(6 CC); if (Centroid6cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==7) check7=aax; Centroid7cc = [s2.Centroid]; end if (check7==aax) %printf(7 CC); if (Centroid7cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==8) check8=aax; Centroid8cc = [s2.Centroid]; end if (check8==aax) %printf(8 CC); if (Centroid8cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==9) check9=aax; Centroid9cc = [s2.Centroid]; end if (check9==aax) %printf(9 CC); if (Centroid9cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==10) check10=aax; Centroid10cc = [s2.Centroid]; end if (check10==aax) %printf(10 CC); if (Centroid10cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==11) check11=aax; Centroid11cc = [s2.Centroid]; end if (check11==aax) %printf(11 CC); if (Centroid11cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end if(count==12) check12=aax; Centroid12cc = [s2.Centroid]; end if (check12==aax) %printf(12 CC); if (Centroid12cc==Centroid2) closezn(CC1.PixelIdxList{objectidx2}) = 0; end end coun=count+1; end figure,imshow(closezn, 'InitialMagnification', 'fit'); %figure,imshow(img, 'InitialMagnification', 'fit');