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

查看:38
本文介绍了轴坐标到像素坐标?(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.

还有这个 来自 File Exchange 的一组 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 个 RGB 值矩阵,用于 N 个点:

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天全站免登陆