{"id":5372,"date":"2014-06-06T09:00:44","date_gmt":"2014-06-06T13:00:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5372"},"modified":"2014-06-06T08:34:50","modified_gmt":"2014-06-06T12:34:50","slug":"detecting-circles-in-images-revisited-2","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/06\/06\/detecting-circles-in-images-revisited-2\/","title":{"rendered":"Detecting circles in images, revisited"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><!--introduction--><!--\/introduction--><p>This week, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a> revisits the historical quest for a circle detection algorithm, and pays tribute to the File Exchange files and authors that led to MathWorks' to offer our own officially supported circle detection algorithm.<\/p><p>I&#8217;ve been supporting MATLAB users as an application engineer for nearly 10 years now, and writing about files on the MATLAB Central File Exchange for nearly as long. In my role at MathWorks, I get to talk to people frequently about how they use our tools, and about how they would <i>like<\/i> to use our tools in ways that are not &#8220;officially&#8221; supported. It's part of my job to feed that information back to our developers, and it helps them to decide where they should be spending their development efforts.<\/p><p>Back in May, 2008, I <a href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/05\/23\/detecting-circles-in-an-image\/\">wrote about<\/a> the difficulty of detecting circles in images using MATLAB; people asked for that capacity often, but we had no in-product tools to facilitate that detection process. <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/21266\">Tao Peng's<\/a> File Exchange submission was my go-to recommendation whenever customers asked.<\/p><p>Partly because you asked so often, and partly because Tao's solution was so popular, we finally introduced in 2012 a couple of different Hough transforms for circle detection; if you haven't used it, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/21266\"><tt>imfindcircles<\/tt><\/a> now makes easy work of the difficult task of finding circles in images.<\/p><p>If you need to detect circles in images, and if you have the <a href=\"https:\/\/www.mathworks.com\/products\/image\/\">Image Processing Toolbox<\/a>, <tt>imfindcircles<\/tt> will be your friend; it's fast, and flexible. (I haven't seen a robust solution that works independently of that Toolbox. Correct me, please, if I've overlooked something.)<\/p><p>Also, if you have a compelling use case for a generalized Hough transform--for detecting shapes in images <i>other than circles or lines<\/i>--please add a comment below to let us know!<\/p><p>In the meantime, try out <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/34365-circle-finder\"><tt>FindCirclesGUI<\/tt><\/a> if you haven't already done so; it allows you to change any of the input parameters to <tt>imfindcircles<\/tt>, and to interactively see the results:<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/FindCirclesGUI.png\" alt=\"\"> <\/p><p>As always, I welcome your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5372#respond\">thoughts and comments<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_5c9db370b0474061944a60893e505e34() {\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='5c9db370b0474061944a60893e505e34 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 5c9db370b0474061944a60893e505e34';\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 2014 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_5c9db370b0474061944a60893e505e34()\"><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; R2014a<br><\/p><\/div><!--\r\n5c9db370b0474061944a60893e505e34 ##### SOURCE BEGIN #####\r\n%% Finding circles, revisited\r\n%% \r\n% This week,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>\r\n% revisits the historical quest for a circle detection algorithm, and pays tribute to\r\n% the File Exchange files and authors that led to MathWorks' to offer our own \r\n% officially supported circle detection algorithm.\r\n\r\n%% \r\n% I\u00e2\u20ac\u2122ve been supporting MATLAB users as an application engineer for nearly\r\n% 10 years now, and writing about files on the MATLAB Central File Exchange\r\n% for nearly as long. In my role at MathWorks, I get to talk to people\r\n% frequently about how they use our tools, and about how they would _like_ to use\r\n% our tools in ways that are not \u00e2\u20ac\u0153officially\u00e2\u20ac\ufffd supported. It's part of my\r\n% job to feed that information back to our developers, and it helps them to\r\n% decide where they should be spending their development efforts.\r\n\r\n%% \r\n% Back in May, 2008, I <https:\/\/blogs.mathworks.com\/pick\/2008\/05\/23\/detecting-circles-in-an-image\/ wrote about> \r\n% the difficulty of detecting circles in images using MATLAB; people asked\r\n% for that capacity often, but we had no in-product tools to facilitate that detection\r\n% process. <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/21266 Tao Peng's>\r\n% File Exchange submission was my go-to recommendation whenever customers\r\n% asked.\r\n\r\n%%\r\n% Partly because you asked so often, and partly because Tao's solution was\r\n% so popular, we finally introduced in 2012 a couple of different Hough\r\n% transforms for circle detection; if you haven't used it, \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/21266 |imfindcircles|>\r\n% now makes easy work of the difficult task of finding circles in images.\r\n\r\n%%\r\n% If you need to detect circles in images, and if you have the\r\n% <https:\/\/www.mathworks.com\/products\/image\/ Image Processing Toolbox>,\r\n% |imfindcircles| will be your friend; it's fast, and flexible.\r\n% (I haven't seen a robust solution that works independently of that Toolbox. Correct me, please, \r\n% if I've overlooked something.)\r\n\r\n%%\r\n% Also, if you have a compelling use case for a generalized Hough\r\n% transformREPLACE_WITH_DASH_DASHfor detecting shapes in images _other than\r\n% circles or lines_REPLACE_WITH_DASH_DASHplease add a comment below to let us know!\r\n\r\n%% \r\n% In the meantime, try out <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/34365-circle-finder |FindCirclesGUI|> if you haven't already done so;\r\n% it allows you to change any of the input parameters to |imfindcircles|,\r\n% and to interactively see the results:\r\n%%\r\n% \r\n% <<https:\/\/blogs.mathworks.com\/pick\/files\/FindCirclesGUI.png>>\r\n% \r\n\r\n%%\r\n% As always, I welcome your\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5372#respond thoughts and comments>.\r\n##### SOURCE END ##### 5c9db370b0474061944a60893e505e34\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/pick\/files\/FindCirclesGUI.png\" onError=\"this.style.display ='none';\" \/><\/div><p>\r\n\r\nThis week, Brett revisits the historical quest for a circle detection algorithm, and pays tribute to the File Exchange files and authors that led to MathWorks' to offer our own officially... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/06\/06\/detecting-circles-in-images-revisited-2\/\">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\/5372"}],"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=5372"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5372\/revisions"}],"predecessor-version":[{"id":5380,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5372\/revisions\/5380"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}