/** * Get a Color that (roughly) corresponds to color represented by this stain vector. * It may be used to create a color lookup table. * * @return */ public int getColor() { int r2 = clip255(255.0 - r * 255); int g2 = clip255(255.0 - g * 255); int b2 = clip255(255.0 - b * 255); return ColorTools.makeRGB(r2, g2, b2); }
public static IndexColorModel createIndexColorModel(Color color, boolean whiteBackground) { if (!whiteBackground) return ColorToolsAwt.createIndexColorModel(color); byte[] rLut = new byte[256]; byte[] gLut = new byte[256]; byte[] bLut = new byte[256]; int red = color.getRed(); int green = color.getGreen(); int blue = color.getBlue(); double len = Math.sqrt(red*red + green*green + blue*blue); double rIncr = 1-((double)red)/len; double gIncr = 1-((double)green)/len; double bIncr = 1-((double)blue)/len; for (int i=0; i<256; ++i) { rLut[i] = (byte)StainVector.clip255(255 - i*rIncr); gLut[i] = (byte)StainVector.clip255(255 - i*gIncr); bLut[i] = (byte)StainVector.clip255(255 - i*bIncr); } return new IndexColorModel(8, 256, rLut, gLut, bLut); }
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); }