?? digitize.m
字號:
function nXY = digitize()
%function iXY = digitize()
%
%jdc 17-Feb-00
%PURPOSE
% > Interactively digitizes data from an image file.
% > X-Y axis scales can be any combination of linear, log.
% > Automatic compensation for angular misalignment of
% image with respect to screen axes.
%INPUT
% (All input is interactively prompted)
% > imagename - image filespec (any Matlab-compatible format)
% > three points defining coordinate axes
% > arbitrary number of points on graph - digitized with left mouse button
%OUTPUT
% > numbered sets of iXY triplets written to screen and optionally to disc storage
% > iXY - 3 x i matrix of all points digitized from image
%
%TYPICAL CALL
% digitize <RETURN>
% It is necessary to switch between the MATLAB command window and the graphic display window to
% enter the prompted information.
% This file is not part of MZDDE. It was downloaded from the MATLAB Central File Exchamge.
% A small modification was required to get it working under Matlab 6 Release 13.
% Also, a GUI file dialog is now used to select the image file.
% http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=287&objectType=file
% The author is J Cogdell. This is a rather useful utility.
% $Header: C:\\Projects\\RCS\\C\\Projects\\MZDDE\\digitize.m,v 1.1 2005-04-22 09:52:52+02 dgriffith Exp dgriffith $
% $Revision: 1.1 $
fmts = imformats; % Get the available image formats that will be read by imread
% Cook up a string to give to uigetfile
allimagefmts = '';
for i = 1:length(fmts)
if length(fmts(i).ext) == 1
extensions = ['*.' char(fmts(i).ext)];
else
extensions = ['*.' char(fmts(i).ext(1)) ';*.' char(fmts(i).ext(2))];
end
uigetstring{i,1} = extensions;
uigetstring{i,2} = fmts(i).description;
allimagefmts = [allimagefmts ';' extensions];
end
uigetstring{end+1,1} = allimagefmts;
uigetstring{end,2} = 'All Known Image File Formats';
uigetstring{end+1,1} = '*.*';
uigetstring{end,2} = 'All Files (*.*)';
[filename, pathname] = uigetfile(uigetstring, 'Select an Image File');
imagename = [pathname filename];
pic = imread(imagename);
imshow(pic);
set(gcf,'Units','normalized','Position',[0 .15 1 .85])
set(gca,'Units','normalized','Position',[0 0 1 1]);
fprintf([ 'Select the plot origin with the left mouse button ...\n' 7])
[Xopixels,Yopixels] = ginput(1);
line(Xopixels,Yopixels,'Marker','.','Color','r')
OriginXYdata = input([ ' Enter the [x y] graph values at the origin => ' 7]);
if length(OriginXYdata)==1,
OriginXYdata(2) = input([' Enter the Y graph value at the origin => ' 7]);
end
fprintf(['\nSelect a point on the X-axis ...\n' 7])
[XAxisXpixels,XAxisYpixels] = ginput(1);
line(XAxisXpixels,XAxisYpixels,'Marker','.','Color','r')
XAxisXdata = input(['Enter the X-value of the point => ' 7]);
logx = input( ' X-axis scale? [ {lin} | log ] => ','s');
if findstr('log',lower(logx)),
logx = 1;
scalefactorXdata = log10(XAxisXdata/OriginXYdata(1));
else
logx = 0;
scalefactorXdata = XAxisXdata - OriginXYdata(1);
end
th = atan((XAxisYpixels-Yopixels)/(XAxisXpixels-Xopixels)); % note image file line 1 is at top
%fprintf( ' Graph rotation angle: %+3.1f degrees +cw\n', th*180/pi)
rotmat = [cos(th) sin(th); -sin(th) cos(th)]; % axis rotation matrix
fprintf(['\nSelect a point on the Y-axis ...\n' 7])
[YAxisXpixels,YAxisYpixels] = ginput(1);
line(YAxisXpixels,YAxisYpixels,'Marker','.','Color','r')
YAxisYdata = input(['Enter the Y-value of the point => ' 7]);
logy = input( ' Y-axis scale? [ {lin} | log ] => ','s');
if findstr('log',lower(logy)),
logy = 1;
scalefactorYdata = log10(YAxisYdata/OriginXYdata(2));
else
logy = 0;
scalefactorYdata = YAxisYdata - OriginXYdata(2);
end
delxyx = rotmat*[(XAxisXpixels-Xopixels);(XAxisYpixels-Yopixels)];
delxyy = rotmat*[(YAxisXpixels-Xopixels);(YAxisYpixels-Yopixels)];
delXcal = delxyx(1);
delYcal = delxyy(2);
numberformat = '%6.2f';
nXY = [];
ng = 0;
while 1,
fprintf(['\n Select graph points with left mouse button ...\n',...
' To terminate capture - select a point to the left of or below the graph axes\n' 7])
n = 0;
%---------------------------------------------------------------------------------------- data acquire loop
while 1
[x,y] = ginput(1);
line(x,y,'Marker','+','Color','g')
xy = rotmat*[(x-Xopixels);(y-Yopixels)];
delXpoint = xy(1);
delYpoint = xy(2);
if delXpoint>=0 & delYpoint<=0,
if logx,
x = OriginXYdata(1)*10^(delXpoint/delXcal*scalefactorXdata);
else
x = OriginXYdata(1) + delXpoint/delXcal*scalefactorXdata;
end
if logy,
y = OriginXYdata(2)*10^(delYpoint/delYcal*scalefactorYdata);
else
y = OriginXYdata(2) + delYpoint/delYcal*scalefactorYdata;
end
n = n+1;
xpt(n) = x;
ypt(n) = y;
fprintf( ['%4.0f ' numberformat ' ' numberformat '\n'],n,x,y)
ng = ng+1;
nXY(ng,:) = [n x y];
else
break
end
end
%---------------------------------------------------------------------------------------------
fname = input([ ' Enter a filespec to save the data to (default: no save) => ' 7],'s');
if ~isempty(fname),
numberformat = input([' Enter a format to save the data (default: %6.2f ) => ' 7],'s');
if isempty(numberformat),
numberformat = '%6.2f';
end
for i = 1:n,
fprintf(fname,['%4.0f ' numberformat ' ' numberformat '\n'],i,xpt(i),ypt(i));
end
I = findstr('\',fname);
if ~isempty(I),
for i = length(I):-1:1,
fname = [fname(1:i) '\' fname(i+1:length(fname))];
end
end
fprintf([ sprintf([' %3.0f x-y data pairs saved to file => ' fname],n) '\n'])
end
yn = input([ ' Digitize more data from this graph? [ {y} | n ] => ' 7],'s');
if findstr('n',lower(yn)),
break
end
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -