Clearing border components from an imfreehand ROI

7 visualizaciones (últimos 30 días)
Ramin Dastanpour
Ramin Dastanpour el 30 de Sept. de 2015
Editada: Ramin Dastanpour el 1 de Oct. de 2015
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.

Respuesta aceptada

Ramin Dastanpour
Ramin Dastanpour el 1 de Oct. de 2015
Editada: Ramin Dastanpour el 1 de Oct. de 2015
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.

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Sept. de 2015
Editada: Image Analyst el 30 de Sept. de 2015
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 comentarios
Image Analyst
Image Analyst el 30 de Sept. de 2015
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 el 30 de Sept. de 2015
Editada: Image Analyst el 30 de Sept. de 2015
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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by