Clearing border components from an imfreehand ROI

4 次查看(过去 30 天)
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 中查找有关 Image Segmentation and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by