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 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