HSB Stack Conversion

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

HSB Stack Conversion

Lee Berndt
Good Morning … hope everyone is doing well today … I have a Nikon raw image (*.NEF) that I can convert to 16 bit TIFF using the Nikon software … from the 16 bit Tiff I can ultimately generate a 32 bit floating point LAB stack quite nicely with image/type …. but when I try to convert it to HSB stack or RGB stack it returns 8 bit images …. is there a way to generate 32 bit HSB stack? I'd like to examine the hue slice in detail but with an 8 bit stack it appears to be limited to only 255 hue angles … meaning the returned value for hue slice is not even close …. this may be a question for Wayne? … Please advise and thank you in advance …. have a blessed day … Lee

William L. Berndt, Ph.D.  7133 Penner Lane. Apt. #40Fort Myers, FL 33907@Dr_Lee_Berndt239.246.0396     

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Wayne Rasband-2
> On Jul 11, 2020, at 8:39 AM, Lee Berndt <[hidden email]> wrote:
>
> Good Morning … hope everyone is doing well today … I have a Nikon raw image (*.NEF) that I can convert to 16 bit TIFF using the Nikon software … from the 16 bit Tiff I can ultimately generate a 32 bit floating point LAB stack quite nicely with image/type …. but when I try to convert it to HSB stack or RGB stack it returns 8 bit images …. is there a way to generate 32 bit HSB stack? I'd like to examine the hue slice in detail but with an 8 bit stack it appears to be limited to only 255 hue angles … meaning the returned value for hue slice is not even close …. this may be a question for Wayne? … Please advise and thank you in advance …. have a blessed day … Lee

The latest ImageJ daily build (1.53d18) adds adds an Image>Type>HSB (32-bit) command.

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Lee Berndt
Hello Wayne … thank you for responding …. and the 32-bit version of HSB stack is much appreciated … but when I look at the same image the Lab = 53.4, -15.9, 14.3 and its RGB equivalent is 109.4, 136.5, 104.5 … but the 32 bit version of HSB stack gives me hue = 0.301, satur. = 0.289, and brightness = 0.538 …. brightness is spot on but hue and saturation appear to be off (?)  ….. the equivalent hue angle should be about 109° and saturation is 24% …. arctan(b/a) is about 2.4 …. how is the reported hue angle in 32 bit HSB stack being calculated or reported?  please advise and thank you very much …. have a blessed day …. Lee

William L. Berndt, Ph.D.  7133 Penner Lane. Apt. #40Fort Myers, FL 33907@Dr_Lee_Berndt239.246.0396     

-----Original Message-----
From: Wayne Rasband <[hidden email]>
To: [hidden email]
Sent: Sat, Jul 11, 2020 11:32 am
Subject: Re: HSB Stack Conversion

> On Jul 11, 2020, at 8:39 AM, Lee Berndt <[hidden email]> wrote:
>
> Good Morning … hope everyone is doing well today … I have a Nikon raw image (*.NEF) that I can convert to 16 bit TIFF using the Nikon software … from the 16 bit Tiff I can ultimately generate a 32 bit floating point LAB stack quite nicely with image/type …. but when I try to convert it to HSB stack or RGB stack it returns 8 bit images …. is there a way to generate 32 bit HSB stack? I'd like to examine the hue slice in detail but with an 8 bit stack it appears to be limited to only 255 hue angles … meaning the returned value for hue slice is not even close …. this may be a question for Wayne? … Please advise and thank you in advance …. have a blessed day … Lee

The latest ImageJ daily build (1.53d18) adds adds an Image>Type>HSB (32-bit) command.

-wayne

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Gabriel Landini
On Saturday, 11 July 2020 18:48:05 BST Lee Berndt wrote:
> Hello Wayne … thank you for responding …. and the 32-bit version of HSB
> stack is much appreciated … but when I look at the same image the Lab =
> 53.4, -15.9, 14.3 and its RGB equivalent is 109.4, 136.5, 104.5 … but the
> 32 bit version of HSB stack gives me hue = 0.301, satur. = 0.289, and
> brightness = 0.538 …

Just did a test with a full colour 24bit image and HSB channels are all scaled
to the range 0..1 which seems very convenient.

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Lee Berndt
Hello Gabriel …. thank you for responding …. it makes sense now and I appreciate the work it took to produce this algorithm …. but if I might ask … the saturation component seems to be off a little bit …. LAB values of 57.9, -18.2, and 15.1 from a raw image (RGB = 116, 147,112) result in a saturation value of 24% but the 32-bit HSB stack reports saturatioin as 29% …. I checked these calculations with my own and using a commercial software package (independent calculations) …. any thoughts?  How is the saturation component being calculated?  Please advise and thank you in advance …. have a blessed day …. Lee

William L. Berndt, Ph.D.  7133 Penner Lane. Apt. #40Fort Myers, FL 33907@Dr_Lee_Berndt239.246.0396     

