%读入6幅图像(每一幅图像的大小是564*564)
f1 = imread('WashingtonDC_Band1_564.tif');
subplot(3,2,1),imshow(f1);
f2 = imread('WashingtonDC_Band2_564.tif');
subplot(3,2,2),imshow(f2);
f3 = imread('WashingtonDC_Band3_564.tif');
subplot(3,2,3),imshow(f3);
f4 = imread('WashingtonDC_Band4_564.tif');
subplot(3,2,4),imshow(f4);
f5 = imread('WashingtonDC_Band5_564.tif');
subplot(3,2,5),imshow(f5);
f6 = imread('WashingtonDC_Band6_564.tif');
subplot(3,2,6),imshow(f6);
% 对图像进行堆叠
S = cat(3,f1,f2,f3,f4,f5,f6);
[X,R] = imstack2vectors(S);
P = princomp(X,6);
% 显示主分量图像
g1 = P.Y(:,1);
g1 = reshape(g1,512,512);
subplot(3,2,1),imshow(g1,[]);
g2 = P.Y(:,2);
g2 = reshape(g2,512,512);
subplot(3,2,2),imshow(g2,[]);
g3 = P.Y(:,3);
g3 = reshape(g3,512,512);
subplot(3,2,3),imshow(g3,[]);
g4 = P.Y(:,4);
g4 = reshape(g4,512,512);
subplot(3,2,4),imshow(g4,[]);
g5 = P.Y(:,5);
g5 = reshape(g5,512,512);
subplot(3,2,5),imshow(g5,[]);
g6 = P.Y(:,6);
g6 = reshape(g6,512,512);
subplot(3,2,6),imshow(g6,[]);
上述代码运行后出现错误:
错误使用 reshape要执行 RESHAPE,请勿更改元素数目。
将代码修改为:
%读入6幅图像(每一幅图像的大小是564*564)
f1 = imread('WashingtonDC_Band1_564.tif');
subplot(3,2,1),imshow(f1);
f2 = imread('WashingtonDC_Band2_564.tif');
subplot(3,2,2),imshow(f2);
f3 = imread('WashingtonDC_Band3_564.tif');
subplot(3,2,3),imshow(f3);
f4 = imread('WashingtonDC_Band4_564.tif');
subplot(3,2,4),imshow(f4);
f5 = imread('WashingtonDC_Band5_564.tif');
subplot(3,2,5),imshow(f5);
f6 = imread('WashingtonDC_Band6_564.tif');
subplot(3,2,6),imshow(f6);
% 对图像进行堆叠
S = cat(3,f1,f2,f3,f4,f5,f6);
[X,R] = imstack2vectors(S);
P = princomp(X,6);
% 显示主分量图像
g1 = P.Y(:,1);
g1 = reshape(g1,564,564);
subplot(3,2,1),imshow(g1,[]);
g2 = P.Y(:,2);
g2 = reshape(g2,564,564);
subplot(3,2,2),imshow(g2,[]);
g3 = P.Y(:,3);
g3 = reshape(g3,564,564);
subplot(3,2,3),imshow(g3,[]);
g4 = P.Y(:,4);
g4 = reshape(g4,564,564);
subplot(3,2,4),imshow(g4,[]);
g5 = P.Y(:,5);
g5 = reshape(g5,564,564);
subplot(3,2,5),imshow(g5,[]);
g6 = P.Y(:,6);
g6 = reshape(g6,564,564);
subplot(3,2,6),imshow(g6,[]);
运行上述修改后的代码之后,就不会出现reshape错误。
待处理的原图
处理后的主分量图像
本人错误原因:重建的图像与原图大小不一致导致出错,因此,在重建的reshape语句进行运行时,要确保图像的像素一致。(这是本人学习中的出错与纠错,仅仅是希望能够帮助到有相似错误的朋友,谢谢大家,希望与大家一起进步。)