{"id":2493,"date":"2009-11-06T13:58:14","date_gmt":"2009-11-06T13:58:14","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/06\/segmenting-coinsa-tutorial-on-blob-analysis\/"},"modified":"2018-01-08T15:09:28","modified_gmt":"2018-01-08T20:09:28","slug":"segmenting-coinsa-tutorial-on-blob-analysis","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/06\/segmenting-coinsa-tutorial-on-blob-analysis\/","title":{"rendered":"Segmenting Coins&#8230;a Tutorial on Blob Analysis"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/introduction>\r\n   <p>Many of us who have used or participated in <a>comp.soft-sys.matlab<\/a> over the years--particularly those of us who have had occasion to solve image processing problems--have come to appreciate\r\n      <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/31862\">Image Analyst<\/a>'s thoughts on relevant matters.\r\n   <\/p>\r\n   <p>Recently, Image Analyst had occasion to share his first file through the File Exchange--a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/25157-image-segmentation-tutorial\">demo tutorial on blob analysis<\/a>. In a nice, well-documented bit of code, IA steps us through an approach to segmenting, and determining the properties of,\r\n      some objects in an image. In this case, the image is a sample ('coins.png') that ships with the <a href=\"https:\/\/www.mathworks.com\/products\/image\/\">Image Processing Toolbox<\/a>.\r\n   <\/p>\r\n   <p>IA's code shows how one might segment objects of interest (coins) from the background, then use <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/regionprops.html\"><tt>regionprops<\/tt><\/a> (my favorite IPT function!) to differentiate nickels from dimes, and dull dimes from shiny ones:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/..\/images\/pick\/blobsdemo.png\"> <\/p>\r\n   <p>This is a nice demo--very informative, and certainly worth a read. Two thoughts: 1) IA's code uses <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/bwlabel.html\"><tt>bwlabel<\/tt><\/a> to calculate a connected components matrix of the image as a precursor to calling <tt>regionprops<\/tt>. As of R2009a, the new IPT function <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/bwconncomp.html\"><tt>bwconncomp<\/tt><\/a> replaces <tt>bwlabel<\/tt> as the preferred approach; it uses significantly less memory, and can be markedly faster! Also, 2) IA shows how one can extract\r\n      the specific pixels (PixelIdxList) associated with each object of interest, then calculate statistics on those pixel intensities\r\n      to differentiate shiny from dull objects. Note that the fourth syntax of <tt>regionprops<\/tt> in the documentation enables one to avoid this step, and instead to operate directly on the original intensity image. Using\r\n      this syntax, one can calculate directly the MIN, MAX, or MEAN intensitities--or even the weighted centroids-- of each blob\r\n      in the image.\r\n   <\/p>\r\n   <p>Nice work, Image Analyst!<\/p>\r\n   <p><a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2493#respond\">Comments?<\/a><\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_7a225168421d45409cc96a1d89ff7009() {\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='7a225168421d45409cc96a1d89ff7009 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 7a225168421d45409cc96a1d89ff7009';\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 = 'Brett Shoelson';\r\n        copyright = 'Copyright 2009 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_7a225168421d45409cc96a1d89ff7009()\"><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.9<br><\/p>\r\n<\/div>\r\n<!--\r\n7a225168421d45409cc96a1d89ff7009 ##### SOURCE BEGIN #####\r\n%% Segmenting Coins...a Tutorial on Blob Analysis\r\n%%\r\n% Many of us who have used or participated in <http:\/\/ comp.soft-sys.matlab> over the\r\n% yearsREPLACE_WITH_DASH_DASHparticularly those of us who have had occasion to solve image\r\n% processing problemsREPLACE_WITH_DASH_DASHhave come to appreciate <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/31862 Image Analyst>'s thoughts on\r\n% relevant matters. \r\n\r\n%%\r\n% Recently, Image Analyst had occasion to share his first file through the\r\n% File ExchangeREPLACE_WITH_DASH_DASHa <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/25157-image-segmentation-tutorial demo tutorial on blob analysis>. In a nice,\r\n% well-documented bit of code, IA steps us through an approach to\r\n% segmenting, and determining the properties of, some objects in an image.\r\n% In this case, the image is a sample ('coins.png') that ships with the \r\n% <https:\/\/www.mathworks.com\/products\/image\/ Image Processing Toolbox>. \r\n\r\n%% \r\n% IA's code shows how one might segment objects of interest (coins) from\r\n% the background, then use <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/regionprops.html |regionprops|> (my favorite IPT function!) to differentiate\r\n% nickels from dimes, and dull dimes from shiny ones:\r\n%\r\n%%\r\n% \r\n% <<BlobsDemo.png>>\r\n% \r\n%%\r\n% This is a nice demoREPLACE_WITH_DASH_DASHvery informative, and certainly worth a read. Two\r\n% thoughts: 1) IA's code uses <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/bwlabel.html |bwlabel|> to calculate a connected components\r\n% matrix of the image as a precursor to calling |regionprops|. As of\r\n% R2009a, the new IPT function <https:\/\/www.mathworks.com\/help\/releases\/R2009b\/toolbox\/images\/bwconncomp.html |bwconncomp|> replaces |bwlabel| as the\r\n% preferred approach; it uses significantly less memory, and can be\r\n% markedly faster! Also, 2) IA shows how one can extract the specific\r\n% pixels (PixelIdxList) associated with each object of interest, then\r\n% calculate statistics on those pixel intensities to differentiate shiny\r\n% from dull objects. Note that the fourth syntax of |regionprops| in the documentation enables\r\n% one to avoid this step, and instead to operate directly on the original\r\n% intensity image. Using this syntax, one can calculate directly the MIN,\r\n% MAX, or MEAN intensititiesREPLACE_WITH_DASH_DASHor even the weighted centroidsREPLACE_WITH_DASH_DASH of each blob\r\n% in the image.\r\n%%\r\n% Nice work, Image Analyst!\r\n%\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2493#respond Comments?>\r\n##### SOURCE END ##### 7a225168421d45409cc96a1d89ff7009\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Many of us who have used or participated in comp.soft-sys.matlab over the years--particularly those of us who have had occasion to solve image processing problems--have come to appreciate\r\n... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/11\/06\/segmenting-coinsa-tutorial-on-blob-analysis\/\">read more >><\/a><\/p>","protected":false},"author":34,"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\/2493"}],"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\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2493"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2493\/revisions"}],"predecessor-version":[{"id":9314,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2493\/revisions\/9314"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}