MATLAB - ¿Cómo trazar x, y en una imagen y guardar?
Archivo 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
En el archivo anterior, la primera columna representa el código de la imagen que se muestra en la pantalla, y las columnas x e y representan el punto donde las personas miran la imagen. Hubo tres imágenes diferentes que se muestran al usuario. El problema con el código a continuación es que no sé cómo guardar la imagen con la x-y trazada con el mismo nombre de archivo que se abrió.
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
Sin embargo, tengo un pequeño problema. Las "parcelas cruzadas" que superpongo en la imagen, estaban rodeadas de sombras grises (como cuando fotocopiamos un papel, serán de color gris). ¿Cómo pasó esto?