简体   繁体   中英

how to convert a 3x3 matrix to an RGB image in matlab

suppose that I have the following code:

clc
clear
band1 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band1.tif');
band2 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band2.tif');
band3 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band3.tif');
band4 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band4.tif');
band5 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band5.tif');
band7 = imread('C:\Users\sepideh\Desktop\DrAkhundzadeh\Bands\band7.tif');
Vegetation = band4-band3;
Oxide = band3-band1;
Hydroxyl = band5-band7;
%Normalize
NormalizedVegetation = ( Vegetation - min(min(Vegetation)))*255/(max(max(Vegetation)) - min(min(Vegetation)));
NormalizedOxide = ( Oxide - min(min(Oxide)))*255/(max(max(Oxide)) - min(min(Oxide)));
NormalizedHydroxyl = ( Hydroxyl - min(min(Hydroxyl)))*255/(max(max(Hydroxyl)) - min(min(Hydroxyl)));
FalseColor(:,:,1) = NormalizedVegetation;
FalseColor(:,:,2) = NormalizedOxide;
FalseColor(:,:,3) = NormalizedHydroxyl;
RGBIMAG = uint8(FalseColor);
imshow(RGBIMAG);  

my problem is with the line:

RGBIMAG = uint8(FalseColor);  

which causes all the image to get darked. How can I tell matlab that each level of the 3 dimensional matrix are different band of an RGB image without changing its elements.

For converting to uint8, you must use:

RGBIMAG = im2uint8(FalseColor);

That function receives ur double array( values btw 0-1 ) and converts them to RGB values in the range (0, 255).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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