{"id":11535,"date":"2020-05-22T14:09:31","date_gmt":"2020-05-22T18:09:31","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=11535"},"modified":"2020-05-22T14:12:54","modified_gmt":"2020-05-22T18:12:54","slug":"file-exchange-select-inpaint_nans-gridfit-and-fminsearchbnd-fminsearchcon","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2020\/05\/22\/file-exchange-select-inpaint_nans-gridfit-and-fminsearchbnd-fminsearchcon\/","title":{"rendered":"File Exchange Select &#8211; Inpaint_Nans, Gridfit, and fminsearchbnd\/fminsearchcon"},"content":{"rendered":"<div xmlns:mwsh=\"http:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week are the \"File Exchange Select\" files: <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4551\">inpaint_nans<\/a>, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/8277\">fminsearchbnd-fminsearchcon<\/a>, and <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/8998\">surface-fitting-using-gridfit<\/a> all by <a href=\"http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869215\">John D'Errico<\/a>.\r\n      <\/p>\r\n      <p>The \"File Exchange Select\" banner\/badge was an old idea to advertise high quality, reviewed File Exchange submissions.  It never really took off so we'll be deprecating it soon.  The three files that did manage to get it are these by John D'Errico, one of the File Exchange's most prolific authors.  I'm very surprised none of these are already picks of the week!\r\n      <\/p>\r\n   <\/introduction>\r\n   <h3>Contents<\/h3>\r\n   <div>\r\n      <ul>\r\n         <li><a href=\"#1\">Inpaint_Nans<\/a><\/li>\r\n         <li><a href=\"#4\">Comments<\/a><\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <h3>Inpaint_Nans<a name=\"1\"><\/a><\/h3>\r\n   <p>Today, I'll highlight <tt>inpaint_nans<\/tt>.\r\n   <\/p>\r\n   <p>I actually used inpaint_nans in grad school to help cover ring artifacts caused by the detector in x-ray images.  I don't have one of those images handy, so I'll use a picture of of one of my dogs instead.  I've injected bright red ring artifacts to be easily detectable but emulate the real ring artifacts.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">I = imread(<span style=\"color: #A020F0\">\"LexiRing.png\"<\/span>);\r\nimshow(I)\r\ntitle(<span style=\"color: #A020F0\">\"Ring Artifacts\"<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainFEXSelect_01.png\"> <p>Find rings and expand them a little bit to cover edge effects.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">rings = I(:, :, 1) &gt; 200 &amp; I(:, :, 2) &lt; 100;\r\nrings = imdilate(rings, strel(<span style=\"color: #A020F0\">'disk'<\/span>, 2));\r\nimshow(rings)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainFEXSelect_02.png\"> <p>Apply inpaint_nans to each channel.<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">Ipainted = double(I);\r\n<span style=\"color: #0000FF\">for<\/span> ii = 1:3\r\n    planeii = Ipainted(:, :, ii);\r\n    planeii(rings) = NaN;\r\n    Ipainted(:, :, ii) = inpaint_nans(planeii);\r\n<span style=\"color: #0000FF\">end<\/span>\r\nimshow(uint8(Ipainted))\r\ntitle(<span style=\"color: #A020F0\">\"Rings filled with inpainting\"<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainFEXSelect_03.png\"> <h3>Comments<a name=\"4\"><\/a><\/h3>\r\n   <p>Give these tools a try and let us know what you think <a href=\"http:\/\/blogs.mathworks.com\/pick\/?p=11535#respond\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_bb1865dcfe1b442e819672bada4aefcc() {\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='bb1865dcfe1b442e819672bada4aefcc ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' bb1865dcfe1b442e819672bada4aefcc';\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 = 'Sean de Wolski';\r\n        copyright = 'Copyright 2020 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_bb1865dcfe1b442e819672bada4aefcc()\"><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; R2020a<br><\/p>\r\n<\/div>\r\n<!--\r\nbb1865dcfe1b442e819672bada4aefcc ##### SOURCE BEGIN #####\r\n%% File Exchange Select\r\n%\r\n% <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s\r\n% pick this week are the \"File Exchange Select\" files: \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/4551 inpaint_nans>,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/8277 fminsearchbnd-fminsearchcon>\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/8998 surface-fitting-using-gridfit>\r\n% all by <http:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/869215 John\r\n% D'Errico>.\r\n%\r\n% The \"File Exchange Select\" banner\/badge was an old idea to advertise high\r\n% quality, reviewed File Exchange submissions.  It never really took off so\r\n% we'll be deprecating it soon.  The three files that did manage to get it\r\n% are these by John D'Errico, one of the File Exchange's most prolific\r\n% authors.  I'm very surprised none of these are are already picks of the\r\n% week!\r\n\r\n%% Inpaint_Nans\r\n% Today, I'll highlight |inpaint_nans|.\r\n%\r\n% I actually used inpaint_nans in grad school to help cover ring artifacts\r\n% caused by the detector in x-ray images.  I don't have one of those images\r\n% handy, so I'll use a picture of of one of my dogs instead.  I've injected\r\n% bright red ring artifacts to be easily detectable but emulate the real\r\n% ring artifacts.\r\n\r\nI = imread(\"LexiRing.png\");\r\nimshow(I)\r\ntitle(\"Ring Artifacts\")\r\n\r\n%% \r\n% Find rings and expand them a little bit to cover edge effects.\r\n\r\nrings = I(:, :, 1) > 200 & I(:, :, 2) < 100;\r\nrings = imdilate(rings, strel('disk', 2));\r\nimshow(rings)\r\n\r\n%%\r\n% Apply inpaint_nans to each channel.\r\n\r\nIpainted = double(I);\r\nfor ii = 1:3\r\n    planeii = Ipainted(:, :, ii);\r\n    planeii(rings) = NaN;\r\n    Ipainted(:, :, ii) = inpaint_nans(planeii);\r\nend\r\nimshow(uint8(Ipainted))\r\ntitle(\"Rings filled with inpainting\")\r\n\r\n%% Comments\r\n% \r\n% Give these tools a try and let us know what you think\r\n% <http:\/\/blogs.mathworks.com\/pick\/?p=11535#respond here>.\r\n%\r\n \r\n\r\n##### SOURCE END ##### bb1865dcfe1b442e819672bada4aefcc\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/mainFEXSelect_01.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   \r\n      Sean's pick this week are the \"File Exchange Select\" files: inpaint_nans, fminsearchbnd-fminsearchcon, and surface-fitting-using-gridfit all by John D'Errico.\r\n      \r\n      The \"File... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2020\/05\/22\/file-exchange-select-inpaint_nans-gridfit-and-fminsearchbnd-fminsearchcon\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11535"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=11535"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11535\/revisions"}],"predecessor-version":[{"id":11551,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/11535\/revisions\/11551"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=11535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=11535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=11535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}