How can I decrease image contrast using simple arithmetic?

9 次查看(过去 30 天)
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!

回答(3 个)

David Young
David Young 2014-3-23
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.

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

tom
tom 2020-5-7
编辑:tom 2020-5-7
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 个评论
Image Analyst
Image Analyst 2020-5-8
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);

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by