MATLAB Answers

0

How to implement a funtion to 'Count an amount of one type of lego piece in the Image'?

Asked by Chanodom Utsahajit on 18 Jan 2015
Latest activity Commented on by Image Analyst
on 13 Jan 2019
Sorry if it's a lot to ask but is there an easy way to implement a function that takes in the image of cluster of lego pieces and returns the count of a particular type of Lego piece? i.e. given the lego piece type shown in the first image--------->
how to implement a function that return the amount of the same type of lego pieces existed in the image below.
Thank you very much in advance!!
Baz

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 19 Jan 2015
 Accepted Answer

First you have to do color segmentation to get separate, individual blocks. See my File Exchange for demos: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Then try using imfindcircles() to count the circles in each colored brick. Here is a demo: http://www.mathworks.com/matlabcentral/fileexchange/34365-circle-finder

  6 Comments

I doubt you'd be able to do research online and find a solution like that, unless you're very very lucky. I think you're going to be stuck writing code.
Even so, there are cases when you just can't get it right. For example, in a jumbled pile of Lego's, if you see just the end of a block, there is no way of knowing if it's a 4-bump Lego or an 8-bump Lego. No way. They both look identical.
Good luck though.
I know there is no way but is there any way to measure the length of the side of the pieces thats longest along the perimeter. And if there is no way to do that is there a way to measure at least the bounding boxes longest side. Or get the bound area to a threshold measuring the ratio of the other pieces and create a ratio of the smallest section and the biggest area, and discard only the small sectors, Areafilter has an option to get the biggest chunks in an image but it has a N number input how would someone go on to make it a variable amount depending on image. Or measure from a centroid to the corner of the object at least. Would ConvexHull property from regionprops be of any use in this task. Or instead would cuboid search with regionprops3 be of any use for the task. The following images illustrate the bounding boxes i created around the objects but cannot measure them just yet. Thanks for your help in advance.
Kind regards,
Nafis
Well of course you can ask regionprops() for the BoundingBox, but I think you may want the Feret Diameters.

Sign in to comment.