开发者

How to get coordinates of corners of an image in matlab

I want to get the four corner points or coordinates of an image.开发者_运维知识库 How can get I get them in MatLab?


If you are referring to the coordinates of the image corners when you plot the image in an axes using either IMSHOW or IMAGE/IMAGESC, then here is how you can find them:

  • If you plot the image without specifying ranges:

    image(img);
    imshow(img);
    

    Then img is plotted on an axes with the pixels centered at the values 1:size(img,2) horizontally and 1:size(img,1) vertically. Since these values represent the pixel centers, and the pixel size is 1, then the image extends half a pixel past the above ranges in every direction. The extents of the image are therefore:

    xmin = 0.5;
    xmax = size(img,2)+0.5;
    ymin = 0.5;
    ymax = size(img,1)+0.5;
    

    From which you can get your corner coordinates [xmin ymin], [xmin ymax], [xmax ymin], and [xmax ymax].

  • If you specify ranges for plotting, such as:

    image([x1 x2],[y1 y2],img);
    

    You may think that these limits you specify are the edges of the plotted image, but they are actually the extents of the pixel centers, so yet again the true extent of the plotted image is half a pixel further in every direction. The pixel size in each direction can be calculated as follows:

    dx = abs(x2-x1)/size(img,2);
    dy = abs(y2-y1)/size(img,1);
    

    And the extents of the image are therefore:

    xmin = min(x1,x2)-0.5*dx;
    xmax = max(x1,x2)+0.5*dx;
    ymin = min(y1,y2)-0.5*dy;
    ymax = max(y1,y2)+0.5*dy;
    

    From which you can again easily get your corner coordinates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