Clearing border components from an imfreehand ROI

조회 수: 7 (최근 30일)
Ramin Dastanpour
Ramin Dastanpour 2015년 9월 30일
편집: Ramin Dastanpour 2015년 10월 1일
I have a binary image with an ROI defined using imfreehand function; and I want to remove object touching the ROI border. imclearborder is a great function to remove border objects but it works for rectangular ROI. What is the less-costly method to do this? I tried using the freehand ROI border and "bwconncomp" function but it requires multiple loops which is costly for a big image.

채택된 답변

Ramin Dastanpour
Ramin Dastanpour 2015년 10월 1일
편집: Ramin Dastanpour 2015년 10월 1일
Thanks for the help. I dug a bit more and found a trick to get what I wanted. This is what I have used:
% Build a location array for the pixels on the edge of the freehand curve
% lassoxy.i and lassoxy.j are the index positions of the freehand curve.
% Img is the binary image produced by masking the original image by imfreehand.
locationxy=(lassoxy.j-1)*size(Img,1)+lassoxy.i;
% Use flood-fill operation to remove blobs touching the boundary (inside) of the freehand curve (negative binary image)
BW2 = imfill(~Img,locationxy);
Img_Bord = ~BW2; % Img_Bord is the binary image with all blobs touching the ROI edge removed.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 9월 30일
편집: Image Analyst 2015년 9월 30일
First of all imclearborder() works for any blobs of any shape, not just rectangular. Secondly, imclearborder removes blobs touching the border of the image, not blobs touching the border of some freehand curve you drew.
I'm not sure what you want to do. Do you want to remove any blobs that your freehand curve touches or passes through?
If you just want to blacken the freehand mask pixels from your other binary image of your blobs, then you can just set the binary image to false inside the mask
blobsBinaryImage(freehandMask) = false;
  댓글 수: 4
Image Analyst
Image Analyst 2015년 9월 30일
Ramin's "Answer" was really a comment so I moved it here:
Well, this is an image from graphite layers inside a carbon nanoparticle. The image is masked by freehand to separate ROI from the other parts of the image. The freehand is a closed curve and I want to remove all objects touching the interior of this curve. I have different images and for each image a different ROI should be used.
Image Analyst
Image Analyst 2015년 9월 30일
편집: Image Analyst 2015년 9월 30일
Ramin: See my attached imfreehand masking demos and see if this is what you want. Again, "touching" the cirve itself, or the interior of it as you said (whatever that means) is different than removing all blobs inside the curve. It's like removing only the perimeter blobs versus ALL the blobs inside.

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

카테고리

Help CenterFile Exchange에서 Build Interactive Tools에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by