/** * Get a scaled version of the specified color, where the RGB values are independently scaled by a specified factor. * * The alpha value is preserved unchanged. * * @param color * @return */ public static Color scaleColor(Color color, double factor) { return new Color(ColorTools.do8BitRangeCheck(color.getRed()*factor), ColorTools.do8BitRangeCheck(color.getGreen()*factor), ColorTools.do8BitRangeCheck(color.getBlue()*factor), color.getAlpha()); }
public void setLUTColor(int r, int g, int b) { // Create a LUT rgbLUT = new int[256]; byte[] rb = new byte[256]; byte[] gb = new byte[256]; byte[] bb = new byte[256]; for (int i = 0; i < 256; i++) { rgbLUT[i] = ColorTools.makeRGB( ColorTools.do8BitRangeCheck(r / 255.0 * i), ColorTools.do8BitRangeCheck(g / 255.0 * i), ColorTools.do8BitRangeCheck(b / 255.0 * i) ); rb[i] = (byte)ColorTools.do8BitRangeCheck(r / 255.0 * i); gb[i] = (byte)ColorTools.do8BitRangeCheck(g / 255.0 * i); bb[i] = (byte)ColorTools.do8BitRangeCheck(b / 255.0 * i); } cm = new IndexColorModel(8, 256, rb, gb, bb); this.rgb = (r << 16) + (g << 8) + b; // this.r = do8BitRangeCheck(r); // this.g = do8BitRangeCheck(g); // this.b = do8BitRangeCheck(b); // this.rgb = (r << 16) + (g << 8) + b; }
public static int deconvolve8bit(int rgb, double[][] invMat, double[] od_lut, int stain) { // Apply deconvolution & store the results return ColorTools.do8BitRangeCheck(Math.exp(-deconvolve(rgb, invMat, od_lut, stain)) * 255); }
public static int makeScaledRGBwithRangeCheck(float v, float offset, float scale, ColorModel cm) { return ColorTransformerAWT.makeRGB(ColorTools.do8BitRangeCheck((v - offset) * scale), cm); }
public static int deconvolve8bit(int rgb, double[][] invMat, double[] od_lut_red, double[] od_lut_green, double[] od_lut_blue, int stain) { // Apply deconvolution & store the results return ColorTools.do8BitRangeCheck(Math.exp(-deconvolve(rgb, invMat, od_lut_red, od_lut_green, od_lut_blue, stain)) * 255); }
public static int makeRGBwithRangeCheck(float v, ColorModel cm) { return ColorTransformerAWT.makeRGB(ColorTools.do8BitRangeCheck(v), cm); }
/** * Create a 'normalized' color by converting RGB values to optical densities, putting the RGB ODs into * a 3x1 vector and normalizing this to unit length, then rescaling the result to give an RGB representation. * Because of the somewhat strange rescaling involved, the final RGB values produced should not be over-interpreted - * this is really intended for visualization, such as when interactively looking for regions of single stains * when selecting color deconvolution stain vectors. * * @param rgb original 8-bit RGB values * @param minOD the minimum OD - pixels with an OD less than this will be considered unstained, and shown as white * @param offset brightness and contrast offset * @param scale brightness and contrast scale value * @return normalized color, as packed RGB value */ public static int getODNormalizedColor(int rgb, double minOD, float offset, float scale) { double r_od = od_lut[ColorTools.red(rgb)]; double g_od = od_lut[ColorTools.green(rgb)]; double b_od = od_lut[ColorTools.blue(rgb)]; double norm = Math.sqrt(r_od*r_od + g_od*g_od + b_od*b_od); if (norm < minOD) { norm = minOD; //Jreturn ((255<<16) + (255<<8) + 255) & ~ColorTools.MASK_ALPHA | (rgb & ColorTools.MASK_ALPHA); return 0x00ffffff | (rgb & ColorTools.MASK_ALPHA); //J Slightly faster? } int r = 255-ColorTools.do8BitRangeCheck((255*r_od/norm - offset) * scale); int g = 255-ColorTools.do8BitRangeCheck((255*g_od/norm - offset) * scale); int b = 255-ColorTools.do8BitRangeCheck((255*b_od/norm - offset) * scale); return ((r<<16) + (g<<8) + b) & ~ColorTools.MASK_ALPHA | (rgb & ColorTools.MASK_ALPHA); }
int ind = 0; for (int v : buffer) { int r = ColorTools.do8BitRangeCheck((ColorTools.red(v) - offset) * scale); int g = ColorTools.do8BitRangeCheck((ColorTools.green(v) - offset) * scale); int b = ColorTools.do8BitRangeCheck((ColorTools.blue(v) - offset) * scale); rgb[ind] = (r << 16) + (g << 8) + b; ind++;
int r = ColorTools.do8BitRangeCheck((ColorTools.red(rgb) - offset) * scale); int g = ColorTools.do8BitRangeCheck((ColorTools.green(rgb) - offset) * scale); int b = ColorTools.do8BitRangeCheck((ColorTools.blue(rgb) - offset) * scale);
bufOutput[i] = (ColorTools.do8BitRangeCheck((r + offset) * scale) << 16) + (ColorTools.do8BitRangeCheck((g + offset) * scale) << 8) + ColorTools.do8BitRangeCheck((b + offset) * scale);