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!
0 件のコメント
回答 (3 件)
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 件のコメント
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().
0 件のコメント
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
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!