필터 지우기
필터 지우기

How can I decrease image contrast using simple arithmetic?

조회 수: 9 (최근 30일)
Lauren
Lauren 2014년 3월 23일
댓글: tom 2020년 5월 11일
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.
  댓글 수: 2
Lauren
Lauren 2014년 3월 23일
Does gamma correction allow for a linear relationship between luminance and pixel value? The monitor I will be using will be gamma corrected.

댓글을 달려면 로그인하십시오.


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);
tom
tom 2020년 5월 11일
thank you very much!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by