Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Displaying Image Data

This example shows how to display an image and convert it to grayscale in MATLAB®.

Read the Image

The sample file named peppers.png contains an RGB image. Read the image into the workspace using the imread function.

RGB = imread('peppers.png');

Display the Color Image

Display the image data using the imshow function.

imshow(RGB)

Convert to Grayscale

Convert the RGB image to grayscale using the rgb2gray function.

gray = rgb2gray(RGB);

Display the Grayscale Image

Display the grayscale image using imshow.

imshow(gray)

Was this topic helpful?