why do i got error with active countor edge ?

2 次查看(过去 30 天)
why do i get this an error ?
I = imread('2820072.jpg');
% A = rgb2gray(I2);
bw=im2bw(I,0.4);
kernel = -1*ones(1);
kernel(2,2) = 10;
enhancedImage = imfilter(bw, kernel);
figure(6),imshow(enhancedImage);title('enhancedImage Image');
I2 = imcrop(bw,[75 68 130 112]);
figure;
imshow(I2)
title('Cropped Image')
imshow(A)
title('Original Image')
r = drawrectangle;
mask = createMask(r);
bw2 = activecontour(I2,mask,200,'edge');
figure
imshow(labeloverlay(I2,bw2));
hold on;
visboundaries(bw2,'Color','r');
the error .....
Error using labeloverlay
Expected A to be one of these types:
single, double, uint8, uint16, int16
Instead its type was logical.
Error in labeloverlay>parseInputs (line 131)
validateattributes(A,{'single', 'double', 'uint8', 'uint16', 'int16'},{'nonsparse','real','nonempty'},mfilename,'A');
Error in labeloverlay (line 88)
parsedInputs = parseInputs(varargin{:});
Error in Untitled (line 20)
imshow(labeloverlay(I2,bw2));

采纳的回答

Walter Roberson
Walter Roberson 2021-12-9
im2bw() returns a logical matrix. You crop that logical matrix, which leaves it as a logical matrix. You then pass that to labeloverlay() but labeloverlay() does not permit logical matrices for its first position. You should im2double() before passing it into labeloverlay()
  4 个评论
Walter Roberson
Walter Roberson 2021-12-9
imshow(I2)
title('Cropped Image')
imshow(A)
title('Original Image')
r = drawrectangle;
mask = createMask(r);
You are doing the drawrectangle() over the original image, not over the cropped image. The coordinates you get will probably be outside the coordinates for the cropped image.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by