Luminance correction for colored images using SHINE toolbox
Afficher commentaires plus anciens
Unable to create colored images with equalized luminance with SHINE toolbox (images I've put in the input folder are colored, however the images in output folder are in grey scale), no error is given.
Réponses (2)
Rodrigo Souza
le 28 Jan 2019
Modifié(e) : Rodrigo Souza
le 28 Jan 2019
3 votes
Hi all,
I have put together three scripts 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.
Image Analyst
le 4 Juil 2016
Modifié(e) : Image Analyst
le 19 Sep 2016
2 votes
I've never heard of the SHINE toolbox. It's not one that the Mathworks sells. Do you have a reference?
To equalize luminance, convert to hsv or lab color space, then set the L or v channel to a constant, then convert back to rgb color space.
6 commentaires
ANA BUJAN
le 19 Sep 2016
I had the same problem. This is the reference: Willenbockel V, Sadr J, Fiset D, Horne GO, Gosselin F, Tanaka JW. Controlling low-level image properties: the SHINE toolbox.Behav Res Methods. 2010 Aug;42(3):671-84. doi: 10.3758/BRM.42.3.671.
Anyway, I would like to equate the luminance of a set of 500 colored photos. I'm sure I can do that with Matlab, but I don't know how to programm it. What i want to do is the following:
1. Calculate the luminance average value from the whole set of images, but excluding the background (they are in .png and then they have a transparent background). 2. Convert the images to Lab color space. 3. Set the calculated average value as the luminance value (L in Lab Space) for all the images. 4. Convert again all the images to RGB.
I have these steps very clear, the problem is that I don't know how to programm all that. A friend of mine has Matlab and I would like to check if this sequence is possible with the Image processing Toolbox. I would really appreciate any tip.
Thank you in advance.
Image Analyst
le 19 Sep 2016
Step 3 is not correct. That will make the luminance value of every pixel be the average luminance value, giving no variation in luminance at all. You need to compute the luminance value of that image and multiply by the ratio
for k = 1 : numImages
rgbImage = imread(......
labImage = rgb2lab(rgbImage);
thisLuminanceImage = labImage(:,:,1);
thisLuminanceValue = mean2(thisLuminanceImage);
% Scale luminance values (not replace with mean - it's different!).
newLuminanceImage = thisLuminanceImage * meanLuminanceValue / thisLuminanceValue;
labImage(:,:,1) = newLuminanceImage;
rgbImage = lab2rgb(labImage);
% Save new image
imwrite(..........
end
ANA BUJAN
le 20 Sep 2016
Many thanks :) I still have a doubt... using this code the luminance mean calculation includes the luminance values of the background or only the colored foreground luminance value?
ANA BUJAN
le 20 Sep 2016
I've also changed your code in order to include the calculation of the meanLuminanceValue, but as I'm very new in this field, I'm not sure my code is ok. I have run it, and no errors were given, but I'm not very confident about the results. In fact, the new images have a white background instead transparent, and even one of the images has a black backgorund. I'm sure I have a lot of mistakes.
I'm copying the code below:
images = dir('C:\Users\USUARIO\Documents\MATLAB\Images1\*.png')
for i=1:numel(images)
file_name=dir(strcat('C:\Users\USUARIO\Documents\MATLAB\Images1\'));
rgbImage=imread(strcat('C:\Users\USUARIO\Documents\MATLAB\Images1\',images(i).name))
labImage = rgb2lab(rgbImage);
thisLuminanceImage = labImage(:,:,1);
thisLuminanceValue = mean2(thisLuminanceImage);
meanLuminanceValue = mean (thisLuminanceValue);
% Scale luminance values (not replace with mean - it's different!).
newLuminanceImage = thisLuminanceImage * meanLuminanceValue / thisLuminanceValue;
labImage(:,:,1) = newLuminanceImage;
rgbImage = lab2rgb(labImage);
% Save new image
imwrite(rgbImage,['C:\Users\USUARIO\Documents\MATLAB\Images1\', 'NEW',num2str(i),'.png']);
end
Thanks in advance.
Ana
Image Analyst
le 20 Sep 2016
Your code where you computed meanLuminanceValue is not correct. It's just computing the mean of the current image, not of the reference/background image.
Also attach a background image(s) that you use to compute meanLuminanceValue as well as an image or two that you wish to correct/alter to match the luminance of your reference/background images.
ANA BUJAN
le 21 Sep 2016
Many thanks for your patience. Yeah, that was the reason why the images remained the same... Nevertheless, I'm not using a specific set of images for computing the meanLuminancevalue, instead I would like to use the whole set of images for doing that. Then, the reference images for computing the mean and for matching the luminance are the same.
I'm attaching five images from my set. Again, thank you.
Catégories
En savoir plus sur Lighting, Transparency, and Shading dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!