How do I eliminate (minimize) display quantization with imshow?

1 view (last 30 days)
I see extra quantization when displaying a grayscale uint8 image. For example:
inRamp = uint8 ( round ( repmat( linspace(0,60,1200), 600, 1 ) ) );
imshow ( inRamp)
imwrite ( inRamp, 'inputRamp.tif' )
If I display this tif image in another display application, I see a series of steps. The image displayed in MATLAB using imshow has a couple of steps that are double-wide and double-deep. I have verified this using Windows screen captures of the image as displayed by other software and as displayed in MATLAB. The plots of this data show a clear stairstep pattern, with the MATLAB showing a couple of steps (near pixel value 10 and 40) that are double width and double height. I can email plots to anyone interested in seeing them.

Accepted Answer

Bruce Pillman
Bruce Pillman on 23 Aug 2013
After discussing this with Mathworks technical support, I tried changing the renderer used from "painters" to "opengl". This appears to solve the quantization problem.

More Answers (2)

DGM
DGM on 18 Jun 2024
I don't really know why the renderer would change it that significantly, but maybe it depends on settings or drivers I don't have. That said, I do tend to see extra bands, and it's for reasons that nobody tends to mention.
You have a single-channel image displayed with imshow(). Depending on the usage, the discrete levels in the image are mapped to the rows of a colormap. In the given usage, there are 61 graylevels, the colormap is a uniformly-spaced 256-level ramp. In this case, each unique value in the image maps to one unique row in the colormap. If you had called imshow() with a nondefault 'DisplayRange' parameter, or if you specified a different colormap (e.g. different length or nonuniform), the mapping may not be 1:1.
So your image values have been mapped to colors. They're then subject to another uniform 256-level quantization. If the colormap were not uniform, or if it were a different length, there may be subtle aliasing effects.
That much is complicated enough, and that's usually where everyone stops scratching their head, but it's not where the complication actually stops. There are still system-level and hardware-level transformations that get applied. If you have any system-level tools that allow you to manipulate display brightness/contrast/gamma, those will cause patterns in the mach bands.
Many monitors also offer similar controls which again manipulate integer data. Most monitors I've ever used come with a default "vivid" profile with absurd contrast boosting. Right from the box, they'll render everything wrong. Many LCD panels do not even actually render 8b depth. They fake it with dithering. How that's implemented is typically not disclosed, but occasionally not unnoticeable.
In my case, I have some display gamma settings dynamically set using xcalib, so I always see a geometric progression of steps in the mach bands. On my old laptop, I see extra bands because the LCD panel is a worse piece of junk than old panels made 20 years prior.
The point is that there are a number of points where the data gets quantized/remapped/transformed. It's not always MATLAB, and it's not always even fixable from within MATLAB.

Image Analyst
Image Analyst on 19 Aug 2013
You may be observing aliasing, possibly compounded by the Mach effect. Post your plots and images to snag.gy.
  8 Comments
Bruce Pillman
Bruce Pillman on 21 Aug 2013
Thanks for doing that test. That is interesting, since my results don't seem random. I am running 64-bit Windows 7. What are you running?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!