% DiGraph.m % % Capture data from a scanned graph into Matlab matrix % and store it as ASCII two-colimn outfile % % Original version due to Lester John (LJOHN@anat.uct.ac.za), October 1998 % Modified and adopted by Valery Grikurov (grikurov@math.nw.ru), 2003-04 % This version works fine under MatLab 7.0.1 % % USAGE: % % Press "Set XY" button and click on 4 points in the graph ! MANDATORY BEFORE READING DATA ! % % Then press "Read Data" button to capture point by point from graph; % terminate capturing with the "Enter" key % % NOTE: % % To change the mouse pointer, edit the Matlab function 'ginput.m' % % OPTIONS: % % Rotate box: set angle of rotation (in degrees) for skewed graphs % % Axes limit boxes: set new limits to scale the axes % fig_handle = 333; figure(fig_handle); set(fig_handle,'Position',[50,100,750,550]); set(fig_handle,... 'NumberTitle','off','Name',' Matlab Graph Digitizer','Toolbar','none','Menubar','none'); axis off % Open button pbopn = uicontrol(... 'Style','push',... 'Position',[10 500 60 30],... 'String','Open',... 'ForegroundColor',[1 0 0],... 'CallBack',... ['[filename, pathname] = uigetfile({''*.bmp;*.gif;*.jpg;*.png;*.tif'';''*.*''},''Open File with Graph'');,',... 'if filename ~= 0,',... '[graf,map]=imread([pathname,filename]);,',... 'image(graf);,',... 'axis off;,',... 'colormap(map);,',... 'end;,',... 'graf_orig=graf;']); % Preset Variables rot_angle=0; new_xstart=0; new_ystart=0; new_xend=1; new_yend=1; % Rotate pbxy1 = uicontrol(... 'Style','push',... 'Position',[10 10 45 20],... 'String','Rotate',... 'ForegroundColor',[0 0 1],... 'CallBack', ['graf=imrotate(graf,-rot_angle,''nearest'',''crop'');',... 'image(graf);,','axis off;']); % Set XY pbxy2 = uicontrol(... 'Style','push',... 'Position',[300 10 60 30],... 'String','Set XY',... 'ForegroundColor',[1 0 0],... 'CallBack', ['title(''Click on START and END of X-AXIS'');,',... '[x,y]=ginput(2);,',... 'xstart=x(1);,',... 'xend =x(2);,',... 'title(''Click on START and END of Y-AXIS'');,',... '[x,y]=ginput(2);,',... 'title('' '');,',... 'ystart = y(1);,',... 'yend = y(2);,']); % Read Data pbxy3 = uicontrol(... 'Style','push',... 'Position',[400 10 100 30],... 'String','Read Data',... 'ForegroundColor',[1 0 1],... 'CallBack', ['title(''Read DATA with left mouse button. Press ENTER to end'');,',... 'xunit = (xend-xstart)/(new_xend-new_xstart);,',... 'yunit = (yend-ystart)/(new_yend-new_ystart);,',... '[xin,yin]=ginput;,',... 'title('' '');,',... 'new_xin = new_xstart+(xin-xstart)/xunit;,',... 'new_yin = new_ystart+(yin-ystart)/yunit;,',... 'figure(',num2str(fig_handle+1),');,',... 'set(', num2str(fig_handle+1),',''NumberTitle'',''off'');,',... 'set(', num2str(fig_handle+1),',''Position'',[650 400 500 400]);,',... 'plot(new_xin,new_yin);,','grid,',... 'axis([new_xstart new_xend new_ystart new_yend]);,',... 'title(''Captured data'');,',... 'xlabel(''X_{new}'');,',... 'ylabel(''Y_{new}'');,',... '[filename,pathname] = uiputfile(''Untitled.dat'',''Save data to file:'');,',... 'if filename ~= 0;,',... 'fid = fopen([pathname,filename],''w'');,',... 'fprintf(fid,''%g %g \n'',[new_xin;new_yin]);,',... 'fclose(fid);,'... 'end;,',... 'close(',num2str(fig_handle+1),');']); % Reset pbxy4 = uicontrol(... 'Style','push',... 'Position',[80 10 100 20],... 'String','Reset Rotation',... 'ForegroundColor',[0 0 1],... 'CallBack', ['graf = graf_orig;,', 'image(graf);,', 'axis off;']); % Exit pbxy5 = uicontrol(... 'Style','push',... 'Position',[650 10 60 30],... 'String','Exit',... 'ForegroundColor',[1 0 1],... 'CallBack', ['close(',num2str(fig_handle),');','return;']); % Create Editable text boxes % Y-end pbed1 = uicontrol(... 'Style','edit',... 'String',num2str(new_yend),... 'Position',[10 200 65 20],... 'Max',1,... 'CallBack', ['new_yend=str2num(get(pbed1,''String''));']); tpbed = uicontrol(... 'Style','text',... 'String','Ymax',... 'ForegroundColor',[0 0 0],... 'Position',[10 200+20 65 20]); % Y-start pbed2 = uicontrol(... 'Style','edit',... 'String',num2str(new_ystart),... 'Position',[10 250 65 20],... 'Max',1,... 'CallBack', ['new_ystart=str2num(get(pbed2,''String''));']); tpbed2 = uicontrol(... 'Style','text',... 'String','Ymin',... 'ForegroundColor',[0 0 0],... 'Position',[10 250+20 65 20]); % X-end pbed3 = uicontrol(... 'Style','edit',... 'String',num2str(new_xend),... 'Position',[10 300 65 20],... 'Max',1,... 'CallBack', ['new_xend=str2num(get(pbed3,''String''));']); tpbed3 = uicontrol(... 'Style','text',... 'String','Xmax',... 'ForegroundColor',[0 0 0],... 'Position',[10 300+20 65 20]); % X-start pbed4 = uicontrol(... 'Style','edit',... 'String',num2str(new_xstart),... 'Position',[10 350 65 20],... 'Max',1,... 'CallBack', [... 'new_xstart=str2num(get(pbed4,''String''));']); tpbed4 = uicontrol(... 'Style','text',... 'String','Xmin',... 'ForegroundColor',[0 0 0],... 'Position',[10 350+20 65 20]); % Angle of Rotation pbed5 = uicontrol(... 'Style','edit',... 'String',num2str(rot_angle),... 'Position',[10 50 65 20],... 'Max',1,... 'CallBack', ['rot_angle=str2num(get(pbed5,''String''));']); tpbed5 = uicontrol(... 'Style','text',... 'String','Rotation angle',... 'Max',2,... 'ForegroundColor',[0 0 0],... 'Position',[10 50+20 85 20]);