MATLAB Answers

Priyanka
0

Extracting Raw Data From an Image in MATLAB

Asked by Priyanka
on 18 Apr 2013
% 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;
I want to know what is the logic behind the formula in getting x and y in the last two lines of the code.

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
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.

  2 Comments

How would we know exactly if the final coordinates are right?
Do you trust your user to click on the right point or not? Who's to say what's "right"?

Sign in to comment.