poster
2019-12-10, 20:48
我转储了视频的某些帧,并希望从中生成一个长方体,如以下示例图像所示:
https://i.stack.imgur.com/sMqZO.png
我想知道是否存在一个MATLAB函数来绘制这样的图?
回答:
目前还不清楚是什么格式的视频帧与开始,所以我会认为他们加载到MATLAB的电影帧的结构阵列(如描述在这里 (http://www.mathworks.com/help/techdoc/ref/getframe.html) )。我将创建一些示例电影数据(单个图像重复200次),以首先向您展示如何将第一帧加载到图像中以及如何在所有帧的顶部和侧面边缘之外创建图像(使用作为长方体的顶面和侧面):
M = repmat(im2frame(imread('peppers.png')),1,200); %# Sample movie data nFrames = numel(M); %# The number of frames face1 = frame2im(M(1)); %# Get the image for the front face [R,C,D] = size(face1); %# Get the dimensions of the image face2 = zeros(R,nFrames,3,'uint8'); %# Initialize the image for the side face face3 = zeros(nFrames,C,3,'uint8'); %# Initialize the image for the top face for k = 1:nFrames %# Loop over the frames img = frame2im(M(k)); %# Get the image for the current frame face2(:,k,:) = img(:,end,:); %# Copy the side edge to the side face image face3(k,:,:) = img(1,:,:); %# Copy the top edge to the top face image end 上面的代码假定影片帧是RGB图像 (http://www.mathworks.com/help/techdoc/creating_plots/f2-10709.html#f2-12468) ,而不是索引图像 (http://www.mathworks.com/help/techdoc/creating_plots/f2-10709.html#f2-155) 。如果他们是索引图像,你将获得从功能的附加颜色表的参数FRAME2IM (http://www.mathworks.com/help/techdoc/ref/frame2im.html) ,然后用它来将图像转换为使用功能的RGB图像IND2RGB (http://www.mathworks.com/help/techdoc/ref/ind2rgb.html) 。
接下来,您可以使用SURF (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/surf.shtml)函数将立方体的每一边绘制为纹理映射的表面:
offset = nFrames/sqrt(2); %# The offset in pixels between the back %# corners and front corners of the %# displayed cuboid surf([0 C; 0 C],... %# Plot the front face [RR; 0 0],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face1); hold on; %# Add to the existing plot surf([C C+offset; C C+offset],... %# Plot the side face [R R+offset; 0 offset],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face2); surf([0 C; offset C+offset],... %# Plot the top face [RR; R+offset R+offset],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face3); axis equal %# Make the scale on the x and y axes equal view(2); %# Change the camera view axis off %# Turn off display of the axes set(gcf,'Color','w'... %# Scale the figure up 'Position',[50 50 C+offset+20 R+offset+20]); set(gca,'Units','pixels',... %# Scale the axes up 'Position',[10 10 C+offset R+offset]); 这是结果图:
https://i37.photobucket.com/albums/e77/kpeaton/example_cuboid_new.png
更多&回答... (https://stackoverflow.com/questions/3627679)
https://i.stack.imgur.com/sMqZO.png
我想知道是否存在一个MATLAB函数来绘制这样的图?
回答:
目前还不清楚是什么格式的视频帧与开始,所以我会认为他们加载到MATLAB的电影帧的结构阵列(如描述在这里 (http://www.mathworks.com/help/techdoc/ref/getframe.html) )。我将创建一些示例电影数据(单个图像重复200次),以首先向您展示如何将第一帧加载到图像中以及如何在所有帧的顶部和侧面边缘之外创建图像(使用作为长方体的顶面和侧面):
M = repmat(im2frame(imread('peppers.png')),1,200); %# Sample movie data nFrames = numel(M); %# The number of frames face1 = frame2im(M(1)); %# Get the image for the front face [R,C,D] = size(face1); %# Get the dimensions of the image face2 = zeros(R,nFrames,3,'uint8'); %# Initialize the image for the side face face3 = zeros(nFrames,C,3,'uint8'); %# Initialize the image for the top face for k = 1:nFrames %# Loop over the frames img = frame2im(M(k)); %# Get the image for the current frame face2(:,k,:) = img(:,end,:); %# Copy the side edge to the side face image face3(k,:,:) = img(1,:,:); %# Copy the top edge to the top face image end 上面的代码假定影片帧是RGB图像 (http://www.mathworks.com/help/techdoc/creating_plots/f2-10709.html#f2-12468) ,而不是索引图像 (http://www.mathworks.com/help/techdoc/creating_plots/f2-10709.html#f2-155) 。如果他们是索引图像,你将获得从功能的附加颜色表的参数FRAME2IM (http://www.mathworks.com/help/techdoc/ref/frame2im.html) ,然后用它来将图像转换为使用功能的RGB图像IND2RGB (http://www.mathworks.com/help/techdoc/ref/ind2rgb.html) 。
接下来,您可以使用SURF (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/surf.shtml)函数将立方体的每一边绘制为纹理映射的表面:
offset = nFrames/sqrt(2); %# The offset in pixels between the back %# corners and front corners of the %# displayed cuboid surf([0 C; 0 C],... %# Plot the front face [RR; 0 0],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face1); hold on; %# Add to the existing plot surf([C C+offset; C C+offset],... %# Plot the side face [R R+offset; 0 offset],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face2); surf([0 C; offset C+offset],... %# Plot the top face [RR; R+offset R+offset],... [0 0; 0 0],... 'FaceColor','texturemap',... 'CData',face3); axis equal %# Make the scale on the x and y axes equal view(2); %# Change the camera view axis off %# Turn off display of the axes set(gcf,'Color','w'... %# Scale the figure up 'Position',[50 50 C+offset+20 R+offset+20]); set(gca,'Units','pixels',... %# Scale the axes up 'Position',[10 10 C+offset R+offset]); 这是结果图:
https://i37.photobucket.com/albums/e77/kpeaton/example_cuboid_new.png
更多&回答... (https://stackoverflow.com/questions/3627679)