Shop OBEX P1 Docs P2 Docs Learn Events
Color matching "minimax" — Parallax Forums

Color matching "minimax"

VicVic Posts: 2
edited 2004-11-23 19:01 in BASIC Stamp
Hello,

I am trying to find a color matching one of 8 preset colors using a BS 2, BOE and TAOS Color Sensor, similar to the M&M Sorter...
The pdf article which comes with the example color matching program at the Parallax software CD-ROM mentions a "minimax" value. Calculating such a value seems quite easy, as well as retrieving the color which has the smallest color minimax.

However my script seems unable to see the difference between, for example, purple and red, and green and blue. So I must be doing something wrong rolleyes.gif

I use the following line of code to calculate the minimax value:
Color_Diff = ( ABS ( Input_Red - Red_Value) ) + ( ABS ( Input_Green - Green_Value ) ) + ( ABS ( Input_Blue - Blue_Value ) )

Input_Red, Input_Green and Input_Blue are the color values which are read from the color sensor, and Red_Value, Green_Value and Blue_Value are the variables containing the RGB values of the stored color.

Am I calculating the minimax value the correct way?

Thanks,
Vic




·

Comments

  • VicVic Posts: 2
    edited 2004-11-23 19:01
    Never mind - replacing the line I was using with the follow block of code did the trick smile.gif

    Color_Diff_Red = ABS ( Input_Red - Red_Value )
    Color_Diff_Green = ABS ( Input_Green - Green_Value )
    Color_Diff_Blue = ABS ( Input_Blue - Blue_Value )

    Color_Diff = 0

    if ( Color_Diff_Red > Color_Diff ) then
    Color_Diff = Color_Diff_Red
    endif

    if ( Color_Diff_Green > Color_Diff ) then
    Color_Diff = Color_Diff_Green
    endif

    if ( Color_Diff_Blue > Color_Diff ) then
    Color_Diff = Color_Diff_Blue
    endif


    Vic
Sign In or Register to comment.