Reshape Video Matrix Into Long RGB Matrix and Back
Ältere Kommentare anzeigen
Hello,
Let's say I have a Video Matrix `mVideoMatrix`.
This is a 4D matrix (Numnber of Rows x Number of Columns x Number of Color Channels x Number of Frames).
For instance, 360 x 480 x 3 x 10, namely 360 Rows, 480 Columns, 3 RGB Channels and 10 Frames.
Now I want to make it a long RGB image where each frame is beneath the previous one. Is the a vectorized way to do so?
How would you formulate the way back, namely from the image into the Video?
I'm attaching sample codes which use "For Loop".
At first, reshaping RGB Video into long RGB Image:
function [ mOutputImage ] = ReshapeVideoIntoImage( tInputVideo )
numRows = size(tInputVideo, 1);
numCols = size(tInputVideo, 2);
numChannels = size(tInputVideo, 3);
numFrames = size(tInputVideo, 4);
mOutputImage = zeros([(numFrames * numRows), numCols, numChannels]);
firstRowIdx = 1;
for iFrameIdx = 1:numFrames
vRows = (firstRowIdx - 1) + [1:numRows];
mOutputImage(vRows, :, :) = tInputVideo(:, :, :, iFrameIdx);
firstRowIdx = firstRowIdx + numRows;
end
end
Going back, from long RGB Image into RGB Video:
function [ tOutputVideo ] = ReshapeImageIntoVideo( mInputtImage, videoNumRows )
numRows = size(mInputtImage, 1);
numCols = size(mInputtImage, 2);
numChannels = size(mInputtImage, 3);
videoNumFrames = numRows / videoNumRows;
tOutputVideo = zeros([videoNumRows, numCols, numChannels, videoNumFrames]);
firstRowIdx = 1;
for iFrameIdx = 1:videoNumFrames
vRows = (firstRowIdx - 1) + [1:videoNumRows];
tOutputVideo(:, :, :, iFrameIdx) = mInputtImage(vRows, :, :);
firstRowIdx = firstRowIdx + videoNumRows;
end
end
Thank You.
Akzeptierte Antwort
Weitere Antworten (2)
Sid
am 29 Jun. 2015
Can you use something like this?
% Concatenate along 'fourth' dimension.
alpha = cat(4,newArray(:,:,:));
% Extract every third color plane, starting with 1.
red = alpha(:,:,1:3:size(alpha,3));
red = vertcat(red(:,:));
% Extract every third color plane, starting with 2.
green = alpha(:,:,2:3:size(alpha,3));
green = vertcat(green(:,:));
% Extract every third color plane, starting with 3.
blue = alpha(:,:,3:3:size(alpha,3));
blue = vertcat(blue(:,:));
RGB = cat(3,red,green,blue);
figure, imshow(RGB)
where newArray refers to the original 4-D array.
Perhaps I'm missing something, but I'm not sure I completely follow the logic of concatenating images?
HTH.
1 Kommentar
Royi Avital
am 29 Jun. 2015
Image Analyst
am 29 Jun. 2015
To stitch the frames together vertically, do this:
numFrames = size(myVideo, 4);
stitchedImage = [];
for k = 1 : numFrames
stitchedImage = [stitchedImage; myVideo(:,:,:,k)];
end
1 Kommentar
Royi Avital
am 30 Jun. 2015
Kategorien
Mehr zu Video Formats and Interfaces finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!