要执行K均值聚类K = 3(段)。所以我:
To perform K means clustering with k = 3 (segments). So I:
1)转换的RGB IMG为灰度
1) Converted the RGB img into grayscale
2)铸造原始图像转换为X 1,列矩阵
2) Casted the original image into a n X 1, column matrix
3)IDX = k均值(column_matrix)
3) idx = kmeans(column_matrix)
4)输出= IDX,浇铸放回相同的尺寸与原始图像
4) output = idx, casted back into the same dimensions as the original image.
我的问题是:
A
当我这样做imshow(输出),我得到一个纯白色的图像。然而,当我这样做imshow(输出[0 5]),它显示了输出图像。我的理解是0和5指定显示范围。但是,为什么我必须这样做?
When I do imshow(output), I get a plain white image. However when I do imshow(output[0 5]), it shows the output image. I understand that 0 and 5 specify the display range. But why do I have to do this?
B) 现在的输出图像是指被划分成3个段权。我怎么门槛是这样的,我分配一个
B) Now the output image is meant to be split into 3 segments right. How do I threshold it such that I assign a
0为区域1的簇 1簇区域2的 2集群区域3
0 for the clusters of region 1 1 for clusters of region 2 2 for clusters of region 3
由于我的整点做这个集群是让我可以分割图像分为3个区域。
As the whole point of me doing this clustering is so that I can segment the image into 3 regions.
非常感谢。
亲切的问候。
答:考虑到你的矩阵输出
包含标值范围从1 3, imshow(输出)
被这当作一个的灰度的矩阵,假设全值范围是0到255这就是为什么制约了颜色限制是必要的,否则您的图像全白或几乎全白。
A: Given that your matrix output
contains scalar values ranging from 1 to 3, imshow(output)
is treating this as a grayscale matrix and assuming that the full range of values is 0 to 255. This is why constraining the color limits is necessary as otherwise your image is all white or almost all white.
B: 输出=输出 - 1