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

17 views (last 30 days)
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)

Answers (2)

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

Lahiru Karunathilaka
Lahiru Karunathilaka on 12 Dec 2021
imshow(cd/255);
  1 Comment
Walter Roberson
Walter Roberson on 12 Dec 2021
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.

Sign in to comment.

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!