Extracting Raw Data From an Image in MATLAB

6 次查看(过去 30 天)
% 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.

回答(1 个)

Image Analyst
Image Analyst 2013-4-18
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 个评论
Priyanka
Priyanka 2013-4-18
How would we know exactly if the final coordinates are right?
Image Analyst
Image Analyst 2013-4-18
Do you trust your user to click on the right point or not? Who's to say what's "right"?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by