{"id":380,"date":"2011-07-19T20:50:18","date_gmt":"2011-07-20T00:50:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-3\/"},"modified":"2019-10-29T16:47:37","modified_gmt":"2019-10-29T20:47:37","slug":"jahne-test-pattern-take-3","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-3\/","title":{"rendered":"J\u00e4hne test pattern &#8211; take 3"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-2\/\">Earlier today<\/a> I told you that I was feeling a little dense because I couldn't figure out the right parameters to use in the tanh term of\r\n      this test pattern:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq56929.png\"> <\/p>\r\n   <p>(This is equation 10.63 in <i>Practical Handbook on Image Processing for Scientific Applications<\/i> by Bernd Jahne.)\r\n   <\/p>\r\n   <p>I'm grateful to reader <a href=\"https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-2\/#comment-24340\">Alex H<\/a> for quickly enlightening me. He described <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq34340.png\">  as an approximation to a step function, where <i>a<\/i> is the location of the step and <i>w<\/i> is the width of the transition. That was very helpful.\r\n   <\/p>\r\n   <p>I've also realized that I misinterpreted the meaning of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq48843.png\"> . In the book this is described as the \"maximum radius of the pattern,\" and I assumed this would be fixed as the distance\r\n      from the center of the square image to one of its corners. But now I realize that the author intended for this to be an adjustable\r\n      parameter. That is, one can set <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq48843.png\">  so that the maximum instantaneous frequency is reached closer to the center than at the image corners.\r\n   <\/p>\r\n   <p>For example, I can set the parameters so that the maximum instantaneous frequency of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq11731.png\">  is reached in the center of the image edges, and then the tapering function prevents aliasing artifacts from appearing as\r\n      you move out to the corners. The book's figure 10.23 is based on maximum instantaneous frequency of <img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_eq47336.png\">  (a period of 2.5 samples) reached at the edges, so I'll use that.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[x,y] = meshgrid(-200:200);\r\nkm = 0.8*pi;\r\nrm = 200;\r\nw = rm\/10;\r\nterm1 = sin( (km * r.^2) \/ (2 * rm) );\r\nterm2 = 0.5*tanh((rm - r)\/w) + 0.5;\r\ng = term1 .* term2;\r\nimshow(g,[])<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/2011\/jahne_take_3_01.jpg\"> <p>Finally, a result that looks like the figure in the book!<\/p>\r\n   <p>Thanks again, Alex.<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_fe8f876c1fdf4c6a911915fcf551f3ba() {\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='fe8f876c1fdf4c6a911915fcf551f3ba ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' fe8f876c1fdf4c6a911915fcf551f3ba';\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 2011 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_fe8f876c1fdf4c6a911915fcf551f3ba()\"><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.12<br><\/p>\r\n<\/div>\r\n<!--\r\nfe8f876c1fdf4c6a911915fcf551f3ba ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-2\/\r\n% Earlier today> I told you that I was feeling a little dense because I\r\n% couldn't figure out the right parameters to use in the tanh term of this\r\n% test pattern:\r\n%\r\n% $$g({\\bf x}) = g_0 \\sin\\left(\\frac{k_m|{\\bf x}|^2}{2r_m}\\right) \\left[\\frac{1}{2}\r\n% \\tanh\\left(\\frac{r_m-|{\\bf x}|}{w}\\right) + \\frac{1}{2}\\right]$$\r\n%\r\n% (This is equation 10.63 in _Practical Handbook on Image Processing for\r\n% Scientific Applications_ by Bernd Jahne.)\r\n%\r\n% I'm grateful to reader\r\n% <https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-2\/#comment-24340\r\n% Alex H> for quickly enlightening me. He described $tanh((a-x)\/w)$ as an\r\n% approximation to a step function, where _a_ is the location of the step\r\n% and _w_ is the width of the transition. That was very helpful.\r\n%\r\n% I've also realized that I misinterpreted the meaning of $r_m$. In the\r\n% book this is described as the \"maximum radius of the pattern,\" and I\r\n% assumed this would be fixed as the distance from the center of the square\r\n% image to one of its corners. But now I realize that the author intended\r\n% for this to be an adjustable parameter. That is, one can set $r_m$ so\r\n% that the maximum instantaneous frequency is reached closer to the center\r\n% than at the image corners.\r\n%\r\n% For example, I can set the parameters so that the maximum instantaneous\r\n% frequency of $\\pi$ is reached in the center of the image edges, and then\r\n% the tapering function prevents aliasing artifacts from appearing as you\r\n% move out to the corners. The book's figure 10.23 is based on maximum\r\n% instantaneous frequency of $0.8\\pi$ (a period of 2.5 samples) reached at\r\n% the edges, so I'll use that.\r\n\r\n[x,y] = meshgrid(-200:200);\r\nkm = 0.8*pi;\r\nrm = 200;\r\nw = rm\/10;\r\nterm1 = sin( (km * r.^2) \/ (2 * rm) );\r\nterm2 = 0.5*tanh((rm - r)\/w) + 0.5;\r\ng = term1 .* term2;\r\nimshow(g,[])\r\n\r\n%%\r\n% Finally, a result that looks like the figure in the book!\r\n%\r\n% Thanks again, Alex.\r\n##### SOURCE END ##### fe8f876c1fdf4c6a911915fcf551f3ba\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Earlier today I told you that I was feeling a little dense because I couldn't figure out the right parameters to use in the tanh term of\r\n      this test pattern:\r\n   \r\n    \r\n   (This is... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2011\/07\/19\/jahne-test-pattern-take-3\/\">read more >><\/a><\/p>","protected":false},"author":42,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[36,30,532,34,809],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/380"}],"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=380"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/380\/revisions"}],"predecessor-version":[{"id":3741,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/380\/revisions\/3741"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=380"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=380"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=380"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}