how to change luminance level of binary image?
조회 수: 3(최근 30일)
Walter Roberson 2014년 1월 24일
rgbbinimg = repmat(double(binimg), [1 1 3]);
Now you can play with the rgb values associated with rgbbinimg
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
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
... 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).