轴坐标到像素坐标? (Matlab的) [英] Axis coordinates to pixel coordinates? (Matlab)

查看:82
本文介绍了轴坐标到像素坐标? (Matlab的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将轴坐标转换为像素坐标?我有一组包含负值和浮点值的数据,我需要将所有数据都放入图像中。但像素坐标都是正整数。如何解决负面问题?

How can i convert the axis coordinates into pixel coordinates? I have a set of data which include the negative and floating values, i need to put all of the data into the image. But the pixel coordinates are all positive integer. how to solve the negative issue?

推荐答案

您可以将坐标向量传递给 scatter

You can pass vectors of coordinates to scatter.

x = [-1.2 -2.4 0.3 7];
y = [2    -1   1  -3];
scatter(x,y,'.');

如果您需要图像矩阵,

h = figure();
scatter(x,y);
F = getframe(h);
img = F.cdata;

您还可以使用 print 来保存绘制到文件(或只是从图窗口导出),然后使用 imread 来读取文件。

You can also use print to save the plot to a file (or simply export from figure window), then use imread to read the file.

那里也是这一组来自文件交换的m文件已经非常接近你所需要的。

There is also this set of m-files from the File Exchange, which are already very close to what you need.

最后,这是一种在指定精度内获得所需内容的简单方法:

Finally, here is a simple way to get what you want, within a specified precision:

precision = 10;        %# multiple of 10
mi = min(min(x),min(y));
x = x - mi;        %# subtract minimum to get rid of negative numbers
y = y - mi;
x = round(x*precision) + 1;    %# "move" decimal point, round to integer,
y = round(y*precision) + 1;    %# add 1 to index from 1
img = zeros(max(max(x),max(y)));    %# image will be square, doesn't have to be
x = uint32(x);
y = uint32(y);
ind = sub2ind(size(img),y,x);    %# use x,y or reverse arrays to flip image
img(ind) = 1;    %# could set intensity or RGB values in a loop instead

precision参数确定多少小数将保持浮点值的位置,从而保持图像的分辨率和精度。可能不需要转换为 uint32

The "precision" parameter determines how many decimal places of the floating point values will be kept, and thus the resolution and accuracy of the image. The cast to uint32 might be unnecessary.

如果您有 Nx3 每个 N 点的RGB值矩阵:

If you have a Nx3 matrix of RGB values for each of N points:

img = zeros(max(max(x),max(y)),max(max(x),max(y)),3);
for i=1:length(N)        %# N = length(x) = length(y)
    img(x(i),y(i),:) = rgb(i,:);
end

这篇关于轴坐标到像素坐标? (Matlab的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