Cut an image based on pixel size

1 Ansicht (letzte 30 Tage)
Shan  Kapoor
Shan Kapoor am 14 Dez. 2011
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.

Akzeptierte Antwort

David Young
David Young am 14 Dez. 2011
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
  1 Kommentar
Shan  Kapoor
Shan Kapoor am 14 Dez. 2011
Shan Kapoor less than a minute ago Delete
Hi David,
This code solves my problem to an extend. I was trying an ImageJ plugin http://www.gcsca.net/IJ/Shapes.html combined with watershed segmentation ( watershed and remove clusters of pixels less than a certain range). this code works as a replacement to that. thank you for sharing.
Regards,
Shanoob

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by