【问题标题】:MATLAB - How to plot x,y on an image and save?MATLAB - 如何在图像上绘制 x,y 并保存?
【发布时间】:2011-03-11 20:05:21
【问题描述】:

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

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

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

【问题讨论】:

标签: image matlab plot


【解决方案1】:
猜你喜欢
  • 2011-12-19
  • 2017-08-11
  • 2010-12-23
  • 2015-08-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多