Using imread and plot grayscale image

32 views (last 30 days)
Askic V
Askic V on 18 May 2022
Edited: DGM on 18 May 2022
I'm following a tutorial about image processing and there is a following code:
img = imread('tire.tif');
size(img) % 205x232
In the tutoria, picture that is shown is grayscale (black/white), but in my case the picture looks like shown in the attachment. What would a reason for this difference?
Thank you!
The actual picture is attached.
I use online Matlab (latest version).

Accepted Answer

DGM on 18 May 2022
Edited: DGM on 18 May 2022
Tools like imshow(), image(), imagesc() will display single-channel (grayscale) images with the current colormap. In your case, that colormap is parula().
If you want it to be displayed in grayscale, you can change the colormap. After you display the image, use
If all you want to display is the image, that should suffice.
Alternatively, you can convert the image to a gray RGB image so that imshow() doesn't apply a colormap anymore.
imagesc(repmat(img,[1 1 3]))
This method is useful if you want to do something like overlay a contour plot or some other colormapped graphics object in the same axes. Since the image no longer uses the axes colormap, you can avoid the problem of needing two different colormaps.

More Answers (0)


Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!