HSI Colorroom Convert to RGB or the other way around

are the Way to Convert HSI to RGB ( RGB to HSI )

Have fun with the procedures.
We developed them so that they are neither available in VB nor in Xojo.
You can find more information about the explanation in Wikipedia or in special industrial information.

Sub HSI_to_RGB( byref Hue as double , byref Saturation as double, byref Intensity as double, Transform as Boolean ) as Color

Dim Dh, H, Ds, S, Di, I, xx, yy, zz, R, G, B, tm1, tm2 As Double
Dim RM , GM , BM , RGB_Summe as Double
dim rr, gg, bb, ur as double
Dim HSIColor as Color
'Const pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899

'Beispielaufruf:
'Die Farbe, die sich aus dem HSI-XQ der Liste ergibt
'call HSI_to_RGB(mittelwert_H,mittelwert_S,mittelwert_I, True) 'Aufruf mit 2D-Transformation

H = Hue
S = Saturation
I = Intensity

'Erklärung
'Die gewünschten Werte werden durch Hue (Farbwert), Saturation (Sättigung) und Intensity (Intensität) festgelegt.
’ Die Umrechnung von HSI nach RGB erfolgt mit der Formel:
Dh = H * pi / 180
Ds = S / 255 '100 oder '255
Di = I / 255

If H > 120 And H <= 240 Then
Dh = 2 * pi / 3
ElseIf H > 240 And H <= 360 Then
Dh = -4 * pi / 3
end if

xx = Di * (1 - Ds)
tm1 = Ds *Cos(Dh)
tm2 = Cos(pi / 3 - Dh)
yy = Di * (1 + tm1 / tm2)
zz = 3 * Di - (xx + yy)

if H <= 120 Then
R = yy
G = zz
B = xx

ElseIf H > 120 And H <= 240 Then
R = xx
G = yy
B = zz

ElseIf H > 240 And H <= 360 Then
R = zz
G = xx
B = yy
End If

if xRayView.HSITransform.Value = True then
'Ausgabe der Mischfarbe / resutierenden Farbe
'Mischfarbe berechnen
'Additive Farbmischung
RM= ( R * 255 )
GM= ( G * 255 )
BM= ( B * 255 )

'2D-Transformation zur Ermittelung der resultierenden Mischfarbe
'r+g+b=1 (Anteil: 0,333) r=R / (R+G+B) ; g=G / (R+G+B) ; b=B / (R+G+B)
RGB_Summe = RM + GM + BM
rr = RM / RGB_Summe
gg = GM / RGB_Summe
bb = BM / RGB_Summe
end if

'Primärfarben:
'Rot R =(1,0,0)
'GrĂĽn G=(0,1,0)
'Blau B = (0,0,1)

'Mischfarben F berechnen sich nach der Formel:
'F=aR+bG+c*B ,0<= a,b,c<= 1
'MF = rr * RM + gg * GM + bb * BM

'Ausgabe wie korrekt (Jetzt anders berechnet)
'Mit oder ohne 2D Transformation

if xRayView.HSITransform.Value = True then
'mit 2D-Transformation
HSIColor = Color.RGB( rr * 255 , gg * 255, bb * 255 )
else
'ohne 2D Transformation
HSIColor = Color.RGB( R * 255, G * 255, B * 255)
end if

'Ăśbergabe
Return HSIColor

end sub

or / oder

Sub RGB_To_HSI_Lite ( ByRef HSI_H as double, ByRef HSI_S as double, ByRef HSI_I as double, R as Double, G as Double, B as double )

// Leicht vereinfachte Funktion. Etwas weniger Parameter
// U. Scharte © Germany
// Wenn eine Prozedur mit Call aufgrufen wird kann auch eine Variable darĂĽber zurĂĽckgelesen werden
// Nur ein Tip 03-2021
// Falls es nicht klappt Die Variablen HSI_H und HSI_S und HSI_I einfach global anlegen un damit ĂĽbergeben z.B. als HSI_H_Wert , HSI_S_Wert , HSI_I_Wert

'RGB auf HSI-Umrechnung
'Variablen fĂĽr die HSI-Umrechnung
’ const pi=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899

'Aufuf: 'Normal RGB to HSI-Farbraum berechnen
'Beispiel / Sample :
'Call RGB_To_HSI(HSI_H ,HSI_S ,HSI_I ,c.red,c.green,c.blue, HSI_HG, HSI_SG , HSI_IG)

// or in Lite:

'Ausgabevariablen fĂĽr HSI-Farbraum
'dim HSI_H as double
'dim HSI_S as double
'dim HSI_I as double

Dim tm1, tm2, h, ds, di As Double
Dim Rs, Gs, Bs, S As Double
Dim Minimum As double
dim ur as double

