Clear Filters
Clear Filters

how to change luminance level of binary image?

1 view (last 30 days)
NIVETHA RAJENDRAN
NIVETHA RAJENDRAN on 24 Jan 2014
Edited: DGM on 13 Nov 2022
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)

Answers (2)

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

DGM
DGM on 13 Nov 2022
Edited: DGM on 13 Nov 2022
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!