I find the dominant colors in a picture with the help of the codes below.
> Public Class baskinrenkler
>
> Public Items As New Collection
>
> Public Sub AddItem(ByVal R As Integer, ByVal G As Integer, ByVal B As Integer, ByVal Count As Single)
> If (R = 0 And G = 0 And B = 0) Or (R >= 25 And G >= 25 And B >= 25) Then
> Exit Sub
> End If
> For Each i As RGBItem In Items
> If i.R = R And i.G = G And i.B = B Then
> i.Count += Count
> Exit Sub
> End If
> Next
> Dim i2 As New RGBItem(R, G, B, Count)
> Items.Add(i2)
> End Sub
>
> Public Function GetDominantColor(ByVal Image As Bitmap) As Color
> If Image Is Nothing Then
> Return Color.White
> End If
> For i As Integer = 0 To Image.Width - 1
> For j As Integer = 0 To Image.Height - 1
> Dim c As Color = Image.GetPixel(i, j)
> If c.A = 255 Then
> AddItem(c.R / 10, c.G / 10, c.B / 10, c.A / 255)
> End If
> Next
> Next
> If Items.Count = 0 Then
> Return Color.White
> End If
> Dim Dominant As RGBItem = Items(1)
> For Each i As RGBItem In Items
> If i.Count > Dominant.Count Then
> Dominant = i
> End If
> Next
> Return Dominant.ReturnColor
> End Function End Class
>
>
> Public Class RGBItem
> Public R As Integer
> Public G As Integer
> Public B As Integer
>
> Public Count As Single = 0
>
> Public Sub New(ByVal R1 As Integer, ByVal G1 As Integer, ByVal B1 As Integer, ByVal Count1 As Single)
> R = R1
> G = G1
> B = B1
> Count = Count1
> End Sub
>
> Public Function ReturnColor() As Color
> Dim R1 As Integer = 10 * R
> Dim G1 As Integer = 10 * G
> Dim B1 As Integer = 10 * B
> If R1 > 255 Then
> R1 = 255
> End If
> If G1 > 255 Then
> G1 = 255
> End If
> If B1 > 255 Then
> B1 = 255
> End If
> Return Color.FromArgb(R1, G1, B1)
> End Function
End Class
my first question:
I want to increase the number of dominant colors to 3
as in the link below
https://www.imgonline.com.ua/eng/get-dominant-colors.php
my second question:
I'll create the palette like the one below and round every color I find to the appropriate color in this palette. Like this
and these codes must be in vb I'm using vs2010.
how can I do that?. Thank you in advance for your help
*