How to apply the outlines defined by superpixels to a hyperspectral image to calculate the mean spectrum of each superpixel?
1 次查看(过去 30 天)
显示 更早的评论
I have applied the function superpixels to extract the outlines of several pixels wich have similar colour within an RGB image. Now I want to apply these outlines to the original hypercube to obtain the mean spectrum for each of these superpixels. Can you help me?
0 个评论
采纳的回答
Parth Parikh
2023-3-21
Hi Laura,
Here is the code you can try:
Suppose you have number of labels (N) and label matrix (L) from superpixels function.
[rows, cols, channels] = size(hypercube);
hypercube = reshape(hypercube, [rows*cols channels]);
idx = label2idx(L);
outputImg = zeros(rows*cols, channels);
for labelVal = 1:N
idxs = idx{labelVal};
outputImg(idxs, :) = repmat(mean(hypercube(idxs,:)), length(idxs),1);
end
outputImg = reshape(outputImg, [rows, cols, channels]);
I am assuming instead of taking mean in spatial dimension, you would like to take a mean of spectral dimension.
If you would like to explore more about the hyperspectral domain, kindly go through this:
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!