I was going through some old code and ran across this little gem of a MATLAB script, so I thought I’d post it here for posterity.
The script lets you specify an image file to view and lets you click on each data point until you’re finished. Then it exports the (x,y) coordinates of all of the points that you clicked. This is indispensable if you have a graph from a paper that you would like to analyze further but don’t have the original data file.
% digitize.m function [x,y] = digitize(imgname) [img,map] = imread(imgname); image(img); colormap(map); Left = input('Enter the left X coordinate: '); Right = input('Enter the right X coordinate: '); Bottom = input('Enter the bottom Y coordinate: '); Top = input('Enter the top Y coordinate: '); disp('Click on the lower-left corner'); [localLeft,localBottom] = ginput(1); disp('Click on the upper-right corner'); [localRight,localTop] = ginput(1); disp('Begin digitizing points. Click right mouse button when finished.'); b = 0; bold = 0; while(b~=3) [xp,yp,b] = ginput(1); if (b == 1) if (bold ~= 0) line([xold; xp], [yold; yp]); x = [x; xp]; y = [y; yp]; else x = xp; y = yp; end xold = xp; yold = yp; bold = b; end end x = (x - localLeft) / (localRight-localLeft) * (Right-Left) + Left; y = (y - localBottom) / (localTop - localBottom) * (Top-Bottom) + Bottom;
Credit goes to Brian Usner, wherever you are