{"id":601,"date":"2012-12-27T13:15:00","date_gmt":"2012-12-27T18:15:00","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=601"},"modified":"2012-12-26T13:15:33","modified_gmt":"2012-12-26T18:15:33","slug":"end-of-year-suggestion-steve-on-counting","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2012\/12\/27\/end-of-year-suggestion-steve-on-counting\/","title":{"rendered":"End of Year Suggestion: Steve on Counting"},"content":{"rendered":"<!DOCTYPE html\r\n  PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\">\r\n<style type=\"text\/css\">\r\n\r\nh1 { font-size:18pt; }\r\nh2.titlebg { font-size:13pt; }\r\nh3 { color:#4A4F55; padding:0px; margin:5px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:11pt; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }\r\nh4 { color:#4A4F55; padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:10pt; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }\r\n   \r\np { padding:0px; margin:0px 0px 20px; }\r\nimg { padding:0px; margin:0px 0px 20px; border:none; }\r\np img, pre img, tt img, li img { margin-bottom:0px; } \r\n\r\nul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }\r\nul li { padding:0px; margin:0px 0px 7px 0px; background:none; }\r\nul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }\r\nul li ol li { list-style:decimal; }\r\nol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }\r\nol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }\r\nol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }\r\nol li ol li { list-style-type:lower-alpha; }\r\nol li ul { padding-top:7px; }\r\nol li ul li { list-style:square; }\r\n\r\npre, tt, code { font-size:12px; }\r\npre { margin:0px 0px 20px; }\r\npre.error { color:red; }\r\npre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }\r\npre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }\r\n\r\n@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }\r\n\r\nspan.keyword { color:#0000FF }\r\nspan.comment { color:#228B22 }\r\nspan.string { color:#A020F0 }\r\nspan.untermstring { color:#B20000 }\r\nspan.syscmd { color:#B28C00 }\r\n\r\n.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }\r\n.footer p { margin:0px; }\r\n\r\n  <\/style><div class=\"content\"><!--introduction--><p>I just read the <a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/12\/18\/counting-objects-without-bias\/\">latest post<\/a> on Steve Eddins image processing blog.  I recommend you read it too.  It discusses how to count objects in an image without introducing bias. It would be easy to count all the blobs you see, including partial ones cut by the border.  But that would be an overestimate. So how do we get a better estimate?<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#f9e55fd8-5a01-4f8c-9a63-d2a96ac3a3f4\">Counting Via Each \"Lower Right Corner\"<\/a><\/li><li><a href=\"#555a669c-ece8-498d-a6fc-98182402ec9b\">Weighted Count of Interior Objects<\/a><\/li><\/ul><\/div><h4>Counting Via Each \"Lower Right Corner\"<a name=\"f9e55fd8-5a01-4f8c-9a63-d2a96ac3a3f4\"><\/a><\/h4><p>The first technique Steve discusses is one I am familiar with already. The basic idea is to count all objects that don't touch any edges of the image, and only count objects if they touch two adjacent edges, say the north and west ones, equivalent to counting objects via the \"lower right corner\". That will, statistically speaking, give you an unbiased estimate of the count.<\/p><h4>Weighted Count of Interior Objects<a name=\"555a669c-ece8-498d-a6fc-98182402ec9b\"><\/a><\/h4><p>The second method instead does a weighted count of only the objects that touch no edges.  The weighting accounts for the relative likelihood for an object of that size to encounter an edge from a particular view.  See Steve's code and explanation to learn more of the details.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_63f7c7f2f6b341548f40dbfda156ede2() {\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='63f7c7f2f6b341548f40dbfda156ede2 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 63f7c7f2f6b341548f40dbfda156ede2';\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        copyright = 'Copyright 2012 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_63f7c7f2f6b341548f40dbfda156ede2()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2012b<br><\/p><\/div><!--\r\n63f7c7f2f6b341548f40dbfda156ede2 ##### SOURCE BEGIN #####\r\n%% End of Year Suggestion: Steve on Counting\r\n% I just read the\r\n% <https:\/\/blogs.mathworks.com\/steve\/2012\/12\/18\/counting-objects-without-bias\/\r\n% latest post> on Steve Eddins image processing blog.  I recommend you read\r\n% it too.  It discusses how to count objects in an image without\r\n% introducing bias. It would be easy to count all the blobs you see,\r\n% including partial ones cut by the border.  But that would be an\r\n% overestimate. So how do we get a better estimate?\r\n%% Counting Via Each \"Lower Right Corner\"\r\n% The first technique Steve discusses is one I am familiar with already.\r\n% The basic idea is to count all objects that don't touch any edges of the\r\n% image, and only count objects if they touch two adjacent edges, say the\r\n% north and west ones, equivalent to counting objects via the \"lower right\r\n% corner\". That will, statistically speaking, give you an unbiased estimate\r\n% of the count.\r\n%\r\n%% Weighted Count of Interior Objects\r\n% The second method instead does a weighted count of only the objects that\r\n% touch no edges.  The weighting accounts for the relative likelihood for\r\n% an object of that size to encounter an edge from a particular view.  See\r\n% Steve's code and explanation to learn more of the details.\r\n\r\n##### SOURCE END ##### 63f7c7f2f6b341548f40dbfda156ede2\r\n-->","protected":false},"excerpt":{"rendered":"<!--introduction--><p>I just read the <a href=\"https:\/\/blogs.mathworks.com\/steve\/2012\/12\/18\/counting-objects-without-bias\/\">latest post<\/a> on Steve Eddins image processing blog.  I recommend you read it too.  It discusses how to count objects in an image without introducing bias. It would be easy to count all the blobs you see, including partial ones cut by the border.  But that would be an overestimate. So how do we get a better estimate?... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2012\/12\/27\/end-of-year-suggestion-steve-on-counting\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/601"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=601"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/601\/revisions"}],"predecessor-version":[{"id":604,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/601\/revisions\/604"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}