matlab:如何绘制多维数组

发布于 2024-09-27 19:41:35 字数 403 浏览 1 评论 0原文

假设我有 9 MxN 黑白图像,它们以某种方式相互关联(即某个事件的延时)。有什么方法可以在一个曲面图上显示所有这些图像?

假设 MxN 矩阵仅包含 0 和 1。假设图像仅包含黑色背景上的白线(即,如果该像素是线的一部分,则像素值 == 1,否则为 0)。假设图像以建议后续图像中的线的移动进程的方式排序。我希望能够看到这些图像的“侧视图”(或体积表示),它将显示特定线条在图像上移动时“雕刻出”的表面。

编码是在 MATLAB 中完成的。我查看了 plot (但它只执行 2D 绘图)和 surf,它执行 3D 绘图,但不适用于我的 MxNx9 图像矩阵。我也尝试过使用 contourslice 进行实验,但不确定要传递哪些参数。

谢谢!

玛丽亚

Let's say I have 9 MxN black and white images that are in some way related to one another (i.e. time lapse of some event). What is a way that I can display all of these images on one surface plot?

Assume the MxN matrices only contain 0's and 1's. Assume the images simply contain white lines on a black background (i.e. pixel value == 1 if that pixel is part of a line, 0 otherwise). Assume images are ordered in such a way as to suggest movement progression of line(s) in subsequent images. I want to be able to see a "side-view" (or volumetric representation) of these images which will show the surface that a particular line "carves out" in its movement across the images.

Coding is done in MATLAB. I have looked at plot (but it only does 2D plots) and surf, which does 3D plots but doesn't work for my MxNx9 matrix of images. I have also tried to experiment with contourslice, but not sure what parameters to pass it.

Thanks!

Mariya

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩套路吗 2024-10-04 19:41:35

这些图像是在“空白”字段上具有简单特征的黑白图像,还是具有更密集信息的灰度图像?

我可以看到几种方法。

您可以使用 movie() 将一系列图像显示为动画。

对于稀疏、简单数据的静态视图,您可以将每个图像绘制为单个图中的单独图层,为每个图层提供不同的前景颜色,并使用 AlphaData 使背景透明,以便序列中的所有步骤都显示通过。颜色的梯度对应于图像序列中的位置。这是一个例子。

function plotImageSequence

% Made-up test data
nLayers = 9;
x = zeros(100,100,nLayers);
for i = 1:nLayers
    x(20+(3*i),:,i) = 1;
end

% Plot each image as a "layer", indicated by color
figure;
hold on;
for i = 1:nLayers
    layerData = x(:,:,i);
    alphaMask = layerData == 1;
    layerData(logical(layerData)) = i; % So each layer gets its own color
    image('CData',layerData,...
        'AlphaData',alphaMask,...
        'CDataMapping','scaled');
end
hold off

使用栅格数据直接显示一条“线”所形成的移动路径是很困难的,因为 Matlab 不知道两个后续图像中哪些“移动”像素彼此关联。您是否认为您没有图像中几何特征的基础矢量数据? Plot3() 可能允许您显示它们的运动,以时间为 z 轴。或者您可以使用常规的plot()和一些手动操作来绘制几何特征中所有控制点或顶点的路径。


编辑:这是一个变体,使用 patch() 将每个像素绘制为漂浮在图像序列中索引的 Z 级别空间中的小多边形。我认为这看起来更像是您要求的“表面”风格的图。您可以调整 FaceAlpha 属性以使密集的图更清晰。

function plotImageSequencePatch

% Made-up test data
nLayers = 6;
sz = [50 50];
img = zeros(sz(1),sz(2),nLayers);
for i = 1:nLayers
    img(20+(3*i),:,i) = 1;
end

% Plot each image as a "layer", indicated by color
% With each "pixel" as a separate patch
figure;
set(gca, 'XLim', [0 sz(1)]);
set(gca, 'YLim', [0 sz(2)]);
hold on;
for i = 1:nLayers
    layerData = img(:,:,i);
    [x,y] = find(layerData);  % X,Y of all pixels
    % Reshape in to patch outline
    x = x';
    y = y';
    patch_x = [x; x+1; x+1; x];
    patch_y = [y; y; y+1; y+1];
    patch_z = repmat(i, size(patch_x));

    patch(patch_x, patch_y, patch_z, i);
end
hold off

Are these images black and white with simple features on a "blank" field, or greyscale, with more dense information?

I can see a couple of approaches.

You can use movie() to display a sequence of images as an animation.

For a static view of sparse, simple data, you could plot each image as a separate layer in a single figure, giving each layer a different color for the foreground, and using AlphaData to make the background transparent so all the steps in the sequenc show through. The gradient of colors corresponds to position in the image sequence. Here's an example.

function plotImageSequence

% Made-up test data
nLayers = 9;
x = zeros(100,100,nLayers);
for i = 1:nLayers
    x(20+(3*i),:,i) = 1;
end

% Plot each image as a "layer", indicated by color
figure;
hold on;
for i = 1:nLayers
    layerData = x(:,:,i);
    alphaMask = layerData == 1;
    layerData(logical(layerData)) = i; % So each layer gets its own color
    image('CData',layerData,...
        'AlphaData',alphaMask,...
        'CDataMapping','scaled');
end
hold off

Directly showing the path of movement a "line" carves out is hard with raster data, because Matlab won't know which "moved" pixels in two subsequent images are associated with each other. Don't suppose you have underlying vector data for the geometric features in the images? Plot3() might allow you to show their movement, with time as the z axis. Or you could use the regular plot() and some manual fiddling to plot the paths of all the control points or vertexes in the geometric features.


EDIT: Here's a variation that uses patch() to draw each pixel as a little polygon floating in space at the Z level of its index in the image sequence. I think this will look more like the "surface" style plots you are asking for. You could fiddle with the FaceAlpha property to make dense plots more legible.

function plotImageSequencePatch

% Made-up test data
nLayers = 6;
sz = [50 50];
img = zeros(sz(1),sz(2),nLayers);
for i = 1:nLayers
    img(20+(3*i),:,i) = 1;
end

% Plot each image as a "layer", indicated by color
% With each "pixel" as a separate patch
figure;
set(gca, 'XLim', [0 sz(1)]);
set(gca, 'YLim', [0 sz(2)]);
hold on;
for i = 1:nLayers
    layerData = img(:,:,i);
    [x,y] = find(layerData);  % X,Y of all pixels
    % Reshape in to patch outline
    x = x';
    y = y';
    patch_x = [x; x+1; x+1; x];
    patch_y = [y; y; y+1; y+1];
    patch_z = repmat(i, size(patch_x));

    patch(patch_x, patch_y, patch_z, i);
end
hold off
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文