Colour segmentation on resistor color band and calculate the value
Mostrar comentarios más antiguos
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?
6 comentarios
Jan
el 28 de Dic. de 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.
You can approach this problem from both ends: having a list of known resistor values could help you assign a weight to the color-combinations that you get. Because resistors come in fixed and known combinations you can use this to choose the most likely value out of several similar matches, or confirm/reject the value that you have detected.
You might find my FEX submission useful to help do this:
The main function rounds the input values to the standard resistor values: you can use it to check your detected color combination are the same as a known standard value:
>> round60063(514, 'E24')
ans = 510
Its 3rd output returns the full preferred number sequence of values that includes all input values, for example:
>> [~,~,pns] = round60063([1,1e6],'E12');
pns = [1;1.2;1.5;1.8;2.2;2.7;3.3; .. ;470000;560000;680000;820000;1000000]
returns all preferred values in the E12 range, between one and one million.
reginald kwenda
el 24 de Mzo. de 2015
i am currently working on the same project , i have looked at your code but i am finding it hard to understand
vv_art
el 22 de Jul. de 2018
me too
Image Analyst
el 22 de Jul. de 2018
Exactly which code are you two having trouble understanding?
Respuesta aceptada
Más respuestas (1)
reginald kwenda
el 19 de Feb. de 2015
Editada: Image Analyst
el 19 de Feb. de 2015
0 votos
Hello guys, I am working on the same problem. I have managed to detect Red, Green, and Blue following an example that was given by Image Analyst ( http://www.mathworks.com/matlabcentral/answers/57356#comment_119461)
I have detected these colors off a resistor, but I don't know how to detect other colors such as yellow or brown.
16 comentarios
Image Analyst
el 19 de Feb. de 2015
Each color has a hue. Convert your image to hsv space and find the hue and see which of the standard colors it comes closest to. Post your code and image in a new question if you need more help.
reginald kwenda
el 26 de Feb. de 2015
Movida: DGM
el 12 de Feb. de 2023
i have got the code to detect most of the colours except black and white. From there how can i use if statement to give each colour a number and add them up to give resistance value.

Above is the image I am using.
Image Analyst
el 4 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
What I would do is to first find the resistor and then get a mask that is a stripe through the color bands. Then convert to hsv and find the color of the brown. And then convert to lab color space and find the delta E (color difference) of all pixels to that standard brown color. Regions with high delta E will be the color stripes. Then segment each of those and get the mean LAB color and compare that to known LAB colors of standard colors like red, green, blue, gold, etc. I have color segmentation programs in my file exchange. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
reginald kwenda
el 21 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
@image analyst i was replying to you
Image Analyst
el 21 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
For black and white, you can convert to gray scale and look for pixels with values less than 30 (or whatever) or more than 200 (or whatever). Make sure you filter by size so you don't get the legs or background or reflections.
Image Analyst
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
You should use the Comment box instead of creating a brand new original "Answer" to the original poster's original question at the very top. I don't have any video tutorials, just what is in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
reginald kwenda
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
okay i understand ,i am new to digital image processing . I took on a project on writing a programme in matlab that should extract resistor color bands from an image and do calculations to give resistance values .I saw this as a challenge to learn something new and finding a passion. Through the help that you gave to Ng (the guy that started this poster) i learned how to extract the colours off an image but now i am stuck on how i can give each colour a number and make the calculations to give resistance value.
reginald kwenda
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
I appreciate you taking your time to reply my questions
Image Analyst
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
I think the comments above about first finding the stripes, and then comparing the colors to a list of known, predefined colors is a good suggestion. To make it really easy, first make a jig to make sure that your resistors are all positioned in exactly the same position. Then just crop out known rectangles where you know the stripes will be. Look at their color and compare to the predefined list of colors and find out what predefined color is closest to your stripe color.
reginald kwenda
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
i have used the code above and managed to extract red , green and blue strip from the resistor image but using rgb space.How can i proceed in giving these three colours their resistance value which is 5600 . green represents 5 , blue represent 6 and red represents 2..to get resistance value you read the colours from left to right.in this case 5(green)6(blue)* last colour red which represets the number of zeros = 5600
Image Analyst
el 23 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
You assign the digits when you get the color as you examine the stripes. Then use the formula
resistanceValue = (firstDigit * 10 + secondDigit) * 10^numberOfZeros;
reginald kwenda
el 24 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
rgbImage = imread('resistor.jpg');
imshow(rgbImage);
impixelinfo;
Red=2
Green = 6
Blue=5
firstDigit=0
secondDigit=0
thirdDigit=0
RedSpace = rgbImage(:, :, 1);
GreenSpace = rgbImage(:,:, 2);
BlueSpace = rgbImage(:, :, 3);
if (redMask = (RedSpace > 190) & (GreenSpace < 150) & (BlueSpace < 90));
(redMask = imfill(redMask, 'holes'); % Filling in holes.
(firstDigit= Red)
end
%resistanceValue = (firstDigit * 10 + secondDigit) * 10^numberOfZeros;
if(greenMask=(RedSpace < 167) & (GreenSpace > 160) & (BlueSpace < 150));
(greenMask = imfill(greenMask, 'holes')) % Filling in holes.
(secondDigit= Green)
end
if(blueMask = (RedSpace < 120) & (GreenSpace > 60) & (BlueSpace < 130) & (BlueSpace> 100));
(blueMask = imfill(blueMask, 'holes')); % Filling in holes.
(thirdDigit= Blue)
end
resistanceValue = (firstDigit * 10 + secondDigit) * 10^thirdDigit;
reginald kwenda
el 24 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
@image analyst..that is what i came up with but i keep getting an error with the if statements(i am using the same image that Ng used)
reginald kwenda
el 24 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023

reginald kwenda
el 24 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
i am getting errors with the if statements
Image Analyst
el 24 de Mzo. de 2015
Movida: DGM
el 12 de Feb. de 2023
redMask is an image, so why is it the expression of an "if" statement - that doesn't make sense.
Also, you got the wrong values for green and blue - you swapped the values. Green should be 5 and blue is 6.
Categorías
Más información sobre Blue en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
