{"id":58,"date":"2006-05-12T14:29:15","date_gmt":"2006-05-12T18:29:15","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=58"},"modified":"2019-10-22T11:33:31","modified_gmt":"2019-10-22T15:33:31","slug":"spatial-transformations-where-is-the-output-image","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2006\/05\/12\/spatial-transformations-where-is-the-output-image\/","title":{"rendered":"Spatial transformations: Where is the output image?"},"content":{"rendered":"<p>\r\nI <a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=55\">wrote previously<\/a> that most spatial image transformation implementations use inverse mapping. The Image Processing Toolbox function <tt>imtransform<\/tt> is implementated using this technique.\r\n<\/p>\r\n\r\n<p>\r\nHere's an interesting issue that arose during the design of <tt>imtransform<\/tt>: How does it know where the output image is located in the <em>x-y<\/em> plane? In other words, in the inverse mapping diagram below, how does it know exactly where the output grid should be?\r\n<\/p>\r\n\r\n<p>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/55\/inverse_mapping.png\">\r\n<\/p>\r\n\r\n<p>\r\nThere are three basic problems you can have with the output grid. It can be too small; it can be too big; or it can be in the wrong place entirely. I'll illustrate these situations with an output grid that is the same size as the input grid, and that is also in the same place.\r\n<\/p>\r\n\r\n<p>\r\nIn the first example, the spatial transformation magnifies the input image. The output grid doesn't cover enough territory in output space to capture the entire transformed image.\r\n<\/p>\r\n\r\n<p>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/58\/output_image_example_1.png\">\r\n<\/p>\r\n\r\n<p>\r\nIn the next example, the spatial transformation shrinks the input image.  As a result, the output grid covers too much territory.  The black output pixels below are output image pixels that aren't needed to capture the entire transformed image.\r\n<\/p>\r\n\r\n<p>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/58\/output_image_example_2.png\">\r\n<\/p>\r\n\r\n<p>\r\nIn the final example, the spatial transformation moves the input somewhere else. Maybe the transformation is simply a 1000-pixel horizontal translation. In this situation, the output grid doesn't contain any of the transformed image!\r\n<\/p>\r\n\r\n<p>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/58\/output_image_example_3.png\">\r\n<\/p>\r\n\r\n<p>\r\nWhen we were designing <tt>imtransform<\/tt>, we thought that any of these scenarios would likely result in frustrated users calling tech support. We tried to avoid this by making imtransform do \"the right thing.\"\r\n<\/p>\r\n\r\n<p>\r\nNext time, I'll describe the calculation <tt>imtransform<\/tt> does to automatically produce the results expected by users.  (Almost all the time, that is.)  If you want a preview, take a look at the function <tt>findbounds<\/tt>.\r\n<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>\r\nI wrote previously that most spatial image transformation implementations use inverse mapping. The Image Processing Toolbox function imtransform is implementated using this technique.\r\n\r\n\r\n\r\nHere's... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/05\/12\/spatial-transformations-where-is-the-output-image\/\">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":[42,44],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/58"}],"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=58"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/58\/revisions"}],"predecessor-version":[{"id":2185,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/58\/revisions\/2185"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=58"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=58"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=58"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}