HSB vs HSI anyone have HSB fornular?
Author Message
HSB vs HSI anyone have HSB fornular?

I have the formulas for HSI - arccos(...) and all

I understand the HSB that Photoshop uses differs only in the formula for
Brightness compared to that for Intensity.

I have that I=(B+G+R)/3

Anyone know what the formula for B is?

Or where on the internet I can find it?

I found a couple of places that gave the HSI formula but no HSB formula.

Thanks,
Cal

Mon, 17 Jan 2005 00:02:03 GMT
HSB vs HSI anyone have HSB fornular?
I don't know what photoshop uses, but a very common formula for B is

(76 * R  + 150 * G  + 28 * B)  / 255

I've seen many small variations on this.  To normalize to the 0 - 240
range change / 255 to * 240 / 255 / 255 or equivalent.

Jim Deutch
MS Dev MVP

Quote:
>I have the formulas for HSI - arccos(...) and all

>I understand the HSB that Photoshop uses differs only in the formula for
>Brightness compared to that for Intensity.

>I have that I=(B+G+R)/3

>Anyone know what the formula for B is?

>Or where on the internet I can find it?

>I found a couple of places that gave the HSI formula but no HSB formula.

>Thanks,
>Cal

Mon, 17 Jan 2005 04:52:34 GMT
HSB vs HSI anyone have HSB fornular?
The more I look the more confused the picture becomes.

I found fornula for HSI in a few places - They use arccos and sin

I found code for HSL in a few places - They do not use trig functions. Do
these give the same value for H and S as does HSI (except maybe for a
normalize factor)?

Then there is HSB used by Photoshop for which I can find neither code nor
definitions.

So - are they all the same except for the Brightness/Intensity/Luminisoty
formula and maybe a normalize factor to make the maxs 100, 240 or 360?

Quote:
> I don't know what photoshop uses, but a very common formula for B is

> (76 * R  + 150 * G  + 28 * B)  / 255

> I've seen many small variations on this.  To normalize to the 0 - 240
> range change / 255 to * 240 / 255 / 255 or equivalent.

> Jim Deutch
> MS Dev MVP

Thanks a lot. Do you know if the formulas for H and S is the same as for HSI
and/or HSL?

Cal

Mon, 17 Jan 2005 21:39:47 GMT
HSB vs HSI anyone have HSB fornular?
Those are all good questions, but I don't have good answers....

I have code for a RGB <--> HSL translation that nearly matches the one
built into the Windows color picker (it's off by one or two in some
spots), as well as for CMYK.  As far as I know, HSB = HSL and I've
never heard of HSI before.

Jim Deutch
MS Dev MVP

Quote:
>The more I look the more confused the picture becomes.

>I found fornula for HSI in a few places - They use arccos and sin

>I found code for HSL in a few places - They do not use trig functions. Do
>these give the same value for H and S as does HSI (except maybe for a
>normalize factor)?

>Then there is HSB used by Photoshop for which I can find neither code nor
>definitions.

>So - are they all the same except for the Brightness/Intensity/Luminisoty
>formula and maybe a normalize factor to make the maxs 100, 240 or 360?

>> I don't know what photoshop uses, but a very common formula for B is

>> (76 * R  + 150 * G  + 28 * B)  / 255

>> I've seen many small variations on this.  To normalize to the 0 - 240
>> range change / 255 to * 240 / 255 / 255 or equivalent.

>> Jim Deutch
>> MS Dev MVP

>Thanks a lot. Do you know if the formulas for H and S is the same as for HSI
>and/or HSL?

>Cal

Tue, 18 Jan 2005 00:27:55 GMT
HSB vs HSI anyone have HSB fornular?

Quote:
> Those are all good questions, but I don't have good answers....

> I have code for a RGB <--> HSL translation that nearly matches the one
> built into the Windows color picker (it's off by one or two in some
> spots), as well as for CMYK.  As far as I know, HSB = HSL

I found code for HSL in a few places but the results of the one I checked
does not match Photoshop's HSB

Quote:
>and I've  never heard of HSI before.

I  may have found HSI at Physics sites.
I=(R+G+B)/3
Hue varies 0 to 360 and uses trig functions that probably make it too slow
for programming.
S=1 - min(R,G,B)/I

It's the only one I found a definition for.
For HSL I found code but no definition - hard to determine that they all
implement the same rules.

Thanks,
Cal

Quote:

> Jim Deutch
> MS Dev MVP

> >The more I look the more confused the picture becomes.

> >I found fornula for HSI in a few places - They use arccos and sin

> >I found code for HSL in a few places - They do not use trig functions. Do
> >these give the same value for H and S as does HSI (except maybe for a
> >normalize factor)?

