Write a program to change brightness and change the contrast of the color image (keep the average brightness of the image). I don't understand how to keep the average brightness of the image. thank you!!!

20 ビュー (過去 30 日間)
"Write a program to change brightness and change the contrast of the color image (keep the average brightness of the image)."
I don't understand how to keep the average brightness of the image. thank you!!!

採用された回答

Walter Roberson
Walter Roberson 2017 年 9 月 24 日
編集済み: Walter Roberson 2017 年 9 月 24 日
The way to keep the average brightness of an image is:
  1. calculate the average brightness of the original image; Call this BRorig
  2. make whatever local changes to color and contrast;
  3. calculate the average brightness of the revised image; Call this BRnew
  4. multiply the revised image by the ratio BRorig/BRnew
  5 件のコメント
Hoang Nguyen
Hoang Nguyen 2017 年 9 月 24 日
John D'Errico, My teacher said: 'Used to HSI, but I don't understand' My English not good Can you contact me with facebook: "nguyenhoang140195@gmail.com"? Thank you!! =))
Walter Roberson
Walter Roberson 2017 年 9 月 24 日
You could also calculate the total brightness of the original image (instead of the average) and the total brightness of the modified image, and then pick random locations to add increments to, taking into account that brightness = 0.2989 * R + 0.5870 * G + 0.1140 * B

サインインしてコメントする。

その他の回答 (2 件)

Image Analyst
Image Analyst 2017 年 9 月 24 日
編集済み: Image Analyst 2017 年 9 月 24 日
I'd use a different approach. You can use rgb2hsv to convert to HSV color space. Now, it really depends on what your teacher means by contrast. One way is to increase the brightness contrast and to do that you'd subtract the mean from the V channel, multiply by some value, add back in the original mean, and then transform back:
hsvImage = rgb2hsv(rgbImage);
hChannel = hsvImage(:, :, 1);
sChannel = hsvImage(:, :, 2);
vChannel = hsvImage(:, :, 3);
meanV = mean2(vChannel);
newV = meanV + 1.5 * (vChannel - meanV); % Increase contrast by factor of 1.5
newHSVImage = cat(3, hChannel, sChannel, newV);
newRGBImage = hsv2rgb(newHSVImage);
The other thing they might mean is to increase the saturation so the colors look more vivid. In that case, you'd just multiply the S channel by some factor.
hsvImage = rgb2hsv(rgbImage);
hChannel = hsvImage(:, :, 1);
sChannel = hsvImage(:, :, 2);
vChannel = hsvImage(:, :, 3);
newS = 1.5 * sChannel; % Increase contrast by factor of 1.5
newHSVImage = cat(3, hChannel, newS, vChannel);
newRGBImage = hsv2rgb(newHSVImage);
Of course, clipping may occur if you go back to uint8 (as John said).
Or you could change both the V and S channels.
  4 件のコメント
Image Analyst
Image Analyst 2018 年 6 月 13 日
I don't think it takes a string. It needs to take an image so use imread() to read 'image19.jpg' into an image:
rgbImage = imread('image19.jpg');
hsvImage = rgb2hsv(rgbImage);
By the way, don't use JPG format for image analysis - it introduces artifacts that will affect your measurements.
Akib Rahman
Akib Rahman 2018 年 6 月 13 日
Thanks, Image Analyst :) It works.

サインインしてコメントする。


Rodrigo Souza
Rodrigo Souza 2019 年 1 月 28 日
Hi all,
I have put together three scripts/functions for calculating (mean and SD), matching or normalizing luminance of colored images (using HSV and CIE Lab color spaces).
They may be specially useful for pupillometry measures of infant research.
The scripts and their descriptions are available at my OSF page: https://osf.io/auzjy/
Hope it helps.

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by