简体   繁体   English

使用MATLAB分割3-D矩阵

[英]Segementing a 3-D matrix with MATLAB

I have a 3-D matrix representing a hyper-spectral image: 2 dimensions represent different pixels, and 1 dimension represents different spectral bands. 我有一个表示高光谱图像的3-D矩阵:2个维度表示不同的像素,而1个维度表示不同的光谱带。

I need to segment this image in the following way: 1. divide the image, pixel-wise, into 2 segments. 我需要通过以下方式对该图像进行分段:1.将图像按像素划分为2个部分。 2. Calculate the average spectral value for each of the 2 segments. 2.计算两个段中每个段的平均光谱值。 3. Set all pixels in each of the 2 segments to be equal to said average. 3.将2个分段中的每个分段中的所有像素设置为等于所述平均值。

In the end, I need the image divided into 2 segments, with all pixels in the same segment equal to that segment's spectral average. 最后,我需要将图像分为2个部分,同一部分中的所有像素均等于该部分的光谱平均值。

I've tried using kmeans, but with no success so far. 我尝试过使用kmeans,但到目前为止没有成功。

Does anyone have any idea how to do it? 有谁知道如何做吗?

It would help if you elaborate on what about kmeans() is not working for you. 如果您详细说明kmeans()对您不起作用,这将有所帮助。 I suspect that you are trying to preserve the image dimensions (mxn pixels) in your call to kmeans . 我怀疑您在致电kmeans试图保留图像尺寸(mxn像素)。

If you collapse across rows/cols, kmeans should be able to classify each pixel by its spectral-band vector. 如果您在行/列之间折叠,则kmeans应该能够通过其光谱带向量对每个像素进行分类。

[m,n,sps] size(data); %pixel row, pixel col, spectral band
numGroups = 2;
[idx,centers] = kmeans(reshape(data,[m*n,sps]),numGroups);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM