im2bw help: image threshold array
1 view (last 30 days)
Show older comments
Is there any way to get the output of im2bw to go into an array?
I know the function BW = im2bw(I, level) produces a black white image and that bwboundaries(bw) will then draw the boundarys
I want to do this a bunch for the same image when arrays don't seem to work? my code looks like this.
I=imread('matmap.bmp');
b=I(:,:,3);
for a=1:1:20
bw(a)=im2bw(b, a/20);
end
imshow(I)
hold on
for k = 1:numel(bw)
bb(k)=bwboundaries(bw);
plot(bb{k}(:,2), bb{k}(:,1), 'b', 'Linewidth', 1)
end
0 Comments
Answers (1)
Image Analyst
on 29 May 2016
Why are you doing two separate loops??? You need to put the call to bwboundaries() immediately after im2bw() - right there in the same loop.
2 Comments
Image Analyst
on 29 May 2016
No. Here's a full demo:
% rgbImage = imread('peppers.png');
rgbImage = imread('onion.png');
% Extract blue channel.
b = im2double(rgbImage(:,:,3));
subplot(5,5, 1);
imshow(rgbImage)
subplot(5,5, 2);
imshow(b);
title('Blue Channel', 'FontSize', 13);
for a = 1 : 20
bw = im2bw(b, a/20);
subplot(5,5, a + 2);
imshow(bw);
caption = sprintf('a/20 = %.4f', a/20);
title(caption, 'FontSize', 13);
hold on;
boundaries = bwboundaries(bw);
for k = 1 : length(boundaries)
plot(boundaries{k}(:,2), boundaries{k}(:,1), 'b', 'Linewidth', 1);
end
drawnow;
end
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!