我正在尝试实现这个算法,但我对L,A和B的分类有点困惑。算法大纲如下:
我非常担心如何将L分类为阴影像素,将其他像素分类为非阴影像素。
这是实现算法的代码:
clear;
I = imread('flower.jpg');
rgb = imresize(I,[256,256]);
mlab = makecform('srgb2lab');
lab = applycform(rgb,mlab);
S_bin = im2bw(rgb);
S = S_bin + (S_bin == 0);
NS = S;
for i=1:255
for j=1:255
A = lab(j,i,2);
B = lab(j,i,3);
L = lab(j,i,1);
Lmean = mean(mean(L));
Amean = mean2(mean2(A));
Bmean = mean2(mean2(B));
if (Amean + Bmean) <= 256
Lstd = std2(L);
std = (Lmean-(Lstd/3));
Lmean = mean(mean(L));
if L <= std
S(j,i,1) = L;
S(j,i,2) = L;
S(j,i,3) = L;
else
S = lab;
end
else
if L < B
S(j,i,1) = L;
S(j,i,2) = L;
S(j,i,3) = L;
else
S(j,i,1) = B;
S(j,i,2) = B;
S(j,i,3) = B;
end
end
end
end
S = lab2rgb(S);
S=uint8(round(S*255));
figure(3);imshow(S);
答案 0 :(得分:0)
首先:L
,A
和B
是标量。只有一个单一的价值。因此,采取手段或标准偏差是行不通的。
首先分配L
,A
和B
,然后采用均值,标准偏差等,然后在第二个循环中构建您的图像:
I = imread('flower.jpg');
rgb = imresize(I,[256,256]);
mlab = makecform('srgb2lab');
lab = applycform(rgb,mlab);
S_bin = im2bw(rgb);
S = S_bin + (S_bin == 0);
NS = S;
L = squeeze(lab(:,:,1);
A = squeeze(lab(:,:,2);
B = squeeze(lab(:,:,3);
Lmean = mean(L(:));
Amean = mean(A(:));
Bmean = mean(B(:));
Lstd = std(L(:));
Astd = std(A(:));
Bstd = std(B(:));
if (Amean + Bmean) <= 256
if L<=(Lmean-(Lstd/3));
tmp = L<=(Lmean-(Lstd/3));
S(:,:,1) = zeros(size(L))+L(tmp);
S(:,:,2) = zeros(size(L))+L(tmp);
S(:,:,3) = zeros(size(L))+L(tmp);
else
S = lab;
end
tmp=L<B;
S(:,:,1) = zeros(size(L))+L(tmp);
S(:,:,1) = zeros(size(L))+L(tmp);
S(:,:,1) = zeros(size(L))+L(tmp);
tmp=L=>B;
S(:,:,1) = zeros(size(B))+B(tmp);
S(:,:,1) = zeros(size(B))+B(tmp);
S(:,:,1) = zeros(size(B))+B(tmp);
end
S = lab2rgb(S);
S=uint8(round(S*255));
figure(3);imshow(S);
通过这种方式,您只需获得一个颜色窗格,可以根据L
或B
进行着色,但由于您之前在代码中使用过,我将其保留在此处。