%% Display Grayscale, RGB, Indexed, or Binary Image
% Display a grayscale, RGB (truecolor), indexed or binary image using imshow. MATLAB® includes a TIF file, named corn.tif, that contains three images: a grayscale image, an indexed image, and a truecolor (RGB) image. This example creates a binary image from the grayscale image.
%
%% Display a Grayscale Image
% Read the grayscale image from the corn.tif file into the MATLAB workspace.  The grayscale version of the image is the third image in the file.

corn_gray = imread('corn.tif',3);

% Display the grayscale image using imshow.

imshow(corn_gray)

%
%% Display an Indexed Image
% Read the indexed image from the corn.tif file into the MATLAB workspace.  The indexed version of the image is the first image in the file.

[corn_indexed,map] = imread('corn.tif',1);

% Display the indexed image using imshow.

imshow(corn_indexed,map)

%
%% Display an RGB Image
% Read the RGB image from the corn.tif file into the MATLAB workspace. The RGB version of the image is the second image in the file.

[corn_rgb] = imread('corn.tif',2);

% Display the RGB image using imshow.

imshow(corn_rgb)

%
%% Display a Binary Image
% Read the grayscale image from the corn.tif file into the MATLAB workspace and use thresholding to convert it into a binary image. The grayscale version of the image is the third image in the file.

[corn_gray] = imread('corn.tif',3);

% Determine the mean value of pixels in the grayscale image.

meanIntensity = mean(corn_gray(:));

% Create a binary image by thresholding, using the mean intensity value as the threshold.

corn_binary = corn_gray > meanIntensity;

% Display the binary image using imshow.

imshow(corn_binary)

% Copyright 2012-2018 The MathWorks, Inc.