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(); }
/** * Create a new stains object with the same StainVectors but new max (background) values. * * @param maxRed * @param maxGreen * @param maxBlue * @return */ public ColorDeconvolutionStains changeMaxValues(double maxRed, double maxGreen, double maxBlue) { return new ColorDeconvolutionStains(getName(), getStain(1), getStain(2), getStain(3), maxRed, maxGreen, maxBlue); }
/** * 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()); }
return new ColorDeconvolutionStains(stains.getName(), stain1Refined, stain2Refined, whiteValues[0], whiteValues[1], whiteValues[2]);
ColorDeconvolutionStains stains = new ColorDeconvolutionStains(stainsOriginal.getName(), s1, s2, stainsOriginal.getMaxRed(), stainsOriginal.getMaxGreen(), stainsOriginal.getMaxBlue());