Image into grayscale without using toolbox

2 次查看(过去 30 天)
This is my current code:
function out = luminance(current_img )
R=current_img(:,:,1);
G=current_img(:,:,2);
B=current_img(:,:,3);
I=.299*R + 0.587*G+0.114*B;
out=I;
end
I'm trying to make my image grayscale but that's not what's happening, what am I doing wrong?

采纳的回答

Image Analyst
Image Analyst 2015-10-12
That should work. What's the problem? Perhaps you want to cast it back to uint8 or something.
out = uint8(.299*double(R) + 0.587*double(G)+0.114*double(B));
or else just leave it as floating point and use [] in imshow to display it:
imshow(out, []);
  2 个评论
Krish Desai
Krish Desai 2015-10-12
The image is coming out in blues, yellows and greens. I tried typecasting but it didn't work.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by