我有兴趣在Matlab(2015a)中使用测地距离变换来获得图片的分割区域,我可以从中对特定区域进行操作。
我已将此处列出的代码(http://www.mathworks.com/help/images/ref/imseggeodesic.html)合并,并可以重现他们的图像。但是,我不确定如何在任何特定的分段区域上执行操作。
L = imseggeodesic(RGB,BW1,BW2); 图,imshow(label2rgb(L));
上面的片段将显示分割成浅蓝色和深蓝色区域的图片,其中深蓝色区域代表原始图片中的黄色花朵。例如,我怎样才能单独对黄花进行颜色直方图均衡化?
单独显示L(没有label2rgb)会产生一个纯白色的图像,导致我认为它是空白的(因为我无法使用它)。那么我可以将label2rgb(L)存储到另一个变量中,将浅蓝色区域(背景,而不是花朵)设置为阈值并执行操作以单独影响黄色花朵吗?或者使用它会更好:
[L,P] = imseggeodesic(RGB,BW1,BW2)
用于阈值目的吗?
任何建议,特别是编码都会有很大的帮助。
答案 0 :(得分:0)
如果要将L矩阵转换为二进制图像,请使用以下代码:
[r,c]=size(L);% row and column length matrix L
BW=[];
for i=1 : r ;
for j=1:c;
if L(i,j)==2;
BW(i,j)=1;% assign class 2 a 1 (true)
else BW(i,j)=0;% assign class 1 a 0 (false)
end
end
end
您可以看到如下结果:
figure;imshow(BW);% background is assigned a 1 (1= true= white) and the flower 0 (0=false=black)
图像的反转如下:
BWinverse=~BW;
figure;imshow(BWinverse); % background is assigned a 0 and the flower 1
如果您想进一步细分背景,请使用:
maskedRgbImage = bsxfun(@times,RGB, cast(BW, class(RGB)));
figure;imshow(maskedRgbImage);%puts a mask on the flower (assigns the background pixels a 0)
如果您想进一步分割花朵:
maskedRgbImage = bsxfun(@times,RGB, cast(BWinverse, class(RGB)));
figure;imshow(maskedRgbImage);% puts a mask on the background