MATLAB - 如何在图像上绘制 x,y 并保存?

发布于 2024-09-08 08:38:21 字数 1250 浏览 0 评论 0原文

文件 datafile.txt

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 列代表人们在图像上观看的点。向用户显示了三个不同的图像。下面代码的问题是我不知道如何使用打开的文件名保存绘制 xy 的图像。

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

在此处输入图像描述

但是,我有一个小问题。我覆盖在图像上的“交叉图”被灰色阴影包围(就像当我们复印一张纸时,它们在上面将是灰色的)。这是怎么发生的?

File datafile.txt

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

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

Enter image description here

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?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文