[英]MATLAB - How to plot x,y on an image and save?
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
但是,我有一點問題。 我覆蓋在圖像上的“十字圖”被灰色陰影包圍(例如,當我們復印紙時,它們將是灰色的)。 這怎么發生的?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.