public static IndexColorModel getIndexColorModel(final StainVector stain, boolean whiteBackground) { if (!whiteBackground) return createIndexColorModel(new Color(stain.getColor())); double r = stain.getRed(); double g = stain.getGreen(); double b = stain.getBlue(); byte[] r2 = new byte[256]; byte[] g2 = new byte[256]; byte[] b2 = new byte[256]; for (int i = 0; i < 256; i++) { r2[i] = (byte)StainVector.clip255(255.0 - r * i); g2[i] = (byte)StainVector.clip255(255.0 - g * i); b2[i] = (byte)StainVector.clip255(255.0 - b * i); // r2[i] = (byte)clip255(Math.exp(-r) * (255 - i)); // g2[i] = (byte)clip255(Math.exp(-g) * (255 - i)); // b2[i] = (byte)clip255(Math.exp(-b) * (255 - i)); } return new IndexColorModel(8, 256, r2, g2, b2); }
public final void ensureStainsUpdated() { if (imageDisplay == null || imageDisplay.getImageData() == null) { stains = null; return; } stains = imageDisplay.getImageData().getColorDeconvolutionStains(); if (stainNumber < 0) { color = ColorTools.makeRGB(255, 255, 255); colorModel = ColorTransformerAWT.getDefaultColorModel(method); } else { color = stains.getStain(stainNumber).getColor(); colorModel = ColorToolsAwt.getIndexColorModel(stains.getStain(stainNumber)); } }