> >Then there is HSB used by Photoshop for which I can find neither code nor
> >definitions.

> >So - are they all the same except for the Brightness/Intensity/Luminisoty
> >formula and maybe a normalize factor to make the maxs 100, 240 or 360?

> >> I don't know what photoshop uses, but a very common formula for B is

> >> (76 * R  + 150 * G  + 28 * B)  / 255

> >> I've seen many small variations on this.  To normalize to the 0 - 240
> >> range change / 255 to * 240 / 255 / 255 or equivalent.

> >> Jim Deutch
> >> MS Dev MVP

> >Thanks a lot. Do you know if the formulas for H and S is the same as for
HSI
> >and/or HSL?

> >Cal

Tue, 18 Jan 2005 05:01:24 GMT
HSB vs HSI anyone have HSB fornular?
Hi!

I did this convertions before. There are many similar algorithms on
the net that do this Photoshop HSB2RGB convertion. A very fast one can
be found at www.xbeat.net/vbspeed (currently down :-( )

Here's the code for a module:

Public Type HSL
Hue         As Long
Saturation  As Long
Luminance   As Long
End Type

Public Function HSLToRGB( _
ByVal Hue As Long, _
ByVal Saturation As Long, _
ByVal Luminance As Long) As Long

Dim r As Long, G As Long, B As Long
Dim lMax As Long, lMid As Long, lMin As Long
Dim q As Single

lMax = (Luminance * 255) / 100
lMin = (100 - Saturation) * lMax / 100
q = (lMax - lMin) / 60

Select Case Hue
Case 0 To 60
lMid = (Hue - 0) * q + lMin
r = lMax
G = lMid
B = lMin
Case 60 To 120
lMid = -(Hue - 120) * q + lMin
r = lMid
G = lMax
B = lMin
Case 120 To 180
lMid = (Hue - 120) * q + lMin
r = lMin
G = lMax
B = lMid
Case 180 To 240
lMid = -(Hue - 240) * q + lMin
r = lMin
G = lMid
B = lMax
Case 240 To 300
lMid = (Hue - 240) * q + lMin
r = lMid
G = lMin
B = lMax
Case 300 To 360
lMid = -(Hue - 360) * q + lMin
r = lMax
G = lMin
B = lMid
End Select

HSLToRGB = B * &H10000 + G * &H100& + r

End Function

Public Function RGBToHSL(ByVal RGBValue As Long) As HSL

Dim r As Long, G As Long, B As Long
Dim lMax As Long, lMin As Long
Dim q As Single
Dim lDifference As Long
Static Lum(255) As Long
Static QTab(255) As Single
Static init As Long

If init = 0 Then
For init = 2 To 255 ' 0 and 1 are both 0
Lum(init) = init * 100 / 255
Next
For init = 1 To 255
QTab(init) = 60 / init
Next init
End If

r = RGBValue And &HFF
G = (RGBValue And &HFF00&) \ &H100&
B = (RGBValue And &HFF0000) \ &H10000

If r > G Then
lMax = r
lMin = G
Else
lMax = G
lMin = r
End If
If B > lMax Then
lMax = B
ElseIf B < lMin Then
lMin = B
End If

RGBToHSL.Luminance = Lum(lMax)

lDifference = lMax - lMin
If lDifference Then
' do a 65K 2D lookup table here for more speed if needed
RGBToHSL.Saturation = (lDifference) * 100 / lMax
q = QTab(lDifference)
Select Case lMax
Case r
If B > G Then
RGBToHSL.Hue = q * (G - B) + 360
Else
RGBToHSL.Hue = q * (G - B)
End If
Case G
RGBToHSL.Hue = q * (B - r) + 120
Case B
RGBToHSL.Hue = q * (r - G) + 240
End Select
End If
End Function

---------------------------------------------------------

It's a bit confusing in the name of that colorspace. In some
applications it is called HSB, in others HSV, HSI or something else.
Important is the way it mixes the saturation and brightness. In
Windows-Way (I call it HSV *grin*) a red color is made by a Hue of 0,
a Saturation of 100% and a Brightness of 50%. In Photoshop the
Saturation and Brightness are both 100%.

Test the code please. It should be that you're looking for (hope so)

Greetings,
Benjamin Wilger

PS: If you speak german, look under www.activevb.de/vb/ for my
colorpicker application ccPicker in the project-section
(Rubriken->Projekte->ccPicker)!

Thu, 20 Jan 2005 10:26:09 GMT
HSB vs HSI anyone have HSB fornular?

Fri, 19 Jun 1992 00:00:00 GMT
HSB vs HSI anyone have HSB fornular?
I've tried a few but the ones I've tried do not agree with Photoshop nor
windows so I'm hoping to learn the definitions used by those applications. I
believe HSV, HSI, HSB,HSL,HSl... refer to slightly different definitions
(although a couple of the names may refer to the same definition.)

I'll try the one you sent see if it agrees with Photshop or Windows.

Thanks a lot.
Cal

Quote:
> Hi!

> I did this convertions before. There are many similar algorithms on
> the net that do this Photoshop HSB2RGB convertion. A very fast one can
> be found at www.xbeat.net/vbspeed (currently down :-( )

> Here's the code for a module:

> Public Type HSL
>     Hue         As Long
>     Saturation  As Long
>     Luminance   As Long
> End Type

> Public Function HSLToRGB( _
>             ByVal Hue As Long, _
>             ByVal Saturation As Long, _
>             ByVal Luminance As Long) As Long

>     Dim r As Long, G As Long, B As Long
>     Dim lMax As Long, lMid As Long, lMin As Long
>     Dim q As Single

>     lMax = (Luminance * 255) / 100
>     lMin = (100 - Saturation) * lMax / 100
>     q = (lMax - lMin) / 60

>     Select Case Hue
>         Case 0 To 60
>             lMid = (Hue - 0) * q + lMin
>             r = lMax
>             G = lMid
>             B = lMin
>         Case 60 To 120
>             lMid = -(Hue - 120) * q + lMin
>             r = lMid
>             G = lMax
>             B = lMin
>         Case 120 To 180
>             lMid = (Hue - 120) * q + lMin
>             r = lMin
>             G = lMax
>             B = lMid
>         Case 180 To 240
>             lMid = -(Hue - 240) * q + lMin
>             r = lMin
>             G = lMid
>             B = lMax
>         Case 240 To 300
>             lMid = (Hue - 240) * q + lMin
>             r = lMid
>             G = lMin
>             B = lMax
>         Case 300 To 360
>             lMid = -(Hue - 360) * q + lMin
>             r = lMax
>             G = lMin
>             B = lMid
>     End Select

>     HSLToRGB = B * &H10000 + G * &H100& + r

> End Function

> Public Function RGBToHSL(ByVal RGBValue As Long) As HSL

>     Dim r As Long, G As Long, B As Long
>     Dim lMax As Long, lMin As Long
>     Dim q As Single
>     Dim lDifference As Long
>     Static Lum(255) As Long
>     Static QTab(255) As Single
>     Static init As Long

>     If init = 0 Then
>         For init = 2 To 255 ' 0 and 1 are both 0
>             Lum(init) = init * 100 / 255
>         Next
>         For init = 1 To 255
>             QTab(init) = 60 / init
>         Next init
>     End If

>     r = RGBValue And &HFF
>     G = (RGBValue And &HFF00&) \ &H100&
>     B = (RGBValue And &HFF0000) \ &H10000

>     If r > G Then
>         lMax = r
>         lMin = G
>     Else
>         lMax = G
>         lMin = r
>     End If
>     If B > lMax Then
>         lMax = B
>     ElseIf B < lMin Then
>         lMin = B
>     End If

>     RGBToHSL.Luminance = Lum(lMax)

>     lDifference = lMax - lMin
>     If lDifference Then
>         ' do a 65K 2D lookup table here for more speed if needed
>         RGBToHSL.Saturation = (lDifference) * 100 / lMax
>         q = QTab(lDifference)
>         Select Case lMax
>             Case r
>                 If B > G Then
>                     RGBToHSL.Hue = q * (G - B) + 360
>                 Else
>                     RGBToHSL.Hue = q * (G - B)
>                 End If
>             Case G
>                 RGBToHSL.Hue = q * (B - r) + 120
>             Case B
>                 RGBToHSL.Hue = q * (r - G) + 240
>         End Select
>     End If
> End Function

> ---------------------------------------------------------

> It's a bit confusing in the name of that colorspace. In some
> applications it is called HSB, in others HSV, HSI or something else.
> Important is the way it mixes the saturation and brightness. In
> Windows-Way (I call it HSV *grin*) a red color is made by a Hue of 0,
> a Saturation of 100% and a Brightness of 50%. In Photoshop the
> Saturation and Brightness are both 100%.

> Test the code please. It should be that you're looking for (hope so)

> Greetings,
> Benjamin Wilger

> PS: If you speak german, look under www.activevb.de/vb/ for my
> colorpicker application ccPicker in the project-section
> (Rubriken->Projekte->ccPicker)!

Fri, 21 Jan 2005 02:15:36 GMT
HSB vs HSI anyone have HSB fornular?

Fri, 19 Jun 1992 00:00:00 GMT
HSB vs HSI anyone have HSB fornular?
You are correct - the definitions vary.

In Windows S and L depend on max(R,G,B) and min(R,G,B) the other color is
not used (except for H)

In the code you sent me S depends on the other color (as I think it should
since that color indicates how much white is included)

Thanks,
Cal

Quote:
> Hi!

> I did this convertions before. There are many similar algorithms on
> the net that do this Photoshop HSB2RGB convertion. A very fast one can
> be found at www.xbeat.net/vbspeed (currently down :-( )

> Here's the code for a module:

> Public Type HSL
>     Hue         As Long
>     Saturation  As Long
>     Luminance   As Long
> End Type

> Public Function HSLToRGB( _
>             ByVal Hue As Long, _
>             ByVal Saturation As Long, _
>             ByVal Luminance As Long) As Long

>     Dim r As Long, G As Long, B As Long
>     Dim lMax As Long, lMid As Long, lMin As Long
>     Dim q As Single

>     lMax = (Luminance * 255) / 100
>     lMin = (100 - Saturation) * lMax / 100
>     q = (lMax - lMin) / 60

>     Select Case Hue
>         Case 0 To 60
>             lMid = (Hue - 0) * q + lMin
>             r = lMax
>             G = lMid
>             B = lMin
>         Case 60 To 120
>             lMid = -(Hue - 120) * q + lMin
>             r = lMid
>             G = lMax
>             B = lMin
>         Case 120 To 180
>             lMid = (Hue - 120) * q + lMin
>             r = lMin
>             G = lMax
>             B = lMid
>         Case 180 To 240
>             lMid = -(Hue - 240) * q + lMin
>             r = lMin
>             G = lMid
>             B = lMax
>         Case 240 To 300
>             lMid = (Hue - 240) * q + lMin
>             r = lMid
>             G = lMin
>             B = lMax
>         Case 300 To 360
>             lMid = -(Hue - 360) * q + lMin
>             r = lMax
>             G = lMin
>             B = lMid
>     End Select

>     HSLToRGB = B * &H10000 + G * &H100& + r

> End Function

> Public Function RGBToHSL(ByVal RGBValue As Long) As HSL

>     Dim r As Long, G As Long, B As Long
>     Dim lMax As Long, lMin As Long
>     Dim q As Single
>     Dim lDifference As Long
>     Static Lum(255) As Long
>     Static QTab(255) As Single
>     Static init As Long

>     If init = 0 Then
>         For init = 2 To 255 ' 0 and 1 are both 0
>             Lum(init) = init * 100 / 255
>         Next
>         For init = 1 To 255
>             QTab(init) = 60 / init
>         Next init
>     End If

>     r = RGBValue And &HFF
>     G = (RGBValue And &HFF00&) \ &H100&
>     B = (RGBValue And &HFF0000) \ &H10000

>     If r > G Then
>         lMax = r
>         lMin = G
>     Else
>         lMax = G
>         lMin = r
>     End If
>     If B > lMax Then
>         lMax = B
>     ElseIf B < lMin Then
>         lMin = B
>     End If

>     RGBToHSL.Luminance = Lum(lMax)

>     lDifference = lMax - lMin
>     If lDifference Then
>         ' do a 65K 2D lookup table here for more speed if needed
>         RGBToHSL.Saturation = (lDifference) * 100 / lMax
>         q = QTab(lDifference)
>         Select Case lMax
>             Case r
>                 If B > G Then
>                     RGBToHSL.Hue = q * (G - B) + 360
>                 Else
>                     RGBToHSL.Hue = q * (G - B)
>                 End If
>             Case G
>                 RGBToHSL.Hue = q * (B - r) + 120
>             Case B
>                 RGBToHSL.Hue = q * (r - G) + 240
>         End Select
>     End If
> End Function

> ---------------------------------------------------------

> It's a bit confusing in the name of that colorspace. In some
> applications it is called HSB, in others HSV, HSI or something else.
> Important is the way it mixes the saturation and brightness. In
> Windows-Way (I call it HSV *grin*) a red color is made by a Hue of 0,
> a Saturation of 100% and a Brightness of 50%. In Photoshop the
> Saturation and Brightness are both 100%.

> Test the code please. It should be that you're looking for (hope so)

> Greetings,
> Benjamin Wilger

> PS: If you speak german, look under www.activevb.de/vb/ for my
> colorpicker application ccPicker in the project-section
> (Rubriken->Projekte->ccPicker)!

Sat, 22 Jan 2005 04:05:33 GMT

 Page 1 of 1 [ 10 post ]

Relevant Pages