1.load('E:\数据集\Harvard\CZ_hsdb\imga1.mat')
2.whos
3.InputMatImg=ref;
b = size(InputMatImg);
fprintf('输入图像宽度为 %d\n',b(1));
fprintf('输入图像高度为 %d\n',b(2));
fprintf('输入图像波段数为 %d\n',b(3));
i=1;j=15;k=30;%自选三个波段
InputImg_r= InputMatImg(:,:,i);%获取第i个波段
InputImg_g= InputMatImg(:,:,j);%获取第j个波段
InputImg_b= InputMatImg(:,:,k);%获取第k个波段
InputImg_r= uint8(InputImg_r);%将i波段的灰度值转为0~255
InputImg_g= uint8(InputImg_g);%将j波段的灰度值转为0~255
InputImg_b= uint8(InputImg_b);%将k波段的灰度值转为0~255
RGBImg=cat(3,InputImg_r,InputImg_g,InputImg_b);%将i、j、k三个波段进行合成
figure;
subplot(221);imshow(InputImg_r);title('红色波段');
subplot(222);imshow(InputImg_g);title('绿色波段');
subplot(223);imshow(InputImg_b);title('蓝色波段');
subplot(224);imshow(RGBImg);title('合成波段');
imwrite(InputImg_r,['MATBand',num2str(i),'.jpg']);
imwrite(InputImg_g,['MATBand',num2str(j),'.jpg']);
imwrite(InputImg_b,['MATBand',num2str(k),'.jpg']);
imwrite(RGBImg,'compositeMATRGBimg.jpg');