Clear Filters
Clear Filters

A equstion about the function CONTRAST

2 views (last 30 days)
apricity
apricity on 17 May 2024
Edited: DGM on 17 May 2024
You wrote on the help webpage that contrast supports inputting true color images of type m-by-n-by-3, but when I input the code, the following error occurred
Can you help me deal with this problem?

Answers (1)

DGM
DGM on 17 May 2024
Edited: DGM on 17 May 2024
As far as I can see, the documentation is plainly wrong. The code is brief and obviously cannot tolerate any input with more than 2 dimensions. As vague as the synopsis is, it should be clear that contrast() generates a colormap for rendering a grayscale image. The input colorspace used in this sort of scaled colormapping is 1-dimensional. That is to say that so long as the colormap is Mx3, the input is necessarily grayscale.
The example given in the webdocs is not a truecolor image. It is a direct colormapped indexed-color image that is being treated as if it's grayscale, which it's not. The index array X is a 2D array of integer indices into the included color table.
Whatever your expectations are, and whatever the documentation says, contrast() almost certainly isn't what you want if you're working on a JPG -- or probably anything else.
If you want to do contrast adjustment of an actual truecolor image, use something that actually does that. These are some of the tools in IPT:
There are other tools on the File Exchange. This lists several tools for adjusting levels from both IPT and MIMT.
If you're looking for simple levels adjustment, IPT has imadjust(). MIMT has various tools for brightness/contrast/gamma/color adjustment.
If you're looking for something that does histogram equalization, look at histeq() or adapthisteq(). MIMT also has convenience tools (e.g. histeqtool()) for applying global and adaptive histogram equalization to color images, which is something that IPT histeq() and adapthisteq() don't do directly.
Otherwise, you're going to have to be specific about what your needs are.

Community Treasure Hunt

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

Start Hunting!