## Extracting Raw Data From an Image in MATLAB

### Priyanka (view profile)

on 18 Apr 2013
% digitize.m
function [x,y] = digitize(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;
I want to know what is the logic behind the formula in getting x and y in the last two lines of the code.

### Tags ### Image Analyst (view profile)

Answer by Image Analyst

### Image Analyst (view profile)

on 18 Apr 2013

They're getting an x and y in pixels, then getting rid of the offset (the pixel row and column where the axes are located) then scaling to the "real world" coordinates, i.e. the units of the graph rather than pixels.

Priyanka

### Priyanka (view profile)

on 18 Apr 2013
How would we know exactly if the final coordinates are right?
Image Analyst

### Image Analyst (view profile)

on 18 Apr 2013
Do you trust your user to click on the right point or not? Who's to say what's "right"?