Azzera filtri
Azzera filtri

why do i got error with active countor edge ?

2 visualizzazioni (ultimi 30 giorni)
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));

Risposta accettata

Walter Roberson
Walter Roberson il 9 Dic 2021
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 Commenti
Walter Roberson
Walter Roberson il 9 Dic 2021
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by