What dose these errors mean? any help.

16 views (last 30 days)
Moon Shadow
Moon Shadow on 12 Feb 2014
Commented: Image Analyst on 8 Oct 2016
Yesterday, I worked with all these codes and it work immediately, but today all the codes give me same errors.
I tried different images and codes but still the same errors.
Any one can help me PLZ.
My MATLAB:Student R2013a
I = imread('eight.tif');
EDU>> imshow(I);
EDU>> imhist(I);
Error using imhist
Expected input number 1, I or X, to be two-dimensional.
Error in imhist>parse_inputs (line 277)
validateattributes(a,
{'double','uint8','int8','logical','uint16','int16','single','uint32',
'int32'}, ...
Error in imhist (line 59)
[a, n, isScaled, top, map] = parse_inputs(varargin{:});
EDU>> B=imread('eight.tif');
imshow(B);
figure, imcontour(B);
Error using imcontour
Expected input number 1, I, to be two-dimensional.
Error in imcontour>ParseInputs (line 109)
validateattributes(a,{'uint8','int16','uint16','double','logical','single'}, ...
Error in imcontour (line 41)
[x,y,a,extra_args] = ParseInputs(varargin{:});

Answers (2)

Image Analyst
Image Analyst on 12 Feb 2014
Worked for me. Somehow I think your eight.tif got converted to a 3D color image. What does this say:
whos I
size(I)
  3 Comments
Image Analyst
Image Analyst on 12 Feb 2014
What variable are you using in this:
I = imread('eight.tif');
You must have a typographical error somewhere.
Image Analyst
Image Analyst on 8 Oct 2016
Moon, you should definitely have an "I" because your code shows you assigning the output of imread() to it, so if you get the error message
Undefined function or variable 'I'.
then you've changed the code from what you've posted.
Here is some code that I use in demos when the user is expecting to have a gray scale image, but it may not be.
grayImage = imread(fullFileName);
% Get the dimensions of the image.
% numberOfColorBands should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
After that code, grayImage (which is a much better name than I) will be a grayscale image, either the original image, or the original image converted from RGB into gray scale.

Sign in to comment.


Nikhil Lohia
Nikhil Lohia on 8 Oct 2016
The cause of error is because your image is RGB and imhist does not deal with that. To work around this you can either use a single channel:
imhist(YourImage(:,:,Channel));
or convert from RGB to grayscale:
imhist(rgb2gray(YourImage));
That should work fine now.

Community Treasure Hunt

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

Start Hunting!