-5

i m trying to extract 360*360 pixels part from an retinal image with center as optical disk's center pixel. please help me with how to find the connected components from an image and then extract the larger one only in matlab.

sanjana
  • 1
  • 2

1 Answers1

1

you can use the following code:

connComp = bwlabel(yourImage); %find the connected components
imageStats = regionprops(connComp,'all'); 
compNumber = size(imageStats);
for i=1:compNumber - 1 % to compare sizes of connected components
   box1 = imageStats(i).BoundingBox;
   compareVar1 = box1(3)*box1(4);
   box2 = imageStats(i+1).BoundingBox;
   compareVar2 = box2(3)*box2(4);
   if compareVar1 > compareVar2
      largestPosition=i;
   end
end
imshow(imageStats(largestPosition).Image) %this is the largest connected component
ammar
  • 121
  • 8