根据MATLAB对测量每个超像素平均颜色的帮助,我将图像分割为200个超像素,并试图将输出图像中每个像素的颜色设置为超像素区域的平均CIELAB颜色。输入图像如下所示:

B=imread('H.jpg');
A=rgb2lab(B); // conversion from rgb to lab

[L,N] = superpixels(A,200);
figure
BW = boundarymask(L);
imshow(imoverlay(A,BW,'cyan'),'InitialMagnification',67);
outputImage = zeros(size(A),'like',A);
idx = label2idx(L);
numRows = size(A,1);
numCols = size(A,2);
for labelVal = 1:N
redIdx = idx{labelVal};
greenIdx = idx{labelVal}+numRows*numCols;
blueIdx = idx{labelVal}+2*numRows*numCols;
outputImage(redIdx) = mean(A(redIdx));
outputImage(greenIdx) = mean(A(greenIdx));
outputImage(blueIdx) = mean(A(blueIdx));
end
figure
imshow(outputImage,'InitialMagnification',67);


我不确定这段代码的输出是否正确地给出了CIELAB颜色空间中每个超像素的正确的平均颜色。图像是否与RGB颜色空间有如此不同的颜色,还是代码不正确?在测量CIELAB颜色空间通道的平均颜色时,编码中是否存在问题?
发布于 2019-03-03 03:57:14
请注意,尽管超像素算法SLIC在L*a*b*空间中工作,但它需要一个RGB图像作为输入。如果要像在用例中那样预先计算L*a*b*用于下游使用的表示,则需要使用'IsInputLab‘名称/值。否则,算法将尝试将已经存在的L*a*b*图像转换为L*a*b*。
你想:
B=imread('H.jpg');
A=rgb2lab(B);
[L,N] = superpixels(A, 200,'IsInputLab',true);Chris回答了超像素图中特征的平均计算。超像素之间的距离是相似的,基本上计算每个超像素的质心特征来描述它们的位置,然后测量它们之间的距离。注意,在下面的代码中,矩阵对其对角线是对称的,在对角线上是0。如果你关心这件事,我就让你来提高效率。
distanceMatrix = zeros(N,N);
for m = 1:N
for n = 1:n
[i1,j1] = ind2sub(size(A),idx{m});
[i1,j2] = ind2sub(size(A),idx{n});
Icenter1 = mean(i1);
Jcenter1 = mean(j1);
Icenter2 = mean(i2);
Jcenter2 = mean(j2);
distanceMatrix(m,n) = sqrt((Icenter1-Icenter2)^2+(Jcenter1-Jcenter2)^2);
end
endhttps://stackoverflow.com/questions/54959583
复制相似问题