How do i threshold blue colors in Simulink?
50 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am working on RGB signals. I set From Video Device Block to Seperate Signals RGB. I need to detect blue colors. How do i threshold blue signal? I am trying to execute on only blue pixels. Thank you...
0 comentarios
Respuestas (3)
Walter Roberson
el 6 de En. de 2012
Is (0,0,255) "blue"? Probably. Okay, how about (0,0,0)? (0,0,1) ? (1,0,255) ?
You need to define what "blue" means for your purposes before you can go ahead.
Jonathan Sullivan
el 6 de En. de 2012
Perhaps I might suggest something else. I don't believe you want to threshold based an the absolute amount of blue present in a pixel, but rather based off of the relative amount of blue compared to red and green.
Let's look at a few different colors:
c1 = [0 0 255];
c2 = [255 0 255];
c3 = [20 20 255];
c4 = [0 0 128];
I would venture to guess that c1, c3, and c4 are all "blue" enough, while c2 is certainly not what you are looking for. Think of the color of a pixel being a vector in a 3 dimensional space. What you want to do is find the angle of the color vector of the pixel to the color vector of the ideal by using the dot product.
For example:
blue = [0 0 255];
pixel = [10 10 200];
ang_thres = 25; % degrees. You should change this to suit your needs
ang = acosd(dot(blue/norm(blue),pixel/norm(pixel)));
isBlue = ang <= ang_thres; % Apply angle threshold
You might also want to apply a magnitude threshold (i.e. is the pixel dark enough). This would filter out any really faint colors (i.e. [0 0 1]);
For example:
blue = [0 0 255];
pixel = [10 10 200];
ang_thres = 25; % degrees. You should change this to suit your needs
ang = acosd(dot(blue/norm(blue),pixel/norm(pixel)));
mag_thres = 64; % You should change this to suit your needs
mag = norm(pixel);
isBlue = ang <= ang_thres & mag >= mag_thres; % Apply both thresholds
Hope this helps!
2 comentarios
Jonathan Sullivan
el 9 de En. de 2012
I'm not too familiar with Simulink, but this is how it would be done in MATLAB. I hope you can find a solution that suites your needs.
Ver también
Categorías
Más información sobre Color Space Formatting and Conversions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!