convert the color of pictures
Show older comments
Hi all, I'm a learner, need some help.
I have some emotion face pictures with color face on white background, format is bmp. I want to convert them to gray scale, that are gray face presented on gray background. Cause the pictures will be used as experiment material, i have to save them. But the question came up, i found when stored as bmp format, the pictures looks strange with distored color, then stored as jpg format, they looks fine. But when opened, I found the face presented on gray background, but under the gray background is bigger white background. Here is my code, I think there must be some serious problems. Please do me a favor, appreciate that.
clc;clear;
foldername=dir('E:\NimStim\')
for i=1:length(foldername)-2
filename=strcat('E:\NimStim\',foldername(i+2).name);
I=imread(filename);
if length(size(I))==3 %cause i found some picture is m*n*3,but not other pictures that are m*n
J=rgb2gray(I);
J(find(J>230))=205;
figure, imshow(J);
else
[X map]=imread(filename);X(find(X==0))=50;
gmap = rgb2gray(map);
figure, imshow(X,gmap);
end
saveas(figure(i),sprintf('figure_%d.bmp',i))
end
Accepted Answer
More Answers (0)
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!