im2bw help: image threshold array

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일

0 개 추천

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
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')

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2016년 5월 29일

댓글:

2016년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by