Filter löschen
Filter löschen

How can I decrease image contrast using simple arithmetic?

9 Ansichten (letzte 30 Tage)
Lauren
Lauren am 23 Mär. 2014
Kommentiert: tom am 11 Mai 2020
Hi everyone,
I am quite new to Matlab and I am in need of help to find ways to decrease the contrast of an image:
a) mathematically without using functions such as imadjust, etc. b) while keeping the average luminance the same
Here is what I have been using:
im = double(im);
R = im(:,:,1);
G = im(:,:,2);
B = im(:,:,3);
im = 0.2989*R + 0.5870*G + 0.1140*B;
im1 = (im/255);
contrast_factor = 0.6;
av_lum = mean(im1(:));
scaled_image = ((im1 - av_lum)*contrast_factor) + av_lum
This seems to be working but I am not sure if it is the most accurate way. Do I need to use the round function? I will be using this code on at least 60 images with different histograms.
Any help would be greatly appreciated!

Antworten (3)

David Young
David Young am 23 Mär. 2014
Your code looks fine.
You should almost certainly not use the round function. If your image started off as values in the range 0-255, im1 will have values in the range 0-1, so the round function will destroy most of the information.
You are making the assumption that luminance is linearly related to pixel value. That's probably alright, though there are applications where it may not be what you want. We'd need more information to comment on that.
  2 Kommentare
Lauren
Lauren am 23 Mär. 2014
Does gamma correction allow for a linear relationship between luminance and pixel value? The monitor I will be using will be gamma corrected.

Melden Sie sich an, um zu kommentieren.


Image Analyst
Image Analyst am 23 Mär. 2014
If you want it to be faster you can compute the look up table from your equation, and then use intlut().

tom
tom am 7 Mai 2020
Bearbeitet: tom am 7 Mai 2020
Hey everyone,
sorry for the "add-on question", but I try to do the same as Lauren ( (1.) reduce image contrast & (2.) keep pixel intensity constant using simple arithmetric). But in the end I would like to "keep" or recover the RGB/Color image. In Laurens aprroach the RGB image is transformed into grayscale. I dont know if this even possible?
Any help or recommendation would be greatly appreciated!
Tom
  4 Kommentare
Image Analyst
Image Analyst am 8 Mai 2020
Yes, you'd have to do each channel one at a time. Instead of
R = im(:,:,1); G = im(:,:,2); B = im(:,:,3);
you can use
% Extract the individual red, green, and blue color channels using imsplit() (introduced in R2018b).
[R, G, B] = imsplit(im);
tom
tom am 11 Mai 2020
thank you very much!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by