Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know type of image

Tags:

image

matlab

When I use imread in MATLAB and read an image, how would I know if it is RGB, gray scale or single programmatically?

    I1 = imread('sample_image.jpg');

How can I know what type I1 is before any conversion?

like image 633
Lakshmi Narayanan Avatar asked Aug 21 '13 21:08

Lakshmi Narayanan


People also ask

What are the 3 types image format?

The PNG, JPEG, and GIF formats are most often used to display images on the Internet. Some of these graphic formats are listed and briefly described below, separated into the two main families of graphics: raster and vector.


1 Answers

You can use imfinfo to retrieve information about an image file before you load it:

info = imfinfo('sample_image.jpg');
info.ColorType % e.g. 'grayscale', 'truecolor', 'indexed'
info.BitDepth % e.g. 8, 16

You can also look at the help section on imread to see what the output class will be for different file types. The problem comes in determining the difference between a grayscale image, and an indexed colour file - these will have the same size and class. In this case you need to check ColorType beforehand and load the colormap in when you read the image:

[I, map] = imread(filename)

like image 166
nkjt Avatar answered Nov 15 '22 03:11

nkjt