How to fill the regions within the traced boundry using "bwboundaries"

Hi, I am using bwboundaries to trace the boundaries. I want to know,how to fill the traced region alone with white pixels.

 Respuesta aceptada

Dishant Arora
Dishant Arora el 19 de Feb. de 2014
Editada: Dishant Arora el 19 de Feb. de 2014
b=imfill(b,'holes');

4 comentarios

Sir,I want to analyze only the pixels within the traced region. So I am need to create a binary mask of the traced region among other regions. This imfill fills the entire binary region not only the traced region.
b=bwboundaries(bw); % bw is your binary image you want to operate on
binaryMask=false(size(bw));
for i = 1:length(b)
for j = 1:length(b{i})
ind = b{i}(j,:);
binaryMask(ind(1),ind(2))=1;
end
end
figure
imshow(binaryMask)
hopethis is what you are looking for.
Thank you sir @ Dishant Arora. This code gives boundary binary mask,is it possible to fill the region within the boundary likewise?
imfill will do.

Iniciar sesión para comentar.

Más respuestas (1)

filledImage = poly2mask(xBoundaries, yBoundaries, rows, columns);

6 comentarios

Since you must already have the binary image, why use bwboundaries if all you want to do is to fill holes. You can do
filledImage = imfill(binaryImage, 'holes');
No call to bwboundaries() is needed, unless you need it for some other reason.
Since 'bwboundries' gives only the boundary pixels in a cell array format,I cant to able to segment it seperately. To proceed further I am in need to create binary mask to that traced region alone.
I don't understand. You need a binary image FIRST to even call bwboundaries. Please attach your image.
close all;
clear all;
clc;
im=imread('E:\brain images\T2 ABNORMAL BRAIN\P1\image12.jpg');
im1=rgb2gray(im);
im2=medfilt2(im1,[3 3]);
F=imclearborder(im2,4);
J=imadjust(F);
BW=im2bw(im2);
BW=bwareaopen(BW,50);
figure(1),imshow(BW);
[B,L,N,A] = bwboundaries(BW);
for i=1:length(B);
k=i;
BW=bwareaopen(BW,50);
boundary = B{k};
J=imadjust(F);
v=im2uint8(BW);
J=im2uint8(J);
H=v-J;
figure,imshow(H,[]);
hold on
plot(boundary(:,2),...
boundary(:,1),'r','LineWidth',2);
hold off
end
@Image analyst,I guess she probably wants a binary mask having 1's only at boundary positions.
For that they'd use bwperim(). I ran the code and it does an auto-threshold and then gets the boundaries of all the regions. If that is not wanted then I need to know what is wanted. I have not heard a really clear explanation of what is wanted. I don't even know what a traced region is, as opposed to a regular connected components region that you get from thresholding. Perhaps a figure showing what the desired outcome is would be helpful if explaining it in English is difficult because English is not the native language of the poster. I'm pretty sure what is wanted is trivial if I could just understand what is wanted.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 19 de Feb. de 2014

Comentada:

el 19 de Feb. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by