简体   繁体   English

使用Image.CData在MATLAB中快速重绘图像

[英]Fast redrawing of image in MATLAB using Image.CData

I am want to draw once, and then update (very) often and redraw (less) often an image in MATLAB. 我想绘制一次,然后经常更新(非常)并在MATLAB中重绘(少)常常是一个图像。 My image is a vector which is updated and redrawn. 我的图像是一个更新和重绘的矢量。 To show this image, I used I = imagesc(reshape(data, nVoxels)) to draw and I.CData(:) = data to update. 为了显示这个图像,我使用了I = imagesc(reshape(data, nVoxels))来绘制和I.CData(:) = data要更新的I.CData(:) = data (Redrawing is taken care of seperately.) This worked fine. (重绘是单独处理的。)这很好。

Now, in order to make the correspondence to an xy-coordinate system (x horizontal, y vertical - very standard), where the first dimension of reshape(data, nVoxels) is x and the second is y, I need to draw like this: 现在,为了使对应于xy坐标系(x水平,y垂直 - 非常标准),其中reshape(data, nVoxels)的第一维reshape(data, nVoxels)是x而第二维是y,我需要像这样绘制:

I = imagesc(reshape(data, nVoxels)');
axis('xy');

But how can I make a quick update of the image data now? 但是,我现在如何快速更新图像数据呢?

So far, I have found I need to do 到目前为止,我发现我需要这样做

I.CData = reshape(data, nVoxels)';

but I would prefer to do something like before, updating CData without having to reallocate and without having to transpose the data. 但是我更愿意像以前那样做一些事情,更新CData而不必重新分配,也不必转置数据。

Is that possible? 那可能吗? I am specifically interested in updating very often in a loop; 我特别感兴趣的是在循环中经常更新; redrawing is handled independently using a timer. 使用计时器独立处理重绘。

The transpose can be avoided by setting x and y limits when you create the image to flip it, and rotating the axes: 当您创建图像以翻转它并旋转轴时,可以通过设置x和y限制来避免转置:

I = imagesc([nVoxels(2) 1], [1 nVoxels(1)], reshape(data, nVoxels));
camroll(90);

then using 然后使用

I.CData(:) = data;

again. 再次。

However, the transpose time is probably negligible compared to updating the figure using drawnow() . 但是,与使用drawnow()更新图形相比,转置时间可能可以忽略不计。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM