how can I fill these bw images to generate a mask?
Show older comments
Hi folks,
I am trying to threshold an image using edge detection. So far, I have the following 2 images which demonstrate the effectiveness of each of the edge detection techniques used. I am trying to turn the result into a mask by filling inside the perimeter, with no success!
My initial approach was to turn each black pixel to true starting from the bottom of each image until it reached a white pixel for each column, but I'm unsure of how to do this.
My code is below:
i = 1;
myParams = {'Sobel','Prewitt','Roberts','log','zerocross','Canny','approxcanny'};
x = imadjust(im2gray(imread([path, num2str(i), '.png'])));
for i = 1 : 7
bw{i} = myMask(x, myParams{i});
end
figure;
subplot(4, 3, 2);imshow(x);title('Original Greyscale Image');
for i = 1:7
if i == 7
subplot(4, 3, i+4);imshow(bw{i});title(myParams{i});
else
subplot(4, 3, i+3);imshow(bw{i});title(myParams{i});
end
end
function bw = myMask(bw, param)
bw = im2bw(bw);
bw = edge(bw, param, "nothinning");
bw = bwareaopen(bw, 3);
bw = imclose(bw, strel("disk", 10));
bw = imfill(bw, 'holes');
bw = bwperim(bw);
bw = imdilate(bw, ones(12));
bw = imerode(bw, ones(10));
bw = imfill(~bw, 'holes');
bw = ~bw;
end

Accepted Answer
More Answers (0)
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!