{"id":4248,"date":"2013-01-18T09:00:12","date_gmt":"2013-01-18T14:00:12","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=4248"},"modified":"2013-01-18T09:12:53","modified_gmt":"2013-01-18T14:12:53","slug":"custom-ginput-2","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2013\/01\/18\/custom-ginput-2\/","title":{"rendered":"Custom GINPUT"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29096\">Idin<\/a>'s pick for this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/38703-custom-ginput\">custom GINPUT<\/a> by our very own <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro Doke<\/a>.\r\n   <\/p>\r\n   <p>This is the story of how a user's request for a feature turned into a File Exchange submission by one of our very capable\r\n      Application Engineers.\r\n   <\/p>\r\n   <p>A few months ago I was working with a user trying to build a MATLAB GUI when we ran into a seemingly trivial problem: we needed\r\n      the user to select a few points on a figure.  Solution was simple: <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/ginput.html\"><tt>ginput<\/tt><\/a>. The problem was that on some images MATLAB's default \"cross-hair\" cursor blended into the background.  Here's an example\r\n      that shows a mild case of the problem.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_customginput\/woman_bad_cursor.png\"> <\/p>\r\n   <p>You can see how it could be difficult to pick a precise point using this cross-hair. MATLAB's <tt>ginput<\/tt> function provides no flexibility to change the cursor.  We found the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/12-central-diff-m\">myginput<\/a> submission by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/20315\">Frederic Moisy<\/a>.  This got us a little closer, but not quite there. That's when I asked Jiro for help.  Jiro wrote a new function based on\r\n      MATLAB's <tt>ginput<\/tt> that makes the color and thickness of the cursor fully customizable.  Here&#8217;s the same image, but this time with Jiro's <tt>ginputc<\/tt> function:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">load <span style=\"color: #A020F0\">woman<\/span>\r\nimagesc(X)\r\ncolormap(map)\r\nginputc(<span style=\"color: #A020F0\">'color'<\/span>, <span style=\"color: #A020F0\">'r'<\/span>, <span style=\"color: #A020F0\">'linewidth'<\/span>, 3)<\/pre><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_customginput\/woman_new_cursor.png\"> <\/p>\r\n   <p>The picture speaks for itself! Jiro went further and added two new features that I hadn't even asked for:<\/p>\r\n   <div>\r\n      <ul>\r\n         <li>In the top left corner he shows a list of points the user has already selected<\/li>\r\n         <li>He can optionally connect the selected points (very useful if you're selecting an area)<\/li>\r\n      <\/ul>\r\n   <\/div>\r\n   <p>I would like to see some of these features find their way into MATLAB's <tt>ginput<\/tt> function. But in the meantime, I encourage you to download and try Jiro's <tt>ginputc<\/tt> function.\r\n   <\/p>\r\n   <p>As always, your comments <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=4248#respond\">here<\/a> are greatly appreciated.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_628564f4108f44a6bfc3637888161747() {\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='628564f4108f44a6bfc3637888161747 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 628564f4108f44a6bfc3637888161747';\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 = 'Idin Motedayen-Aval';\r\n        copyright = 'Copyright 2013 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_628564f4108f44a6bfc3637888161747()\"><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; R2012b<br><\/p>\r\n<\/div>\r\n<!--\r\n628564f4108f44a6bfc3637888161747 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/29096\r\n% Idin>'s pick for this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/38703-custom-ginput custom GINPUT>\r\n% by our very own\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007 Jiro\r\n% Doke>.\r\n%\r\n% This is the story of how a user's request for a feature turned into a\r\n% File Exchange submission by one of our very capable Application\r\n% Engineers.\r\n%\r\n% A few months ago I was working with a user trying to build a MATLAB GUI\r\n% when we ran into a seemingly trivial problem: we needed the user to\r\n% select a few points on a figure.  Solution was simple:\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/ginput.html |ginput|>. The\r\n% problem was that on some images MATLAB's default \"cross-hair\" cursor\r\n% blended into the background.  Here's an example that shows a mild case of\r\n% the problem.\r\n%\r\n% <<woman_bad_cursor.png>>\r\n%  \r\n% You can see how it could be difficult to pick a precise point using this\r\n% cross-hair. MATLAB's |ginput| function provides no flexibility to change\r\n% the cursor.  We found the\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/12-central-diff-m myginput>\r\n% submission by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/20315\r\n% Frederic Moisy>.  This got us a little closer, but not quite there.\r\n% That's when I asked Jiro for help.  Jiro wrote a new function based on\r\n% MATLAB's |ginput| that makes the color and thickness of the cursor fully\r\n% customizable.  Here\u00e2\u20ac\u2122s the same image, but this time with Jiro's |ginputc|\r\n% function:\r\n%\r\n%   load woman\r\n%   imagesc(X)\r\n%   colormap(map)\r\n%   ginputc('color', 'r', 'linewidth', 3)\r\n%\r\n% <<woman_new_cursor.png>>\r\n%\r\n% The picture speaks for itself! Jiro went further and added two new\r\n% features that I hadn't even asked for:\r\n%\r\n% * In the top left corner he shows a list of points the user has already\r\n% selected\r\n% * He can optionally connect the selected points (very useful if you're\r\n% selecting an area)\r\n%\r\n% I would like to see some of these features find their way into MATLAB's\r\n% |ginput| function. But in the meantime, I encourage you to download and\r\n% try Jiro's |ginputc| function.\r\n%\r\n% As always, your comments <https:\/\/blogs.mathworks.com\/pick\/?p=4248#respond\r\n% here> are greatly appreciated.\r\n\r\n##### SOURCE END ##### 628564f4108f44a6bfc3637888161747\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/idin\/potw_customginput\/woman_bad_cursor.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n   Idin's pick for this week is custom GINPUT by our very own Jiro Doke.\r\n   \r\n   This is the story of how a user's request for a feature turned into a File Exchange submission by one of our very... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2013\/01\/18\/custom-ginput-2\/\">read more >><\/a><\/p>","protected":false},"author":36,"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\/4248"}],"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\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=4248"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4248\/revisions"}],"predecessor-version":[{"id":4256,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/4248\/revisions\/4256"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=4248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=4248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=4248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}