Home > Software engineering >  How to convert hyperspectral image to RGB in Matlab
How to convert hyperspectral image to RGB in Matlab

Time:10-14

I have a problem with extracting 3 bands under the names R, G, and B, and then using those bands as 3 colour channels for RGB pictures. It is a hyperspectral image and it has 103 bands opposite to the normal RGB image which contains just 3. The one who gave me this question to solve, described it as something very basic, however, I am having a very difficult time with it. I may have syntax problems with Matlab. The picture comes as a .mat file. with the size of 610x340x103. I used different codes, searched forums etc. But I failed. here is the code I tried last time.

load("PaviaU.mat")
Blue=paviaU(:,:,7);
imwrite(Blue,"Blue.jpg")
newBlue=imread("Blue.jpg");
imshow(newBlue)
imagesc(newBlue) %*this line gives the result as a scaled image*

Green=paviaU(:,:,21);
imwrite(Green,"Green.jpg")
newGreen=imread("Green.jpg");
imshow(newGreen)

Red=paviaU(:,:,53);
imwrite(Red,"Red.jpg")
newRed=imread("Red.jpg");
imshow(newRed)

rgbImage = paviaU(:,:,[newRed,newGreen,newBlue])

when I use imagesc(Red) instead of imshow I see pictures as a result, but it is not what I would like to see. Also, I analysed this .mat file on the App section of Matlab where there is a hyperspectral image app, I could not observe the spectrum because band information was absent. However, I think, inside the library of image processing there is a file with the name of paviaU.dat that file works, and inside the App, I observed the spectrum and played with it. What is the point I don't understand here? Is there a solution? You can find that PaviaU.mat file with the variable inside as paviaU through this link enter image description here

  • Related