How do i threshold blue colors in Simulink?

3 views (last 30 days)
Erçin
Erçin on 6 Jan 2012
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...

Answers (3)

Walter Roberson
Walter Roberson on 6 Jan 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.
  2 Comments
Erçin
Erçin on 6 Jan 2012
I need (0,0,X). X must be defineable by me. Ex: (0,0,200)
Erçin
Erçin on 6 Jan 2012
Setting with Autothreshold block? I don't understand Autotreshold block settings.

Sign in to comment.


Erçin
Erçin on 6 Jan 2012
Red and Green isn't important for me cause of seperating signals and working on blue only. After the thresholding i will process with that blue image.
  1 Comment
Erçin
Erçin on 6 Jan 2012
I need high blue is 1, low blue is 0 threshold. It means converting image to BW image.

Sign in to comment.


Jonathan Sullivan
Jonathan Sullivan on 6 Jan 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 Comments
Erçin
Erçin on 6 Jan 2012
I had thought similar algorithms but my purpose is doing it with Simulink. Because i will process a video in a physic system and need speed to. So needed embedded functions. Thank you by the way...
Jonathan Sullivan
Jonathan Sullivan on 9 Jan 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.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!