Cut an image based on pixel size

조회 수: 1 (최근 30일)
Shan  Kapoor
Shan Kapoor 2011년 12월 14일
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.

채택된 답변

David Young
David Young 2011년 12월 14일
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
Shan  Kapoor
Shan Kapoor 2011년 12월 14일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by