what is the difference between rgb2gray and im2bw ?

조회 수: 10 (최근 30일)
Mahmoud Hassan
Mahmoud Hassan 2019년 4월 21일
댓글: Walter Roberson 2019년 4월 21일
I want to know the difference between the two functions ... arent both convert the rgb image to black and white image ?!

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 21일
No, rgb2gray() converts to grayscale. For uint8 images, the output could have up to 256 unique values in the matrix. im2bw() converts to bi-level, and has only 2 unique values in its output matrix.
Effectively rgb2gray() converts RGB to "brightness", whereas im2bw() converts to two color ("logical" data type in fact.)
  댓글 수: 2
Mahmoud Hassan
Mahmoud Hassan 2019년 4월 21일
편집: Mahmoud Hassan 2019년 4월 21일
its about that i face a problem in my code when i read image then try to binarize it using imb2w ... thats the error " Error using im2bw>parse_inputs (line 97)
IM2BW: Truecolor RGB image has to be an M-by-N-by-3 array."
so i thougt i have to use rgb2gray first then use imb2w ... am i right ?!
Walter Roberson
Walter Roberson 2019년 4월 21일
You can apply im2bw() to an RGB image or to a grayscale image.
But as discussed in my answer to your other question, https://www.mathworks.com/matlabcentral/answers/457695-how-to-know-if-image-is-rgb#answer_371591 there is a possibility that you are not using an RGB image. You might have RGBA or you might have a DICOM volume. Or maybe what you are passing is not a numeric array at all. Check with class() and size()

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by