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; endend
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; endend
Thank You.
Best Answer