{"id":80,"date":"2006-08-22T08:16:49","date_gmt":"2006-08-22T12:16:49","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/?p=80"},"modified":"2019-10-22T14:46:27","modified_gmt":"2019-10-22T18:46:27","slug":"responses-to-reader-challenge","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2006\/08\/22\/responses-to-reader-challenge\/","title":{"rendered":"Responses to reader challenge"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p>Thanks to Kimo Johnson and Perttu Ranta-aho for responding to my <a href=\"https:\/\/blogs.mathworks.com\/steve\/?p=76\">custom spatial transformation challenge.<\/a><\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Kimo's submission<\/a><\/li>\r\n         <li><a href=\"#2\">Perttu's submission<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Kimo's submission<a name=\"1\"><\/a><\/h3>\r\n   <p>Kimo's custom transform turns the football image inside out!<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">im = imread(<span style=\"color: #A020F0\">'football.jpg'<\/span>);\r\nsx = 1.47;\r\nsy = 1.6;\r\nc2 = 0.14;\r\nc3 = 0.07;\r\np1 = 0.25;\r\np2 = 0.125;\r\n\r\nf = @(x) complex(x(:,1)\/sx,x(:,2)\/sy);\r\ng = @(z) c2*log(abs(z + p1)) + c2*log(abs(z - p1)) + <span style=\"color: #0000FF\">...<\/span>\r\n    c3*log(abs(z + p2*i)) + c3*log(abs(z - p2*i));\r\nh = @(w) [real(w), imag(w)];\r\nq = @(x, unused) h(g(f(x)));\r\n\r\ntform = maketform(<span style=\"color: #A020F0\">'custom'<\/span>, 2, 2, [], q, []);\r\ntrans = imtransform(im, tform, <span style=\"color: #A020F0\">'UData'<\/span>, [-1 1], <span style=\"color: #A020F0\">'VData'<\/span>, [-1 1], <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'XData'<\/span>, [-1 1], <span style=\"color: #A020F0\">'YData'<\/span>, [-1 1]);\r\n\r\nsubplot(1,2,1)\r\nimshow(im)\r\ntitle(<span style=\"color: #A020F0\">'Original'<\/span>)\r\n\r\nsubplot(1,2,2)\r\nimshow(trans)\r\ntitle(<span style=\"color: #A020F0\">'Transformed'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/80\/reader_challenge_01.jpg\"> <h3>Perttu's submission<a name=\"2\"><\/a><\/h3>\r\n   <p>I really don't know how to describe this one.<\/p>\r\n   <p>Notice how Perttu used the 'FillValues' option of <tt>imtransform<\/tt> to get the red pixels in the output.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = imread(<span style=\"color: #A020F0\">'https:\/\/blogs.mathworks.com\/images\/steve\/80\/samu.jpg'<\/span>);<\/pre><p>I'm going to shrink the image a bit so it's not too big for the blog page.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = imresize(I, 0.5);<\/pre><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">clf\r\nimshow(I)\r\ntitle(<span style=\"color: #A020F0\">'Cute kid!'<\/span>)\r\nimcredit(<span style=\"color: #A020F0\">'Image courtesy of Perttu Ranta-aho'<\/span>)  <span style=\"color: #228B22\">% MATLAB Central File Exchange<\/span><\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/80\/reader_challenge_02.jpg\"> <pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">f = @(x) complex(x(:,1),x(:,2));\r\ng = @(z) ((z-1).*(z+1).*(z+.1-2*i).*(z+1+2*i)) .\/ <span style=\"color: #0000FF\">...<\/span>\r\n    (power(z+1+i,4)+power(z-1-i,4));\r\nh = @(w) [real(w) imag(w)];\r\nq = @(x,unused) h(g(g(g(g(f(x))))));\r\ntform = maketform(<span style=\"color: #A020F0\">'custom'<\/span>, 2, 2, [], q, []);\r\nJ=imtransform(I, tform, <span style=\"color: #A020F0\">'UData'<\/span>, [-1.5 1.5], <span style=\"color: #A020F0\">'VData'<\/span>, [-1.5 1.5], <span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'XData'<\/span>, [0 6], <span style=\"color: #A020F0\">'YData'<\/span>, [-4 2], <span style=\"color: #A020F0\">'FillValues'<\/span>, [255 0 0]');\r\nimshow(J)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/80\/reader_challenge_03.jpg\"> <p>Wow!<\/p>\r\n<script language=\"JavaScript\"> \r\n<!--\r\n    function grabCode_80() {\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='80 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 80';\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 2006 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      <\/script>\r\n<noscript>\r\n<em>A JavaScript-enabled browser is required to use the \"Get the MATLAB code\" link.<\/em>\r\n<\/noscript>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_80()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code<\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.2<br><\/p>\r\n<\/div>\r\n<!--\r\n80 ##### SOURCE BEGIN #####\r\n%% Response to reader challenge\r\n% Thanks to Kimo Johnson and Perttu Ranta-aho for responding to my \r\n% <https:\/\/blogs.mathworks.com\/steve\/?p=76 custom spatial transformation\r\n% challenge.>\r\n\r\n%% Kimo's submission\r\n% Kimo's custom transform turns the football image inside out!\r\n\r\nim = imread('football.jpg');\r\nsx = 1.47;\r\nsy = 1.6;\r\nc2 = 0.14;\r\nc3 = 0.07;\r\np1 = 0.25;\r\np2 = 0.125;\r\n\r\nf = @(x) complex(x(:,1)\/sx,x(:,2)\/sy);\r\ng = @(z) c2*log(abs(z + p1)) + c2*log(abs(z - p1)) + ...\r\n    c3*log(abs(z + p2*i)) + c3*log(abs(z - p2*i));\r\nh = @(w) [real(w), imag(w)];\r\nq = @(x, unused) h(g(f(x)));\r\n\r\ntform = maketform('custom', 2, 2, [], q, []);\r\ntrans = imtransform(im, tform, 'UData', [-1 1], 'VData', [-1 1], ...\r\n    'XData', [-1 1], 'YData', [-1 1]);\r\n\r\nsubplot(1,2,1)\r\nimshow(im)\r\ntitle('Original')\r\n\r\nsubplot(1,2,2)\r\nimshow(trans)\r\ntitle('Transformed')\r\n\r\n%% Perttu's submission\r\n% I really don't know how to describe this one.\r\n%\r\n% Notice how Perttu used the 'FillValues' option of \r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmlimtransform.html \r\n% |imtransform|> to get the red pixels in the output.\r\n\r\nI = imread('https:\/\/blogs.mathworks.com\/images\/steve\/80\/samu.jpg');\r\n\r\n%%\r\n% I'm going to shrink the image a bit so it's not too big for the blog\r\n% page.\r\nI = imresize(I, 0.5);\r\n\r\n%%\r\nclf\r\nimshow(I)\r\ntitle('Cute kid!')\r\nimcredit('Image courtesy of Perttu Ranta-aho')  % MATLAB Central File Exchange\r\n\r\n%%\r\nf = @(x) complex(x(:,1),x(:,2));\r\ng = @(z) ((z-1).*(z+1).*(z+.1-2*i).*(z+1+2*i)) .\/ ...\r\n    (power(z+1+i,4)+power(z-1-i,4));\r\nh = @(w) [real(w) imag(w)];\r\nq = @(x,unused) h(g(g(g(g(f(x))))));\r\ntform = maketform('custom', 2, 2, [], q, []); \r\nJ=imtransform(I, tform, 'UData', [-1.5 1.5], 'VData', [-1.5 1.5], ...\r\n    'XData', [0 6], 'YData', [-4 2], 'FillValues', [255 0 0]');\r\nimshow(J)\r\n\r\n%%\r\n% Wow!\r\n##### SOURCE END ##### 80\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Thanks to Kimo Johnson and Perttu Ranta-aho for responding to my custom spatial transformation challenge.\r\n   \r\n   Contents\r\n   \r\n      \r\n         Kimo's submission\r\n... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2006\/08\/22\/responses-to-reader-challenge\/\">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":[208,198,202,76,156,36,44,224,62,226,200,72,52],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/80"}],"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=80"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":2202,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/80\/revisions\/2202"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}