Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Colour segmentation on resistor color band and calculate the value

Asked by Ng on 11 Dec 2012

I'm a beginner to Matlab. I need to do a color segmentation on a resistor color band, identify the color and do a calculation based on the color. Any guideline for this?


Jan Simon on 28 Dec 2012

This is a very general question. It is unlikely that you get a specific answer, which matchs your needs exactly. This forum is powerful, when you post, what you have tried so far and ask a specific Matlab related question. But you will most likely not get a running program after a vague description of the problem. Please note, that all information you have offered about the inputs is "a resistor color band" - we do neither know, if this is a real-time video capture, a graphics file, an imported image in indexed colors, an RGB value of a specific pixel or the real-world resistor in your hand only. The less the readers have to guess, the easier and more likely is a useful answer.

Ng on 29 Dec 2012

Is my bad for not giving enough information. I understand that it is impossible to find an answer that fulfill my need exactly. What I need just a simple guideline as I never learn about this program at all. What I needed now is how to identify all the 10 colors of the resistor band and made a calculation on that. Basically I've tried some code given by ImageAdjust and successfully identify 3 color only which is red,green and blue. The other colors really making me headache.


2 Answers

Answer by Image Analyst on 11 Dec 2012
Accepted answer

I have color segmentation tutorials here if you're interested: Basically you need to find the regions of interest first - the bands. You might use a variety of techniques depending on how repeatable the lighting and positioning are from image to image. Then you can look at the mean RGB value of each band and see which "master" color it's closest to. If the band is closer red color than any other, then assume it's red.


Ng on 29 Dec 2012

oo...I got it d...haha...thanks alot >.<

Image Analyst on 30 Dec 2012

Good. Sounds like I helped you solve it.

Ng on 30 Dec 2012

Thanks alot for your help. >.<

Image Analyst
Answer by vincent on 11 Mar 2013

Try not to be intimidated by the colours, I think it should be easy to get round this. Certainly I wouldn't let it put you off electronics, too much fun to be had :-)

You would ideally have them sorted into separate marked drawers anyway. For example these storage cabinets are what we use. It has 44 separate drawers that can be divided themselves into three parts with dividers, and a slot at the front for a label card. There are many types/sizes around so find something that suits your needs.

That gets you "pretty certain" that the resistor you take out of the drawer will be the right one. To make sure though, I would maybe buy a cheap multimeter (or repurpose one) and set it up as a value tester. If you make a little frame to set the probes just the right distance apart, you can quickly place the resistor between them and double check it's value.

This is more for loose resistors, but another option is to keep them in their packets in the drawers until needed, then take out as necessary. Though you can get errors in the packaging/component it's very very rare, and if you test one you can be even more sure all the rest will be the same anyway.

This should ensure you have very little chance of making a mistake (probably about as much as anyone else, many don't go by the colour bands anyway)

Most other components nowadays have values/codes marked on them, and if you are working with SMD (most) resistors do too - it's the unmarked capacitors that are the pain (for everyone) there :-)



Contact us