SAVE A 4D DATA WITH THE BLOCKS STACKED SIDE BY SIDE

1 次查看(过去 30 天)
Please i need your assistance to complete this code.
Y_pred_1 is a 32x32x2x663 data.
I wanted to extract the 32x32x1 for all the 663 blocks and convert them to an image with size 416x1632 where the 32x32 blocks are stacked side by side along the rows to form the final image (416x1632).
The final output B13 is stacking each column of B12 vertically and not rather the block horizontally.
n=size(Y_pred_1, 4)
for i = 1:n;
pred_1(:,:,1,i) = Y_pred_1(:,:,1,i);
end
B1 = reshape(pred_1, [], size(Y_pred,4));
B12 = reshape(B1, [32,32,663]);
B13=reshape(B12,416,1632);

采纳的回答

DGM
DGM 2022-10-12
编辑:DGM 2022-10-12
Alternatively, you could use IPT imtile().
A = rand(32,32,2,663); % initial 2-channel multiframe image
B = imtile(A(:,:,1,:),'gridsize',[NaN 51]); % tiled composite of first channel
Note that imtile() always tiles the frames in a row-wise fashion. If that weren't your requirement, using imtile() would get more cumbersome.
MIMT has a similar tool of the same name, but it doesn't have the same limitation. With MIMT imtile(), you could just explicitly specify the tiling direction:
C = imtile(A(:,:,1,:),[NaN 51],'direction','col');

更多回答(1 个)

Martin Pryde
Martin Pryde 2022-10-12
It would be helpful if you could provide example data for Y_pred_1.
MATLAB arranges all 2D and multidimensional rows first hence why your blocks are stacking vertically. Input your horizontal resolution as your first dimension and simply transpose the result (B13 = reshape(B12,1632,416).';).
On the otherhand, the description you provided reads to me like your code would be more readable and terse if you used cells.
Y_pred_1 = rand(32,32,2,663); % your data
bar = cell2mat(reshape(num2cell(squeeze(Y_pred_1(:,:,1,:)),[1,2]),1632/32,[])).'; % your image

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by