-----Original Message-----
From: Gabriel Landini <[hidden email]>
To: [hidden email]
Sent: Sat, Jul 11, 2020 2:40 pm
Subject: Re: HSB Stack Conversion

On Saturday, 11 July 2020 18:48:05 BST Lee Berndt wrote:
> Hello Wayne … thank you for responding …. and the 32-bit version of HSB
> stack is much appreciated … but when I look at the same image the Lab =
> 53.4, -15.9, 14.3 and its RGB equivalent is 109.4, 136.5, 104.5 … but the
> 32 bit version of HSB stack gives me hue = 0.301, satur. = 0.289, and
> brightness = 0.538 …

Just did a test with a full colour 24bit image and HSB channels are all scaled
to the range 0..1 which seems very convenient.

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Wayne Rasband-2
> On Jul 13, 2020, at 8:51 AM, Lee Berndt <[hidden email]> wrote:
>
> Hello Gabriel …. thank you for responding …. it makes sense now and I appreciate the work it took to produce this algorithm …. but if I might ask … the saturation component seems to be off a little bit …. LAB values of 57.9, -18.2, and 15.1 from a raw image (RGB = 116, 147,112) result in a saturation value of 24% but the 32-bit HSB stack reports saturatioin as 29% …. I checked these calculations with my own and using a commercial software package (independent calculations) …. any thoughts?  How is the saturation component being calculated?  Please advise and thank you in advance …. have a blessed day …. Lee

ImageJ uses Java's Color.RGBtoHSB() method to convert from RGB to HSB. The source code for this method is below.

-wayne

    /**
     * Converts the components of a color, as specified by the default RGB
     * model, to an equivalent set of values for hue, saturation, and
     * brightness that are the three components of the HSB model.
     * <p>
     * If the <code>hsbvals</code> argument is <code>null</code>, then a
     * new array is allocated to return the result. Otherwise, the method
     * returns the array <code>hsbvals</code>, with the values put into
     * that array.
     * @param     r   the red component of the color
     * @param     g   the green component of the color
     * @param     b   the blue component of the color
     * @param     hsbvals  the array used to return the
     *                     three HSB values, or <code>null</code>
     * @return    an array of three elements containing the hue, saturation,
     *                     and brightness (in that order), of the color with
     *                     the indicated red, green, and blue components.
     * @see       java.awt.Color#getRGB()
     * @see       java.awt.Color#Color(int)
     * @see       java.awt.image.ColorModel#getRGBdefault()
     * @since     JDK1.0
     */
    public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) {
        float hue, saturation, brightness;
        if (hsbvals == null) {
            hsbvals = new float[3];
        }
        int cmax = (r > g) ? r : g;
        if (b > cmax) cmax = b;
        int cmin = (r < g) ? r : g;
        if (b < cmin) cmin = b;

        brightness = ((float) cmax) / 255.0f;
        if (cmax != 0)
            saturation = ((float) (cmax - cmin)) / ((float) cmax);
        else
            saturation = 0;
        if (saturation == 0)
            hue = 0;
        else {
            float redc = ((float) (cmax - r)) / ((float) (cmax - cmin));
            float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin));
            float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin));
            if (r == cmax)
                hue = bluec - greenc;
            else if (g == cmax)
                hue = 2.0f + redc - bluec;
            else
                hue = 4.0f + greenc - redc;
            hue = hue / 6.0f;
            if (hue < 0)
                hue = hue + 1.0f;
        }
        hsbvals[0] = hue;
        hsbvals[1] = saturation;
        hsbvals[2] = brightness;
        return hsbvals;
    }


>
> William L. Berndt, Ph.D.  7133 Penner Lane. Apt. #40Fort Myers, FL 33907@Dr_Lee_Berndt239.246.0396    
>
> -----Original Message-----
> From: Gabriel Landini <[hidden email]>
> To: [hidden email]
> Sent: Sat, Jul 11, 2020 2:40 pm
> Subject: Re: HSB Stack Conversion
>
> On Saturday, 11 July 2020 18:48:05 BST Lee Berndt wrote:
>> Hello Wayne … thank you for responding …. and the 32-bit version of HSB
>> stack is much appreciated … but when I look at the same image the Lab =
>> 53.4, -15.9, 14.3 and its RGB equivalent is 109.4, 136.5, 104.5 … but the
>> 32 bit version of HSB stack gives me hue = 0.301, satur. = 0.289, and
>> brightness = 0.538 …
>
> Just did a test with a full colour 24bit image and HSB channels are all scaled
> to the range 0..1 which seems very convenient.
>
> Cheers
>
> Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: HSB Stack Conversion

Michael Schmid
Hi everyone,

just for further clarification:

For the RGB to HSB conversion, Java does not use an arctangent function
but a kind of linear interpolation between the primary colors. It's the
essentially same for the reverse transformation (HSB to RGB).

