im2bw help: image threshold array

1 次查看(过去 30 天)
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

回答(1 个)

Image Analyst
Image Analyst 2016-5-29
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 个评论
Morpheuskibbe
Morpheuskibbe 2016-5-29
you mean something like this?
for a=1:1:20
bb(a)=bwboundaries(im2bw(b, a/20));
end
still doesn't seem to like me using an array
Image Analyst
Image Analyst 2016-5-29
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')

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by