Match axis director image and plot

조회 수: 2 (최근 30일)
Alejandro Fernández
Alejandro Fernández 2020년 7월 17일
댓글: Alejandro Fernández 2020년 8월 14일
Hello there. See if anyone knows where I can find the answer to my question or see if anyone knows how to solve it. In this case I have the cameraman image with size 7000X7000 pixels. And i need to plot one point over the image. The point has de coordinates [2000,1000]
And what i need to obtain in the image is the point in this location (I know that the image Y Axis is not the same), so in this case, to obtapin the same point it should be [2000 6000]. But i suposse that it has to be one way to do it easy if I have 10000 points to put over the image.
In summary, if I have the image I and the point [2000 1000] what I expect to obtain is this:
Thank you so much in advance.

채택된 답변

Nitin Kapgate
Nitin Kapgate 2020년 8월 14일
The following code snippet and the function will help you to establish the correspondence between the points in regular cartesian coordinates in first quadrant and the location of the same point in Image coordinate system.
% Read the test image, assuming your image is 7000*7000 pixels
I = imread('yourInputImage.tif');
% X and Y coordinates of points (Let's call them as xCart and yCart respectively)
% and the corresponding X and Y coordinates in the Image coordinate system (Let's call them as xImg and yImg respectively)
% Assuming xCart and yCart lie only in the first quadrant and the input
xCart = 2000;
yCart = 1000;
% Get the X and Y coordinates in the Image coordinate system
[xImg,yImg] = returnImgCoordinates(xCart, yCart);
% Display xImg and yImg
xImg
yImg
% To access the image at these coordinates (im Image coordinate system),
% use the following code.
pixelValueAtLoc = I(xImg,yImg)
function [xImg,yImg] = returnImgCoordinates(xCart, yCart)
% The function can be used to establish the correspondence between the points in
% regular cartesian coordinates in first quadrant and the location of the same point
% in Image coordinate system.
% Use the following conversion logic to convert X and Y coordinates of
% points (Let's call them as xCart and yCart respectively) to the corresponding X and Y coordinates
% in the Image coordinate system (Let's call them as xImg and yImg respectively)
% Assuming xCart and yCart lie only in the first quadrant and the input
% Assuming that the image is 7000*7000 pixels
xImg = xCart; % Because in both the coordinate systems, X axis is in the same direction
yImg = 7000 - yCart; % The Y axes in the two coordinate sytems are in the opposite direction
end

추가 답변 (0개)

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by