how to split darker and brighter pixels using a threshold value?

in=imread('window.jpg');
i_in=im2double(in);
i_in=imresize(i_in,[4 4]);
imshow(i_in);
figure(1);
%%LOGRATHIMIC NORMALIZATION
do=rgb2ycbcr(i_in);
% % Extract color
%logarithmic Normalization.
y =do(:,:,1); % Luminance channel
cb =do(:,:,2); % chroma blue channel
cr =do(:,:,3); % chroma red channel
Lin=0.299*do(:,:,1)+0.587*do(:,:,2)+0.114*do(:,:,3);
x=(max(max(Lin)))+1;
Llog=((log(Lin)+1)/log(x));
figure(2);
imshow(Llog);
A=Llog;
%splitting darker and bright pixels
m=4;
%For bright areas
for x=1:m
for y=1:m
if A(x,y)>0.5
b(x,y)=A(x,y);
end
end
end
%for dark areas
for x=1:m
for y=1:m
if A(x,y)<0.5
d(x,y)=A(x,y);
end
end
end
In the above code i got an error on bright area..In b(x,y) i only need pixels values which is greater than threshold,but i didnt get it..I have attached the Input and Bright values of an image for your reference.can you tell me what mistake i have done..

 采纳的回答

There is no need to use for loop. Are you looking for something like this
close all
in=imread('window.jpeg');
i_in=im2double(in);
% i_in=imresize(i_in);
figure(1);
subplot(321)
imshow(i_in);
title('original')
%%LOGRATHIMIC NORMALIZATION
do=rgb2ycbcr(i_in);
% % Extract color
%logarithmic Normalization.
y =do(:,:,1); % Luminance channel
cb =do(:,:,2); % chroma blue channel
cr =do(:,:,3); % chroma red channel
Lin=0.299*do(:,:,1)+0.587*do(:,:,2)+0.114*do(:,:,3);
x=(max(max(Lin)))+1;
Llog=((log(Lin)+1)/log(x));
% figure(2);
subplot(322)
imshow(Llog);
title('LOGRATHIMIC NORMALIZATION')
A=Llog;
B = A;
B(B<0.5) = 0;
D = A;
D(D>0.5) = 0;
% figure(3);
subplot(323)
imshow(B)
title('brigh portion')
% figure(4);
subplot(324)
imshow(D)
title('Dark portion')
B_mask = A>0.5;
D_mask = A<0.5;
% figure(5);
subplot(325)
imshow(B_mask)
title('Bright Mask')
% figure(6);
subplot(326)
imshow(D_mask)
title('Dark Mask')

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by