How can i automatically convert the input image to gray scale
Show older comments
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 ??
Accepted Answer
More Answers (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
Categories
Find more on Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!