필터 지우기
필터 지우기

How to use function 'ind2gray'

조회 수: 4 (최근 30일)
Atinesh Singh
Atinesh Singh 2016년 7월 10일
댓글: Image Analyst 2016년 7월 10일
I'm trying to convert uint8 image to grayscale image using the following command
a = imread('image.png'); % a dimension 18*24*3
b = ind2gray(a, map);
But I'm getting an error message saying
Undefined function or variable 'map'

채택된 답변

Image Analyst
Image Analyst 2016년 7월 10일
You need to have some way to tell the function what color should get mapped to what gray level. The colors are a 2D array with columns for red green, and blue in the range 0-1, and one row for each gray level or range of gray levels. There are several built-in color maps to select from - see the help for colormap. For example you could do
rgbImage = ind2rgb(grayImage, jet(256));
colorbar;
jet() is a function that builds a colormap of a certain pattern with the number of gray levels you specify. There are others too. Or you could make up your own colormap completely customized.
  댓글 수: 2
Atinesh Singh
Atinesh Singh 2016년 7월 10일
When I'm reading an image using this command
a = imread('image.png');
I'm getting three dimensions
18*24*3
I just need an array of 2 dimensions.
Image Analyst
Image Analyst 2016년 7월 10일
Then image.png is an RGB image, not an indexed image. You have to convert it to a grayscale image somehow. There are a variaety of ways to do this and I don't know what method you want to use. For example, one way is to use rgb2gray():
indexedImage = rgb2gray(rgbImage);
Or you could take just one color channel, such as the green channel, which tends to be the least noisy:
indexedImage = rgbImage(:, :, 2);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by