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
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!