Results 1 to 4 of 4

Thread: Imaging - RGB colours need help comparing ....

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Imaging - RGB colours need help comparing ....

    im running the following code below to replace colours .... the code works fine but i need a way to break down RGB values to calculate if the colour is roughly in the same range as the image .... how can i do this

    any help would be great
    many thanks
    illskills


    VB Code:
    1. Dim mycc As New ColorConverter
    2.         pgbProgress.Maximum = 256
    3.         For iColour As Integer = 0 To 255
    4.  
    5.             pgbProgress.Value = iColour
    6.             pgbProgress.Refresh()
    7.             If Not IsNothing(arrColoursToReplace(iColour)) Then
    8.                 For i As Integer = 1 To 1000 '# loops throught mosaics
    9.                     If IsNothing(arrCustomMosaics(i, 0, 0)) Then Exit For
    10.                     For x As Integer = 1 To 15
    11.                         For y As Integer = 1 To 15
    12.                             If Not IsNothing(arrCustomMosaics(i, x, y)) Then
    13.                                 If mycc.ConvertToString(arrCustomMosaics(i, x, y).ToString) = mycc.ConvertToString(arrColoursToReplace(iColour).ToString) Then
    14.                                     arrColoursToReplace(iColour) = arrCustomMosaics(i, 0, 0)
    15.                                 End If
    16.                             End If
    17.                         Next
    18.                     Next
    19.                 Next
    20.             End If
    21.         Next
    22.         For i As Integer = 1 To 255
    23.             If Not IsNothing(arrColoursToReplace(i)) Then
    24.                 txtmytextbox.Text = txtmytextbox.Text & vbCrLf & arrColoursToReplace(i).tostring
    25.             End If
    26.         Next

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Location
    UK
    Posts
    127

    Re: Imaging - RGB colours need help comparing ....

    ... this code looks for an exact match

  3. #3
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Imaging - RGB colours need help comparing ....

    Here is code that Si da Greek wrote
    VB Code:
    1. Private Function ColourLongToWords(ByVal lColour As Long) As String
    2. 'Converts an RGB colour number to a string equivalent
    3. 'By Si_the_geek, VBForums
    4.  
    5.     'ensure value is within range for colours
    6.   lColour = lColour And &HFFFFFF
    7.  
    8.     'convert to separate RGB values
    9. Dim iRed As Integer, iGreen As Integer, iBlue As Integer
    10.   iRed = lColour And &HFF
    11.   iGreen = (lColour \ &H100) And &HFF
    12.   iBlue = lColour \ &H10000
    13.  
    14.     '"guess" the colour based on these values
    15. Dim sColourName As String
    16.   Select Case iRed
    17.   Case Is > 170     'lots of red
    18.       Select Case iGreen
    19.       Case Is > 170     'lots of green
    20.           Select Case iBlue  'blue:  lots/medium/little
    21.           Case Is > 170:  sColourName = "White"
    22.           Case Is > 85:   sColourName = "Bright Yellow"
    23.           Case Else:      sColourName = "Yellow"
    24.           End Select
    25.       Case Is > 85      'medium green
    26.           Select Case iBlue  'blue:  lots/medium/little
    27.           Case Is > 170:  sColourName = "Pink"
    28.           Case Is > 85:   sColourName = "Magenta"
    29.           Case Else:      sColourName = "Orange"
    30.           End Select
    31.       Case Else         'little green
    32.           Select Case iBlue  'blue:  lots/medium/little
    33.           Case Is > 170:  sColourName = "Purple"
    34.           Case Is > 85:   sColourName = "Dark Pink"
    35.           Case Else:      sColourName = "Red"
    36.           End Select
    37.       End Select
    38.  
    39.   Case Is > 85      'medium red
    40.       Select Case iGreen
    41.       Case Is > 170     'lots of green
    42.           Select Case iBlue  'blue:  lots/medium/little
    43.           Case Is > 170:  sColourName = "Cyan"
    44.           Case Is > 85:   sColourName = "Green"
    45.           Case Else:      sColourName = "Bright Green"
    46.           End Select
    47.       Case Is > 85      'medium green
    48.           Select Case iBlue  'blue:  lots/medium/little
    49.           Case Is > 170:  sColourName = "Dark Blue"
    50.           Case Is > 85:   sColourName = "Dark Grey"
    51.           Case Else:      sColourName = "Dark Green"
    52.           End Select
    53.       Case Else         'little green
    54.           Select Case iBlue  'blue:  lots/medium/little
    55.           Case Is > 170:  sColourName = "Dark Blue"
    56.           Case Is > 85:   sColourName = "Purple"
    57.           Case Else:      sColourName = "Dark Red"
    58.           End Select
    59.       End Select
    60.  
    61.   Case Else         'little red
    62.       Select Case iGreen
    63.       Case Is > 170     'lots of green
    64.           Select Case iBlue  'blue:  lots/medium/little
    65.           Case Is > 170:  sColourName = "Cyan"
    66.           Case Is > 85:   sColourName = "Green"
    67.           Case Else:      sColourName = "Bright Green"
    68.           End Select
    69.       Case Is > 85      'medium green
    70.           Select Case iBlue  'blue:  lots/medium/little
    71.           Case Is > 170:  sColourName = "Blue"
    72.           Case Is > 85:   sColourName = "Dark Cyan"
    73.           Case Else:      sColourName = "Dark Green"
    74.           End Select
    75.       Case Else         'little green
    76.           Select Case iBlue  'blue:  lots/medium/little
    77.           Case Is > 170:  sColourName = "Bright Blue"
    78.           Case Is > 85:   sColourName = "Dark Blue"
    79.           Case Else:      sColourName = "Black"
    80.           End Select
    81.       End Select
    82.    End Select
    83.  
    84.   ColourLongToWords = sColourName
    85.  
    86. End Function
    from this thread
    http://www.vbforums.com/showthread.php?t=366584

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Imaging - RGB colours need help comparing ....

    beat me to it!

    By the way, there's no R in geek

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width