change picture into grayscale and keep the luminace...same

Hi guys.I have some color face pictures with white background.I want to convert them to grayscale,match them for luminance and contrast and bring them into an oval shape to remove hair, neck, and background information and then present on a light grey background.How can i do that? Thanks!

 Accepted Answer

Your link doesn't work. Anyway, I'm not a psychologist but I don't think you want to do that. There is a concept called Color Constancy that says people are basically tolerant or immune to changes in color in situations like that. In other words, people will be able to discern the emotion of your subject in the photo regardless of whether the image is monochrome or color or brighter or darker. In essence they compensate for slight changes in color of the lighting or exposure level. In fact converting the images may make it more distracting. If you still want to, you can use rgb2gray()
% Define desired mean gray level
desiredMean = 128; % or whatever....
% Convert to monochrome.
grayImage = rgb2gray(rgbImage);
% Normalize to desired mean.
grayImage = uint8( double(grayImage) * desiredMean / mean2(grayImage));
imshow(grayImage);
There are more sophisticated histogram matching routines if you want, even some that work in color (e.g. Grundland and Dodgson)

3 Comments

Thanks a ton! Very impressive and inspired. Indeed,just as you said,people can extract and perceive emotion information from pictures even with different color or luminance.But with different variables,the sense does not change,the response in the brain may be change,that's what needed to control.Because we just want to observe the effect of emotion in the brain with neuroimaing techniques,of course we can't make sure everything are controlled very well. About the code, does the ' rgbImage ' means the original picture's name? Why the matlab display error warning "MAP must be a m x 3 array." And I don't understand clearly the function of 'grayImage=unit8(...)'.
I didn't use any color map so I don't know why you tried to. rgbImage is the 3D color image like you'd get from imread():
rgbImage = imread('c:\folder\emotion image number 1.png');
I cast it to uint8 so that you could display it. I had cast it to double because it doesn't like uint8's multiplied by doubles. You can leave the uint8 out if you want but you'd just have to display it with [0 255], like:
imshow(grayImage, [0 255]);
If you ever want to write out the gray image to a disk file, you'd have to convert it to uint8 because that's what most imaging formats want.
Thanks.As totally a learner,I will type the codes into matlab to see the functions' meaning.

Sign in to comment.

More Answers (1)

Xu,
the only contribution i can made here is that , as you have N samples, you have to normalize them, i mean after converting to Grayscale, for every sample you need to perform :
% after converting to double
N=(X-mean(mean(X)))/std(std(X));
I think the oval shape is related to Logarithm operator.

1 Comment

Thanks for help.I know little about image process.So maybe very simple for you ,but for me it's a problem.I'm designing one psychology experiment showing some emotion faces to subjects.But to keep some variables constant for subjects except the emotion.I need to achieve the standards expressed in my prior question. So I would be grateful if someone can write the relevant code for me. To show my intention clearly:

Sign in to comment.

Categories

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!