'S = c.red + c.green + c.blue
S = R + G + B
Rs = R / S
Gs = G / S
Bs = B / S

tm1 = 0.5 * (2 * Rs - Gs - Bs)
tm2 = ((Rs - Gs) ^ 2 + (Rs - Bs) * (Gs - Bs)) ^ 0.5
If Bs <= Gs Then
h = Acos(tm1 / tm2)
ElseIf Bs > Gs Then
h = 2 * pi - Acos(tm1 / tm2)
End If
If tm2 < 0.01 And tm2 > -0.01 Then h = 0

HSI_H = h * 180 / pi

'-------------
'25.09.2014 integriert (Erprobung)
if HSI_H = 0 then
'Immer 360° Farbraum beachten
HSI_H = 360
end if

'Auf den Graukeil bezogenen HUE-Wert fĂĽr die AOI berechnen und ausgeben sowie ĂĽbergeben
ur = 360 / 255
'ur = 1 'nicht umrechnen bei 360° bleiben

'In 255 umgerechnet darstellen
di = ( R * 255 + G * 255 + B * 255 ) / 3
'di = (R 360 + G360 + B*360) / 3
HSI_I = (di * ur) / 255 'RGB 255
'HSI_I = (di * ur) / 360 '360° HSI

ds = 1 - ( 3 / (R+G+B)) * min( R, G, B)
'ds = 1 - ( 3 * min(R, G, B ) / S )
'360° Farbraum
HSI_S = ds * 100

'Korrektur, wenn -1 im Ergebnis
if HSI_H = -1 Then
HSI_H = 360
HSI_S = 360
HSI_I = 360
end if

'360° Farbraum auf Graukeil 0-255 bezogen
'Window1.HSI_SG.Text = Format(ds * 255, “0.000000”)

'Window1.HSI_HG.Text = Format((h * 180 / pi)/ur, “0.000000”)
'HSI_HG = Format((h * 180 / pi) / ur , “0.000000”)

'Auf den Graukeil bezogenen Sättigungswert für die AOI berechnen und ausgeben sowie übergeben
'Window1.HSI_SG.Text = Format((ds *255) * ur, “0.000000”)
'HSI_SG = Format((ds * 100) * ur, “0.000000”)
'HSI_SG = Format((ds * 255) * ur, “0.000000”)
'HSI_SG = Format(((ds * 100) * 3.6) / ur, “0.000000”) '360°

'Auf den Graukeil bezogenen Intenstätswert für die AOI berechnen und ausgeben sowie übergeben
'Window1.HSI_IG.text = Format((di * ur ) / 255 , “0.000000”)
'HSI_IG = Format((di * 255) / ur, “0.000000”)
'HSI_IG = HSI_I

'Korrektur, wenn -1 im Ergebnis
'if instr ( HSI_HG , “-1” ) > 0 Then
'HSI_HG = “255”
'HSI_SG = “255”
'HSI_IG = “255”
'end if

end sub

Viel SpaĂź mit den Prozeduren. Wir haben sie entwickelt, das es sie weder in VB noch in Xojo gibt.
Näheres zur Erklärung findet ihr in Wikipedia oder in speziellen industrieellen Informationen.

Interesting, thanks!
In what way are the results different to reading the HSV values of a color / using Color.HSV?

HSL is a different colour model to HSV

In German:

  • Die Farbräume HSL, HSV und HSI berĂĽcksichtigen in Ihren unterschiedlichen Farbräumen
    die menschlich Wahrnehmung des Auges. Gehen auch sehr gut auf das 3D-Empfinden ein. Das alles kann RGB nicht. Deshalb werden sie in der Inspectionstechnik, Polizei gern fĂĽr Farb- und Bildanalysen verwendet.
    Ein wichtiger Unterschied z.B. HSL, HSB, HSV, HSI ist: HLS mit der relativen Helligkeit (lightness) statt des Hellwertes In einem HSB mit der absoluten Helligkeit( Brightness) In einem HSI mit der Lichtintensität (intensity) und dem HSV mit dem Wert (Value) der Helligkeit. RGB ist in der Test und analytischen Arbeit nicht so gut geeignet. Es ist für uns nur ein Vergleich.

In German:

  • The color spaces HSL, HSV and HSI take into account in your different color spaces
    the human perception of the eye. Also respond very well to the 3D sensation. RGB can’t do all of this. That’s why they are often used in information technology, police for color and image analysis.
    An important difference is e.B. HSL, HSB, HSV, HSI: HLS with the relative brightness (lightness) instead of the brightness value In an HSB with the absolute brightness (brightness) In an HSI with the light intensity (intensity) and the HSV with the value of the brightness. RGB is not as well suited in testing and analytical work. It’s just a comparison for us.
1 Like