MATLAB - 如何在图像上绘制x,y并保存? [英] MATLAB - How to plot x,y on an image and save?

查看:499
本文介绍了MATLAB - 如何在图像上绘制x,y并保存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code  x     y
23    22.1  33.11
23    110   22
23    11    200 
24    111   321
24    222   111
24    10    22.1
10    88.3  99.3
10    110   32
10    121   143
10    190   200

在上面的文件中,第一列代表屏幕上显示的图像代码,x和y列代表人们在图像上看到的点。向用户显示了三个不同的图像。下面的代码的问题是我不知道如何使用与打开的文件相同的名称来保存图像。

In the above file, the first column represents the image code which is displayed on the screen, and the x and y columns represent the point where people look on the image. There were three different images displayed to the user. The problem with the code below is that I don't know how to save the image with the plotted x-y on with the same name of file as it opened.

fid = fopen(datafile.txt);
A = textscan(fid,'%f%f%f'); %Read data from the file
code = A{1};
xfix = A{2};
yfix = A{3};

for k=1:length(code)
    imagefile=code(k)        
    I = imread([num2str(imagefile) '.jpg']);    %# Load a sample image
    imshow(I);                                  %# Display it
    [r,c,d] = size(I)                           %# Get the image size
    set(gca,'Units','normalized','Position',[0 0 1 1]);  %# Modify axes size
    set(gcf,'Units','pixels','Position',[200 200 c r]);  %# Modify figure size
    hold on;
    x = xfix2(k);
    y = yfix2(k);
    plot(x,y,'+ b');
    f = getframe(gcf);              %# Capture the current window
    imwrite(f.cdata,([num2str(imagefile) '.jpg']));  %# Save the frame data
    hold off
end

但是,我有一点问题。我在图像上叠加的交叉图被灰色阴影所包围(就像我们复印纸张时,它们将是灰色)。这是怎么发生的?

However, I have a little problem. The "cross plots" which I overlay on the image, were surrounded by gray shadow (like when we photocopy a paper, they will be a gray color on it). How did this happen?

推荐答案

有很多方法:

我可以使用JPEG文件作为MATLAB图中的背景吗?

如何在GUI或图形窗口中添加背景图像?

之后调整轴总会遇到一些问题。

And there's always some kind of problem with adjusting the axes afterwards.

这篇关于MATLAB - 如何在图像上绘制x,y并保存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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