Error using images.int​ernal.imag​eDisplayVa​lidatePara​ms>validat​eCData (line 122) If input is logical (binary), it must be two-dimensional.

37 次查看(过去 30 天)
a=imread('c1.jpg');
imshow(a)
cd=double(a);
imshow(cd)
imshow(cd/255)
cd1=im2double(a);
figure, imshow(cd1)
c= a>120;
imshow(c)
impixelinfo
OUTPUT
Error using images.internal.imageDisplayValidateParams>validateCData (line 122)
If input is logical (binary), it must be two-dimensional.
Error in images.internal.imageDisplayValidateParams (line 30)
common_args.CData = validateCData(common_args.CData,image_type);
Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
Error in img (line 9)
imshow(c)

回答(2 个)

Walter Roberson
Walter Roberson 2020-2-8
Nearly all jpg are rgb. You are not converting to grayscale before doing your test against 120

Lahiru Karunathilaka
imshow(cd/255);
  1 个评论
Walter Roberson
Walter Roberson 2021-12-12
They already have that in their code, and the line is not a problem for them. Their problem was with
c= a>120;
imshow(c)
and imshow() is complaining that logical values must be 2 dimensional.
Th is likely caused by a being 3 dimensional instead of 2 dimensional. The input file is JPG. and the overwhelming majority of JPG files are RGB images instead of grayscale images. The initial specification for JPG did not permit grayscale images, so for maximum compatibility with old readers, most JPG writing software converts grayscale images to the equivalent RGB images and writes those.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by