I am trying to extract plankton from a scanned image. 
I segmented plankton using the technique I found here, http://www.mathworks.com/help/images/examples/detecting-a-cell-using-image-segmentation.html
The scheme is not bad, but now I'm not sure how to extract the images so that each individual plankton can be saved separately. I tried to use labels, but there is a lot of noise, and he names every single specification. I am wondering if there is a better way to do this.
Here is my code:
I = imread('plankton_2.jpg'); figure, imshow(I), title('original image'); [~, threshold] = edge(I, 'sobel'); fudgeFactor = .5; BWs = edge(I,'sobel', threshold * fudgeFactor); figure, imshow(BWs), title('binary gradient mask'); se90 = strel('line', 3, 90); se0 = strel('line', 3, 0); BWsdil = imdilate(BWs, [se90 se0]); figure, imshow(BWsdil), title('dilated gradient mask'); BWdfill = imfill(BWsdil, 'holes'); figure, imshow(BWdfill); title('binary image with filled holes'); BWnobord = imclearborder(BWdfill,1); figure, imshow(BWnobord), title('cleared border image'); seD = strel('diamond',1); BWfinal = imerode(BWnobord,seD); BWfinal = imerode(BWfinal,seD); figure, imshow(BWfinal), title('segmented image'); BWoutline = bwperim(BWfinal); Segout = I; Segout(BWoutline) = 0; figure, imshow(Segout), title('outlined original image'); label = bwlabel(BWfinal); max(max(label)) for j = 1:max(max(label)) [row, col] = find(label == j); len = max(row) - min(row)+2; breadth = max(col)-min(col) +2; target = uint8(zeros([len breadth])); sy = min(col)-1; sx = min(row)-1; for i = 1:size(row,1) x = row(i,1)-sx; y = col(i,1) - sy; target(x,y)=I(row(i,1),col(i,1)); end mytitle =strcat('Object Number:',num2str(j)); figure, imshow(target);mytitle; end for j = 1:max(max(label)) [row, col] = find(label == j); len = max(row) - min(row)+2; breadth = max(col)-min(col) +2; target = uint8(zeros([len breadth])); sy = min(col)-1; sx = min(row)-1; for i = 1:size(row,1) x = row(i,1)-sx; y = col(i,1) - sy; target(x,y)=I(row(i,1),col(i,1)); end mytitle =strcat('Object Number:',num2str(j)); figure, imshow(target);mytitle; end