/** * Convert to optical densities in which a second image is used to provide the 'maximum' (i.e. white) pixel values. * @param px * @param pxMax */ public static void convertPixelsToOpticalDensities(float[] px, float[] pxMax) { for (int i = 0; i < px.length; i++) px[i] = (float)makeOD(px[i], pxMax[i]); }
/** * For originally-8-bit images, optical densities can usually be computed faster by preallocating a LUT with the 0-255 required values. * Otherwise, logs need to be calculated for every pixel (which can be relatively slow). * * @param px * @param maxValue * @param use8BitLUT */ public static void convertPixelsToOpticalDensities(float[] px, double maxValue, boolean use8BitLUT) { if (use8BitLUT) { double[] od_lut = makeODLUT(maxValue, 256); for (int i = 0; i < px.length; i++) px[i] = (float)makeODByLUT(px[i], od_lut); } else { for (int i = 0; i < px.length; i++) px[i] = (float)makeOD(px[i], maxValue); } }
public static double[] makeODLUT(double maxValue, int nValues) { double[] OD_LUT = new double[nValues]; for (int i = 0; i < nValues; i++) //J OD_LUT[i] = makeOD(i, maxValue); return OD_LUT; }
public static float colorDeconvolveRGBPixel(int rgb, ColorDeconvolutionStains stains, int channel) { double[][] matInv = stains.getMatrixInverse(); double scaleRed = matInv[0][channel]; double scaleGreen = matInv[1][channel]; double scaleBlue = matInv[2][channel]; // Apply color deconvolution double r = ColorDeconvolutionHelper.makeOD((rgb & 0xff0000) >> 16, stains.getMaxRed()); double g = ColorDeconvolutionHelper.makeOD((rgb & 0xff00) >> 8, stains.getMaxGreen()); double b = ColorDeconvolutionHelper.makeOD((rgb & 0xff), stains.getMaxBlue()); return (float)(r * scaleRed + g * scaleGreen + b * scaleBlue); }
public static StainVector generateStainVectorFromRGB(String name, int rgb, double redMax, double greenMax, double blueMax) { double rOD = makeOD(ColorTools.red(rgb), redMax); double gOD = makeOD(ColorTools.green(rgb), greenMax); //J double bOD = makeOD(ColorTools.blue(rgb), blueMax); //J return new StainVector(name, rOD, gOD, bOD); }
@Override public float getValue(BufferedImage img, int x, int y) { ensureStainsUpdated(); if (stains == null) return 0f; int rgb = img.getRGB(x, y); if (method == null) return ColorDeconvolution.colorDeconvolveRGBPixel(rgb, stains, stainNumber-1); else if (method == ColorTransformMethod.Optical_density_sum) { int r = ColorTools.red(rgb); int g = ColorTools.green(rgb); int b = ColorTools.blue(rgb); return (float)(ColorDeconvolutionHelper.makeOD(r, stains.getMaxRed()) + ColorDeconvolutionHelper.makeOD(g, stains.getMaxGreen()) + ColorDeconvolutionHelper.makeOD(b, stains.getMaxBlue())); } else return ColorTransformer.getPixelValue(rgb, method); }