0

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?

Community
  • 1
  • 1
Jessy
  • 13,883
  • 31
  • 80
  • 100
  • 1
    A number of solutions are discussed in these previously-asked questions: http://stackoverflow.com/questions/575475/how-can-i-save-an-altered-image-in-matlab, http://stackoverflow.com/questions/1848176/how-do-i-save-a-plotted-image-and-maintain-the-original-image-size-in-matlab, http://stackoverflow.com/questions/606768/write-a-figure-to-a-file-automatically-in-matlab, http://stackoverflow.com/questions/963674/how-do-i-plot-to-an-image-and-save-result-without-displaying-it-in-matlab – gnovice Jul 05 '10 at 18:34

1 Answers1

2

There are numerous ways:

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
rubenvb
  • 69,525
  • 30
  • 173
  • 306