You can find both methods in the wikipedia article:
   https://en.wikipedia.org/wiki/HSL_and_HSV#Hue_and_chroma

For the primary colors RGB and the exact midpoints between them (yellow,
magenta, cyan), the values are the same between these methods. For other
values, there is a difference between the (arc)tangent and the java method.

According Wikipedia, the maximum difference between the (arc)tangent and
the Java method is 1.12°. So you should expect differences up to this
magnitude when comparing different ways of converting RGB to HSB.

Michael
________________________________________________________________
On 13.07.20 16:05, Wayne Rasband wrote:

>> On Jul 13, 2020, at 8:51 AM, Lee Berndt <[hidden email]> wrote:
>>
>> Hello Gabriel …. thank you for responding …. it makes sense now and I appreciate the work it took to produce this algorithm …. but if I might ask … the saturation component seems to be off a little bit …. LAB values of 57.9, -18.2, and 15.1 from a raw image (RGB = 116, 147,112) result in a saturation value of 24% but the 32-bit HSB stack reports saturatioin as 29% …. I checked these calculations with my own and using a commercial software package (independent calculations) …. any thoughts?  How is the saturation component being calculated?  Please advise and thank you in advance …. have a blessed day …. Lee
>
> ImageJ uses Java's Color.RGBtoHSB() method to convert from RGB to HSB. The source code for this method is below.
>
> -wayne
>
>      /**
>       * Converts the components of a color, as specified by the default RGB
>       * model, to an equivalent set of values for hue, saturation, and
>       * brightness that are the three components of the HSB model.
>       * <p>
>       * If the <code>hsbvals</code> argument is <code>null</code>, then a
>       * new array is allocated to return the result. Otherwise, the method
>       * returns the array <code>hsbvals</code>, with the values put into
>       * that array.
>       * @param     r   the red component of the color
>       * @param     g   the green component of the color
>       * @param     b   the blue component of the color
>       * @param     hsbvals  the array used to return the
>       *                     three HSB values, or <code>null</code>
>       * @return    an array of three elements containing the hue, saturation,
>       *                     and brightness (in that order), of the color with
>       *                     the indicated red, green, and blue components.
>       * @see       java.awt.Color#getRGB()
>       * @see       java.awt.Color#Color(int)
>       * @see       java.awt.image.ColorModel#getRGBdefault()
>       * @since     JDK1.0
>       */
>      public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) {
>          float hue, saturation, brightness;
>          if (hsbvals == null) {
>              hsbvals = new float[3];
>          }
>          int cmax = (r > g) ? r : g;
>          if (b > cmax) cmax = b;
>          int cmin = (r < g) ? r : g;
>          if (b < cmin) cmin = b;
>
>          brightness = ((float) cmax) / 255.0f;
>          if (cmax != 0)
>              saturation = ((float) (cmax - cmin)) / ((float) cmax);
>          else
>              saturation = 0;
>          if (saturation == 0)
>              hue = 0;
>          else {
>              float redc = ((float) (cmax - r)) / ((float) (cmax - cmin));
>              float greenc = ((float) (cmax - g)) / ((float) (cmax - cmin));
>              float bluec = ((float) (cmax - b)) / ((float) (cmax - cmin));
>              if (r == cmax)
>                  hue = bluec - greenc;
>              else if (g == cmax)
>                  hue = 2.0f + redc - bluec;
>              else
>                  hue = 4.0f + greenc - redc;
>              hue = hue / 6.0f;
>              if (hue < 0)
>                  hue = hue + 1.0f;
>          }
>          hsbvals[0] = hue;
>          hsbvals[1] = saturation;
>          hsbvals[2] = brightness;
>          return hsbvals;
>      }
>
>
>>
>> William L. Berndt, Ph.D.  7133 Penner Lane. Apt. #40Fort Myers, FL 33907@Dr_Lee_Berndt239.246.0396
>>
>> -----Original Message-----
>> From: Gabriel Landini <[hidden email]>
>> To: [hidden email]
>> Sent: Sat, Jul 11, 2020 2:40 pm
>> Subject: Re: HSB Stack Conversion
>>
>> On Saturday, 11 July 2020 18:48:05 BST Lee Berndt wrote:
>>> Hello Wayne … thank you for responding …. and the 32-bit version of HSB
>>> stack is much appreciated … but when I look at the same image the Lab =
>>> 53.4, -15.9, 14.3 and its RGB equivalent is 109.4, 136.5, 104.5 … but the
>>> 32 bit version of HSB stack gives me hue = 0.301, satur. = 0.289, and
>>> brightness = 0.538 …
>>
>> Just did a test with a full colour 24bit image and HSB channels are all scaled
>> to the range 0..1 which seems very convenient.
>>
>> Cheers
>>
>> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html