MATLAB: Trouble with image importing

image importingimage processing

In my project, which focuses on image processing techniques, I have a significant fundamental problem. When I try to import a black and white or grayscale image, matlab interprets it as a three-dimensional matrix, where I guess the third matrix is a color map (even though we aren't using color images). I have used the command rbgtogray, and while that solves the dimension problem, the result is always an image that is not gray. Is there something I'm missing?

Best Answer

Right, now we've got to the bottom of the problem:
You're using the wrong function to display your image. Instead of
image(I); %or I2
Use
imshow(I); % or I2
As per documentation of image, image creates an image graphics object by interpreting each element in a matrix as an index into the figure's colormap. Another option would be to change the figure colormap to greyscale with
colormap([0:255; 0:255; 0:255]' / 255);