public final void toGrayScale(boolean normalize)
    {
        if (npix == 0)
        {
            return;
        }
        if (!normalize)
        {
            for (int i = 0; i < npix; i++)
            {
                pixels[i] = rgbToGrayScale(pixels[i]);
            }
        }
        else
        {
            int pix;
            pixels[0] = pix = rgbToGrayScale(pixels[0]);
            int min = pix, max = pix;
            for (int i = 1; i < npix; i++)
            {
                pixels[i] = pix = rgbToGrayScale(pixels[i]);
                min = Math.min(min, pix);
                max = Math.max(max, pix);
            }
            int range = max - min;
            if (range < 1)
            {
                for (int i = 0; i < npix; i++)
                {
                    pixels[i] = 255;
                }
            }
            else
            {
                for (int i = 0; i < npix; i++)
                {
                    pixels[i] =
                            Math.min(255,
                            Math.max(0,
                            ((pixels[i]
                            - min) * 255) / range));
                }
            }
        }
    }