how to change luminance level of binary image?

조회 수: 2 (최근 30일)
NIVETHA RAJENDRAN
NIVETHA RAJENDRAN 2014년 1월 24일
편집: DGM 2022년 11월 13일
i=imread('aa1.jpg');
figure,imshow(i(:,:,1))
YCBCR = rgb2ycbcr(i);
figure,imshow(YCBCR);
lev=graythresh(i(:,:,1));
binimg=im2bw(YCBCR,lev);
figure;imshow(binimg)

답변 (2개)

Walter Roberson
Walter Roberson 2014년 1월 24일
rgbbinimg = repmat(double(binimg), [1 1 3]);
Now you can play with the rgb values associated with rgbbinimg

DGM
DGM 2022년 11월 13일
편집: DGM 2022년 11월 13일
The problem here is simple. You're calculating the threshold values from the luma channel (Y), but you're not thresholding the luma channel. Instead, you pass the entire YCbCr image to im2bw(). When im2bw() receives a 3-channel image, it assumes that it's RGB and does a RGB-Y transformation on it. In this case, the result is nonsense, since the input isn't RGB. It's YCbCr.
% you have an RGB image
RGB = imread('peppers.png');
% you turn it into a YCC image
YCBCR = rgb2ycbcr(RGB);
% if you pass im2bw() a 3-channel YCC image,
% it will internally create this nonsense image
imagethatgetsbinarized = rgb2gray(YCBCR);
% which looks like this
imshow(imagethatgetsbinarized)
That's the image that you're trying to binarize. A (typically) low-contrast image that's heavily weighted toward central gray values (due to the influence and symmetry of Cb,Cr). It's understandable that the threshold values calculated for this image
imshow(YCBCR(:,:,1))
... won't work well on the improperly-transformed image that's actually being used.
If you want to threshold on Y, pass Y to im2bw() (or imbinarize() in more modern versions).

Community Treasure Hunt

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

Start Hunting!

Translated by