public static String getColorDeconvolutionStainsAsString(final ColorDeconvolutionStains stains, final int nDecimalPlaces) { if (stains == null) return ""; StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("\"Name").append("\" : \"").append(stains.getName()).append("\", "); for (int i = 1; i <= 3; i++) { StainVector stain = stains.getStain(i); // No need to add the residual stain if (i == 3 && stain.isResidual()) continue; sb.append("\"Stain ").append(i).append("\" : \"").append(stain.getName()).append("\", "); sb.append("\"Values ").append(i).append("\" : \"").append(stain.arrayAsString(Locale.US, nDecimalPlaces)).append("\", "); } sb.append("\"Background\" : \""); sb.append(" ").append(GeneralTools.arrayToString(Locale.US, new double[]{stains.getMaxRed(), stains.getMaxGreen(), stains.getMaxBlue()}, nDecimalPlaces)); // sb.append(String.format( "%.Nf %.Nf %.Nf".replace("N", Integer.toString(nDecimalPlaces)), stains.getMaxRed(), stains.getMaxGreen(), stains.getMaxBlue())); // sb.append(stains.getMaxRed()).append(" "); // sb.append(stains.getMaxGreen()).append(" "); // sb.append(stains.getMaxBlue()); sb.append("\"}"); return sb.toString(); }
public static ColorDeconvolutionStains estimateStains(final BufferedImage img, final ColorDeconvolutionStains stainsOriginal, final double minStain, final double maxStain, final double ignorePercentage, final boolean checkColors) { int[] buf = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth()); int[] rgb = buf; float[] red = ColorDeconvolutionHelper.getRedOpticalDensities(rgb, stainsOriginal.getMaxRed(), null); float[] green = ColorDeconvolutionHelper.getGreenOpticalDensities(rgb, stainsOriginal.getMaxGreen(), null); float[] blue = ColorDeconvolutionHelper.getBlueOpticalDensities(rgb, stainsOriginal.getMaxBlue(), null); return estimateStains(buf, red, green, blue, stainsOriginal, minStain, maxStain, ignorePercentage, checkColors); }
/** * Create a new stains object with the same StainVectors but a new name. * * @param name * @return */ public ColorDeconvolutionStains changeName(String name) { return new ColorDeconvolutionStains(name, getStain(1), getStain(2), getStain(3), getMaxRed(), getMaxGreen(), getMaxBlue()); }
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); }
double maxBlue = stains.getMaxBlue(); //J
@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); }
/** * Create a new ColorDeconvolutionStains object, with all settings the same except one of the stains has been changed. * If the third stain was a residual, it will also be regenerated (i.e. it won't remain the same residual... which would be wrong, * as it would be orthogonal to the old stain rather than the new one). * * @param stains * @param stain * @param stainNumber * @return */ public static ColorDeconvolutionStains makeModifiedStains(ColorDeconvolutionStains stains, StainVector stainNew, int stainNumber) { StainVector[] stainVectors = new StainVector[3]; stainVectors[0] = stains.getStain(1); stainVectors[1] = stains.getStain(2); stainVectors[2] = stains.getStain(3); stainVectors[stainNumber - 1] = stainNew; if (stainVectors[2].isResidual()) stainVectors[2] = null; return new ColorDeconvolutionStains(stains.getName(), stainVectors[0], stainVectors[1], stainVectors[2], stains.getMaxRed(), stains.getMaxGreen(), stains.getMaxBlue()); }
ColorDeconvolutionStains stains = new ColorDeconvolutionStains(stainsOriginal.getName(), s1, s2, stainsOriginal.getMaxRed(), stainsOriginal.getMaxGreen(), stainsOriginal.getMaxBlue());
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++) { od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); inverse = stains.getMatrixInverse(); for (int i = 0; i < buf.length; i++) { od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stains.getMaxBlue()); inverse = stains.getMatrixInverse(); for (int i = 0; i < buf.length; i++) {
double maxBlue = stainsOutput.getMaxBlue(); double[] od_lut_blue = ColorDeconvolutionHelper.makeODLUT(stainsInput.getMaxBlue());