How can i automatically convert the input image to gray scale
Mostra commenti meno recenti
I am dealing with three image types: color, B&W and gray. i am reading a bunch of images and performing enhancement but i want all the images to be in gray scale before i proceed to enhance. But i do not know what type of an image i am reading at an instant. so if i am reading anything other than gray scale i want to convert it to gray and if am reading a gray input i want to proceed directly to enhancement. How can i automate this ??
Risposta accettata
Più risposte (1)
A black & white image is just a grey image with just two levels of grey, so I'm not sure what you want to do in that case. Possibly nothing. A colour image will be a 3d matrix, whereas a grey image will be 2d. That's easy to differentiate with ndims
if ndims(img) == 3
%colour image, convert to greyscale any way you want
img = rgb2gray(img); %note that there are many other ways to convert a colour image to grey
elseif isequal(logical(img), img) %one way of recognising a bw image
%do whatever you want. Nothing?
end
Categorie
Scopri di più su Images in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!