I'm a complete beginner to object recognition.

I need to identify and count how many of a certain type of Lego, in a picture full of different pieces of Lego, using MATLAB.

The pieces of Lego I need to identify, are of a certain shape, colour and size.

I need suggestions for algorithms that can perform this task, and links to where I can find more information about them.

From the research I've done, so many are focused around facial recognition, and provide no help for me!

I followed a tutorial that used SURF points to identify points of interest, in the scene pictures and the picture of the Lego picture to find. But it wasn't able to pick up on all the aspects of the Lego piece, and therefore didn't have a chance of finding it in the scene.

If there aren't any algorithms that can perform this, how can I at least separate the pieces based on their colours?

Any suggestions would be really handy! Thanks in advance.


Sample picture where I will need to identify certain pieces:

enter image description here

  • $\begingroup$ Object detection is very broad area of image processing. There are so many algorithms and methods. If you share sample pictures, I can help you to find correct approach for your problem. $\endgroup$
    – ekarem
    Jan 13, 2015 at 16:12

1 Answer 1


SURF works well for objects with distinctive textures. Unfortunately, all lego blocks have essentially the same texture, so it is not a good cue for telling them apart. The other difficulty is that your blocks can have different 3D orientations.

The good news is that they are brightly colored. The Color Thresholder app is a good way to segment out objects by color. Once you have identified individual blocks, you can try to use other cues, such as size and shape to identify different blocks of the same color. Try using the regionprops function. For example Eccentricity can help you distinguish between a square block and an elongated block, assuming they are viewed from the top.

Unfortunately, I can only give you a starting point, not the complete solution. You are going to have to do some experimenting here.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.