MATLAB: Cut an image based on pixel size

distanceimage analysispixelssegmentationwatershed

Hi All,
Is there a way by which we can separate an image based on pixel size ? Please refer this picture. https://picasaweb.google.com/116243239493929305987/December142011#5685847768746798658
I would like to cut the image say " 200 black pixels boundary to boundary" and I would like to get an output like below.
Is this possible?? Thanks in advance.

Best Answer

You can cut the blob up using morphological operations, as shown below.
A point on terminology: all pixels are the same size (in a conventionally sampled image anyway). The blobs are to be separated based on the width of any "necks" that they have.
The width of the necks in the image as downloaded is much less than the 200 pixels you mention in your example, but maybe your images are actually much larger. To adjust my code, you would change the value of the variable cutsize.
% image downloaded and stored as imorig
imbin = imorig(:,:,1) > max(imorig(:))/2; % binarise
imclean = ~bwareaopen(imbin, 10); % remove dots just inside the edge, and invert
cutsize = 5; % half the thickness of the thickest neck to cut
ime = imerode(imclean, strel('disk',cutsize)); % cut necks
imthick = bwmorph(ime, 'thicken', cutsize); % grow blobs, but don't join up
imsplit = imbin | ~imthick; % split original image