我该如何在MATLAB中重现这个长方体图形?

3

我截取了视频的一些帧,并希望根据这些帧生成一个立方体,就像下面的示例图像:

alt text

我想知道是否存在MATLAB函数可以进行这种绘制?


“cuboid”这个词有不同的定义,您能具体说明一下吗? - Alex Feinman
你的视频帧在MATLAB中是如何存储的?它们是以电影帧的结构数组形式存储的(具有“cdata”和“colormap”字段),还是以4-D数组的形式(例如,沿第四维连接的一组3-D RGB图像),或者其他格式? - gnovice
1个回答

2
“不清楚你的视频帧最初是以什么格式存在的,因此我假设它们已经作为电影帧的结构数组加载到MATLAB中(如这里所述)。我将创建一些示例电影数据(重复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图像而不是索引图像。如果它们是索引图像,则必须从函数FRAME2IM获取附加的颜色映射参数,然后使用函数IND2RGB将图像转换为RGB图像。
接下来,您可以使用SURF函数将立方体的每个面作为贴图表面绘制出来:
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
     [R R; 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
     [R R; 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]);

这是生成的图形:

alt text


谢谢gnovice。这正是我在寻找的!最好的祝愿。 - Javier

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接