Vous êtes sur la page 1sur 3

The input image I can be of class uint8, uint16, int16, single, or double and it must

be nonsparse. The return value level is a double scalar. The effectiveness metric EM
is a double scalar.
I = imread('coins.png');
level = graythresh(I);
BW = im2bw(I,level);
imshow(BW)
**graytresh is an otsu method
http://www.mathworks.com/help/images/ref/graythresh.html

im2bw
Convert image to binary image, based on threshold
http://www.mathworks.com/help/images/ref/im2bw.html

Converting Between Image Types


The toolbox includes many functions that you can use to convert an image from one type to another, listed in the
following table. For example, if you want to filter a color image that is stored as an indexed image, you must first
convert it to truecolor format. When you apply the filter to the truecolor image, MATLAB filters the intensity values in
the image, as is appropriate. If you attempt to filter the indexed image, MATLAB simply applies the filter to the indices
in the indexed image matrix, and the results might not be meaningful.

You can perform certain conversions just using MATLAB syntax. For example, you can convert a grayscale image to
truecolor format by concatenating three copies of the original matrix along the third dimension.

RGB = cat(3,I,I,I);
The resulting truecolor image has identical matrices for the red, green, and blue planes, so the image displays as
shades of gray.
In addition to these image type conversion functions, there are other functions that return a different image type as
part of the operation they perform. For example, the region of interest functions return a binary image that you can
use to mask an image for filtering or for other operations.

Note When you convert an image from one format to another, the resulting image might look different from the original. F
indexed image to a grayscale image, the resulting image displays as shades of grays, not color.

Function

Description

demosaic

Convert Bayer pattern encoded image to truecolor (RGB) image.

dither

Use dithering to convert a grayscale image to a binary image or to convert a truecolor image to an indexed imag

gray2ind

Convert a grayscale image to an indexed image.

grayslice

Convert a grayscale image to an indexed image by using multilevel thresholding.

im2bw

Convert a grayscale image, indexed image, or truecolor image, to a binary image, based on a luminance thresho

ind2gray

Convert an indexed image to a grayscale image.

ind2rgb

Convert an indexed image to a truecolor image.

mat2gray

Convert a data matrix to a grayscale image, by scaling the data.

rgb2gray

Convert a truecolor image to a grayscale image.

Note: To work with images that use other color spaces, such as HSV, first convert the image to RGB, process th
original color space. For more information about color space conversion routines, see Color.

rgb2ind

Convert a truecolor image to an indexed image.


http://www.mathworks.com/help/images/converting-between-image-types.html

Image Type Conversion


Convert between the image types, such as RGB (truecolor), binary, grayscale, and
indexed.
Functions
gray2ind

Convert grayscale or binary image to indexed image

ind2gray

Convert indexed image to grayscale image

mat2gray

Convert matrix to grayscale image

rgb2gray

Convert RGB image or colormap to grayscale

ind2rgb

Convert indexed image to RGB image

label2rgb

Convert label matrix into RGB image

demosaic

Convert Bayer pattern encoded image to truecolor image

imquantize Quantize image using specified quantization levels and output values
multithresh Multilevel image thresholds using Otsu's method
im2bw

Convert image to binary image, based on threshold

graythresh

Global image threshold using Otsu's method

grayslice
Convert grayscale image to indexed image using multilevel
thresholding
im2double

Convert image to double precision

im2int16

Convert image to 16-bit signed integers

im2java2d

Convert image to Java buffered image

im2single

Convert image to single precision

im2uint16

Convert image to 16-bit unsigned integers

im2uint8

Convert image to 8-bit unsigned integers

http://www.mathworks.com/help/images/image-type-conversions.html

Vous aimerez peut-être aussi