

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
matlab codes rgb2gray
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Convert RGB image or colormap to grayscale collapse all in page
I = rgb2gray(RGB) newmap = rgb2gray(map) gpuarrayB = rgb2gray(gpuarrayA) Description I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. rgb2gray^ converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. newmap = rgb2gray(map) returns a grayscale colormap equivalent to map. gpuarrayB = rgb2gray(gpuarrayA) performs the operation on a GPU. gpuarrayA can be either an RGB image or a colormap. gpuarrayB^ is a gpuArray of the same type as^ gpuarrayA. This syntax requires the Parallel Computing Toolbox™ Note: A grayscale image is also called a gray-scale, gray scale, or gray-level image. Class Support If I is an RGB image, it can be of class uint8, uint16, single , or double. The output image I is of the same class as the input image. If I^ is a colormap, the input and output colormaps are both of class^ double^. If gpuarrayA^ is an RGB gpuArray image, it can be^ uint8,^ uint16,^ single^ , or^ double^. The output gpuArray imagegpuarrayB^ has the same class as the input image. If^ gpuarrayA^ is a colormap, the input and output colormaps are gpuArrays of class double^. Examples Convert an RGB image to a grayscale image. I = imread('board.tif'); J = rgb2gray(I); figure, imshow(I), figure, imshow(J); Convert an RGB image to a grayscale image on a GPU. I = gpuArray(imread('board.tif')); J = rgb2gray(I); figure, imshow(I), figure, imshow(J); Convert the colormap to a grayscale colormap. [X,map] = imread('trees.tif'); gmap = rgb2gray(map); figure, imshow(X,map), figure, imshow(X,gmap);
Convert the colormap to a grayscale colormap on a GPU. Note how the example pass the colormap to the gpuArray function. [X,map] = imread('trees.tif');
% Pass colormap to gpuArray gmap = rgb2gray(gpuArray(map)); figure, imshow(X,map), figure, imshow(X,gmap);