{"id":204,"date":"2008-03-31T10:37:04","date_gmt":"2008-03-31T14:37:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2008\/03\/31\/output-space-coordinates\/"},"modified":"2019-10-24T14:02:14","modified_gmt":"2019-10-24T18:02:14","slug":"output-space-coordinates","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2008\/03\/31\/output-space-coordinates\/","title":{"rendered":"Viewing output-space coordinates for a transformed image"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>Blog reader Ram <a href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/02\/14\/spatial-transformations-maketform-tformfwd-and-tforminv\/#comment-20535\">asked a question last week<\/a> that I hear fairly often: When you apply a spatial transformation to an image, how can you see the <i>x-y<\/i> coordinates when you display the image?\r\n   <\/p>\r\n   <p>The answer has three steps:<\/p>\r\n   <p>1. Ask <tt>imtransform<\/tt> for the spatial coordinates of the output image\r\n   <\/p>\r\n   <p>2. Give <tt>imshow<\/tt> the spatial coordinates when you display the output image\r\n   <\/p>\r\n   <p>3. Turn on the axis box and tick labels<\/p>\r\n   <p>Let's walk through these steps using an affine transformation.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">T = maketform(<span style=\"color: #A020F0\">'affine'<\/span>,[.5 0 0; .5 1.5 0; 100 200 1]);\r\nI = imread(<span style=\"color: #A020F0\">'cameraman.tif'<\/span>);<\/pre><p>The first output from <tt>imtransform<\/tt> is the transformed image.  There are two more optional arguments, though: <tt>xdata<\/tt> and <tt>ydata<\/tt>.  <tt>xdata<\/tt> is a two-element vector specifying the x-coordinates of the first and last image columns.  Similarly, <tt>ydata<\/tt> specifies the y-coordinates of the first and last image rows.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[I2, xdata, ydata] = imtransform(I, T);\r\nxdata<\/pre><pre style=\"font-style:oblique\">\r\nxdata =\r\n\r\n   101   356\r\n\r\n<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">ydata<\/pre><pre style=\"font-style:oblique\">\r\nydata =\r\n\r\n  201.5000  584.5000\r\n\r\n<\/pre><p>Step 2 is to pass the coordinate information to <tt>imshow<\/tt>.  You can do that by using the <tt>'XData'<\/tt> and <tt>'YData'<\/tt> parameters, like this:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">imshow(I2, <span style=\"color: #A020F0\">'XData'<\/span>, xdata, <span style=\"color: #A020F0\">'YData'<\/span>, ydata)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2008\/view_output_space_coordinates_01.jpg\"> <p>But we still can't see the coordinates!  That's because <tt>imshow<\/tt> turns the axis display off.  That brings us to step 3: Turn on the axis box and tick labels:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">axis <span style=\"color: #A020F0\">on<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2008\/view_output_space_coordinates_02.jpg\"> <p>After you do these steps, you might also want to call <tt>impixelinfo<\/tt>, which turns on a display of pixel location and value in the figure window.  The display updates as you move the mouse.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_128debeed09f42ccb76c4efc2733827d() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='128debeed09f42ccb76c4efc2733827d ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 128debeed09f42ccb76c4efc2733827d';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Steve Eddins';\r\n        copyright = 'Copyright 2008 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_128debeed09f42ccb76c4efc2733827d()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.6<br><\/p>\r\n<\/div>\r\n<!--\r\n128debeed09f42ccb76c4efc2733827d ##### SOURCE BEGIN #####\r\n%%\r\n% Blog reader Ram \r\n% <https:\/\/blogs.mathworks.com\/steve\/2006\/02\/14\/spatial-transformations-maketform-tformfwd-and-tforminv\/#comment-20535 \r\n% asked a question last week> that I hear fairly often: When you\r\n% apply a spatial transformation to an image, how can you see the _x-y_\r\n% coordinates when you display the image?\r\n%\r\n% The answer has three steps:\r\n% \r\n% 1. Ask \r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmlimtransform.html \r\n% |imtransform|> for the spatial coordinates of the output image\r\n%\r\n% 2. Give \r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmlimshow.html \r\n% |imshow|> the spatial coordinates when you display the\r\n% output image\r\n%\r\n% 3. Turn on the axis box and tick labels\r\n%\r\n% Let's walk through these steps using an affine transformation.\r\n\r\nT = maketform('affine',[.5 0 0; .5 1.5 0; 100 200 1]);\r\nI = imread('cameraman.tif');\r\n\r\n%%\r\n% The first output from |imtransform| is the transformed image.  There are two\r\n% more optional arguments, though: |xdata| and |ydata|.  |xdata| is a\r\n% two-element vector specifying the x-coordinates of the first and last image\r\n% columns.  Similarly, |ydata| specifies the y-coordinates of the first and last\r\n% image rows.\r\n\r\n[I2, xdata, ydata] = imtransform(I, T);\r\nxdata\r\n\r\n%%\r\nydata\r\n\r\n%%\r\n% Step 2 is to pass the coordinate information to |imshow|.  You can do that by\r\n% using the |'XData'| and |'YData'| parameters, like this:\r\n\r\nimshow(I2, 'XData', xdata, 'YData', ydata)\r\n\r\n%%\r\n% But we still can't see the coordinates!  That's because |imshow| turns the\r\n% axis display off.  That brings us to step 3: Turn on the axis box and tick\r\n% labels:\r\n\r\naxis on\r\n\r\n%%\r\n% After you do these steps, you might also want to call |impixelinfo|, which\r\n% turns on a display of pixel location and value in the figure window.  The\r\n% display updates as you move the mouse.\r\n\r\n##### SOURCE END ##### 128debeed09f42ccb76c4efc2733827d\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Blog reader Ram asked a question last week that I hear fairly often: When you apply a spatial transformation to an image, how can you see the x-y coordinates when you display the image?\r\n   \r\n  ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2008\/03\/31\/output-space-coordinates\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[50,488,76,36,44,62],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/204"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":2260,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/204\/revisions\/2260"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}