protected static double[] makeODLUT(double maxValue) { return ColorDeconvolutionHelper.makeODLUT(maxValue, 256); }
/** * Convert red channel of packed rgb pixel to optical density values, using a specified maximum value. * * @param rgb * @param maxValue * @param px optional array used for output * @return */ public static float[] getGreenOpticalDensities(int[] rgb, double maxValue, float[] px) { if (px == null) px = new float[rgb.length]; double[] od_lut = makeODLUT(maxValue, 256); for (int i = 0; i < px.length; i++) px[i] = (float)makeODByLUT(ColorTools.green(rgb[i]), od_lut); return px; }
double[] od_lut_red = ColorDeconvolutionHelper.makeODLUT(maxRed); //J double[] od_lut_green = maxRed == maxGreen ? od_lut_red : ColorDeconvolutionHelper.makeODLUT(maxGreen); //J double[] od_lut_blue = maxBlue == maxRed ? od_lut_red : maxBlue == maxGreen ? od_lut_green : ColorDeconvolutionHelper.makeODLUT(maxBlue); //J
/** * Convert red channel of packed rgb pixel to optical density values, using a specified maximum value. * * @param rgb * @param maxValue * @param px optional array used for output * @return */ public static float[] getBlueOpticalDensities(int[] rgb, double maxValue, float[] px) { if (px == null) px = new float[rgb.length]; double[] od_lut = makeODLUT(maxValue, 256); for (int i = 0; i < px.length; i++) px[i] = (float)makeODByLUT(ColorTools.blue(rgb[i]), od_lut); return px; }
/** * Convert red channel of packed rgb pixel to optical density values, using a specified maximum value. * * @param rgb * @param maxValue * @param px optional array used for output * @return */ public static float[] getRedOpticalDensities(int[] rgb, double maxValue, float[] px) { if (px == null) px = new float[rgb.length]; double[] od_lut = makeODLUT(maxValue, 256); for (int i = 0; i < px.length; i++) px[i] = (float)makeODByLUT(ColorTools.red(rgb[i]), od_lut); return px; }
/** * 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 float[] colorDeconvolveRGBArray(int[] buf, double[] stain1, double[] stain2, double[] stain3, int channel, float[] output) { if (output == null || output.length != buf.length) output = new float[buf.length]; if (stain3 == null) stain3 = StainVector.cross3(stain1, stain2); double[][] stainMat = new double[][]{stain1, stain2, stain3}; ColorDeconvMatrix3x3 mat3x3 = new ColorDeconvMatrix3x3(stainMat); double[][] matInv = mat3x3.inverse(); double[] stain1Inv = matInv[0]; double[] stain2Inv = matInv[1]; double[] stain3Inv = matInv[2]; // Apply color deconvolution double[] od_lut = ColorDeconvolutionHelper.makeODLUT(255, 256); for (int i = 0; i < buf.length; i++) { int c = buf[i]; // Extract RGB values & convert to optical densities using a lookup table double r = od_lut[(c & 0xff0000) >> 16]; double g = od_lut[(c & 0xff00) >> 8]; double b = od_lut[c & 0xff]; // Apply deconvolution & store the results output[i] = (float)(r * stain1Inv[channel] + g * stain2Inv[channel] + b * stain3Inv[channel]); } return output; }
od_lut = ColorDeconvolutionHelper.makeODLUT(stains.getMaxRed()); for (int i = 0; i < buf.length; i++) { pixels[i] = (float)od_lut[ColorTools.red(buf[i])]; od_lut = ColorDeconvolutionHelper.makeODLUT(stains.getMaxGreen()); for (int i = 0; i < buf.length; i++) { pixels[i] = (float)od_lut[ColorTools.green(buf[i])]; od_lut = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); for (int i = 0; i < buf.length; i++) { pixels[i] = (float)od_lut[ColorTools.blue(buf[i])]; od_lut_red = ColorDeconvolutionHelper.makeODLUT(stains.getMaxRed()); od_lut_green = ColorDeconvolutionHelper.makeODLUT(stains.getMaxGreen()); od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); inverse = stains.getMatrixInverse(); for (int i = 0; i < buf.length; i++) { od_lut_red = ColorDeconvolutionHelper.makeODLUT(stains.getMaxRed()); od_lut_green = ColorDeconvolutionHelper.makeODLUT(stains.getMaxGreen()); od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); inverse = stains.getMatrixInverse(); for (int i = 0; i < buf.length; i++) { od_lut_red = ColorDeconvolutionHelper.makeODLUT(stains.getMaxRed()); od_lut_green = ColorDeconvolutionHelper.makeODLUT(stains.getMaxGreen()); od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); inverse = stains.getMatrixInverse(); for (int i = 0; i < buf.length; i++) {