Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Eberechi ICHI
Eberechi ICHI am 11 Okt. 2022
Kommentiert: Eberechi ICHI am 12 Okt. 2022
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);

Akzeptierte Antwort

DGM
DGM am 12 Okt. 2022
Bearbeitet: DGM am 12 Okt. 2022
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');

Weitere Antworten (1)

Martin Pryde
Martin Pryde am 12 Okt. 2022
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

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by