这是我将 512*512 图像切成 64*64*64 维立方体的代码。 但是当我再次将其重塑为 2D 数组时,为什么它没有给我原始 image.am 我做了错误的事情,请帮忙。
clc;
im=ind2gray(y,ymap);
% im=imresize(im,0.125);
[rows ,columns, colbands] = size(im)
end
image3d=reshape(image3d,512,512);
figure,imshow(uint8(image3d));
只是一个小小的提示。
P(:,:,1) = [0,0;0,0]
P(:,:,2) = [1,1;1,1]
P(:,:,3) = [2,2;2,2]
P(:,:,4) = [3,3;3,3]
B = reshape(P,4,4)
B =
0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3
因此,您可以更改切片或自行重塑。
如果我正确理解了您的问题,您可以查看下面的代码来执行相同的操作。
% Random image of the provided size 512X512
imageX = rand(512,512)
imagesc(imageX)
% Converting the image "imageX" into the cube of 64X64X64 dimension
sliceColWise = reshape(imageX,64,64,64)
size(sliceColWise)
% Reshaping the cube to obtain the image original that was "imageX",
% in order to observe that they are identical the difference is plotted
imageY = reshape(sliceColWise,512,512);
imagesc(imageX-imageY)
注意:从 MATLAB 帮助中,您可以看到整形在列上工作
reshape(X,M,N) 或 reshape(X,[M,N]) 返回 M-by-N 矩阵 其元素从 X 逐列取。产生错误 如果 X 没有 M*N 元素。