{"id":163,"date":"2007-10-26T07:00:02","date_gmt":"2007-10-26T11:00:02","guid":{"rendered":"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/26\/bwselect\/"},"modified":"2019-10-23T15:23:00","modified_gmt":"2019-10-23T19:23:00","slug":"bwselect","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/26\/bwselect\/","title":{"rendered":"bwselect"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p>Didja know about the Image Processing Toolbox function <tt>bwselect<\/tt>?\r\n   <\/p>\r\n   <p>For a blog post I wrote earlier this month, I wanted a binary image containing only the central blob indicated in red below:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">url = <span style=\"color: #A020F0\">'https:\/\/blogs.mathworks.com\/images\/steve\/163\/plateaus.png'<\/span>;\r\nbw = imread(url);\r\nimshow(bw)\r\nannotation(gcf,<span style=\"color: #A020F0\">'ellipse'<\/span>,<span style=\"color: #A020F0\">'LineWidth'<\/span>,3,<span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Position'<\/span>,[0.4931 0.463 0.07575 0.2029],<span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Color'<\/span>,[0.8471 0.1608 0]);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/163\/show_bwselect_01.png\"> <p>The Image Processing Toolbox function <tt>bwselect<\/tt> is perfect for this task.  You can use it interactively or noninteractively.\r\n   <\/p>\r\n   <p>If you use the interactive syntax:<\/p><pre> bw2 = bwselect(bw)<\/pre><p>the function displays <tt>bw<\/tt> and waits for you to click on the image with the mouse.  You can click on one or multiple points.  To finish your selection,\r\n      double-click on the last point, or just press RETURN. <tt>bwselect<\/tt> then returns a binary image containing only the objects (\"blobs\") that you clicked on.\r\n   <\/p>\r\n   <p>You can also use the noninteractive syntax, in which you pass in the point locations as input arguments instead of using the\r\n      mouse.\r\n   <\/p>\r\n   <p>For example:<\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">pond = bwselect(bw, 183, 170);\r\nclf\r\nimshow(pond)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/steve\/163\/show_bwselect_02.png\"> <p>I hope you find this function useful.<\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_62f8e9386e98406bb99aa7a19d9f4cf6() {\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='62f8e9386e98406bb99aa7a19d9f4cf6 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 62f8e9386e98406bb99aa7a19d9f4cf6';\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 2007 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_62f8e9386e98406bb99aa7a19d9f4cf6()\"><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.5<br><\/p>\r\n<\/div>\r\n<!--\r\n62f8e9386e98406bb99aa7a19d9f4cf6 ##### SOURCE BEGIN #####\r\n%%\r\n% Didja know about the Image Processing Toolbox function \r\n% <https:\/\/www.mathworks.com\/help\/images\/index.htmlbwselect.html \r\n% |bwselect|>?\r\n%\r\n% For a blog post I wrote earlier this month, I wanted a binary image\r\n% containing only the central blob indicated in red below:\r\n\r\nurl = 'https:\/\/blogs.mathworks.com\/images\/steve\/163\/plateaus.png';\r\nbw = imread(url);\r\nimshow(bw)\r\nannotation(gcf,'ellipse','LineWidth',3,...\r\n    'Position',[0.4931 0.463 0.07575 0.2029],...\r\n    'Color',[0.8471 0.1608 0]);\r\n\r\n%%\r\n% The Image Processing Toolbox function |bwselect| is perfect for this\r\n% task.  You can use it interactively or noninteractively.\r\n%\r\n% If you use the interactive syntax:\r\n%\r\n%   bw2 = bwselect(bw)\r\n%\r\n% the function displays |bw| and waits for you to click on the image with\r\n% the mouse.  You can click on one or multiple points.  To finish your\r\n% selection, double-click on the last point, or just press RETURN.\r\n% |bwselect| then returns a binary image containing only the objects\r\n% (\"blobs\") that you clicked on.\r\n%\r\n% You can also use the noninteractive syntax, in which you pass in the\r\n% point locations as input arguments instead of using the mouse.\r\n%\r\n% For example:\r\n\r\npond = bwselect(bw, 183, 170);\r\nclf\r\nimshow(pond)\r\n\r\n%%\r\n% I hope you find this function useful.\r\n##### SOURCE END ##### 62f8e9386e98406bb99aa7a19d9f4cf6\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Didja know about the Image Processing Toolbox function bwselect?\r\n   \r\n   For a blog post I wrote earlier this month, I wanted a binary image containing only the central blob indicated in red... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/steve\/2007\/10\/26\/bwselect\/\">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":[424,418,178,76,36],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/163"}],"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=163"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":2255,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/posts\/163\/revisions\/2255"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/media?parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/categories?post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/steve\/wp-json\/wp\/v2\/tags?post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}