Extracting Raw Data From an Image in MATLAB

6 ビュー (過去 30 日間)
Priyanka
Priyanka 2013 年 4 月 18 日
% 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 Center および File ExchangeGeographic Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by