Image into grayscale without using toolbox

2 vues (au cours des 30 derniers jours)
Krish Desai
Krish Desai le 12 Oct 2015
Commenté : Krish Desai le 12 Oct 2015
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?

Réponse acceptée

Image Analyst
Image Analyst le 12 Oct 2015
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 commentaires
Krish Desai
Krish Desai le 12 Oct 2015
The image is coming out in blues, yellows and greens. I tried typecasting but it didn't work.
Krish Desai
Krish Desai le 12 Oct 2015
Update: Using the floating point worked

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by