/** * Create a new packed-int representation of an RGB color. * * @param v A value between 0 and 255. If a single value is give, the result will be * a shade of gray (RGB all with that value). Otherwise, 3 or 4 values may be given to generate * either an RGB or RGBA color. * @return */ public static Integer getColorRGB(final int... v) { if (v.length == 1) return ColorTools.makeRGB(v[0], v[0], v[0]); if (v.length == 3) return ColorTools.makeRGB(v[0], v[1], v[2]); if (v.length == 4) return ColorTools.makeRGBA(v[0], v[1], v[2], v[3]); throw new IllegalArgumentException("Input to getColorRGB must be either 1, 3 or 4 integer values, between 0 and 255!"); }
/** * Similar to getDefaultRGBChannelColors, but including Magenta, Cyan & Yellow to return colors for up to 6 channels. * If only one channel is present, or a channel number > 6 is requested, Color.WHITE is returned. * * @param channel * @return */ protected Integer getExtendedDefaultChannelColor(int channel) { if (nChannels() == 1) return ColorTools.makeRGB(255, 255, 255); switch (channel) { case 0: return ColorTools.makeRGB(255, 0, 0); case 1: return ColorTools.makeRGB(0, 255, 0); case 2: return ColorTools.makeRGB(0, 0, 255); case 3: return ColorTools.makeRGB(255, 255, 0); case 4: return ColorTools.makeRGB(0, 255, 255); case 5: return ColorTools.makeRGB(255, 255, 0); default: return ColorTools.makeRGB(255, 255, 255); } }
/** * Method that may be used to get RGB colors. * Classes that only provide RGB images may call this from their getDefaultChannelColors method. * * @param channel * @return */ protected Integer getDefaultRGBChannelColors(int channel) { if (nChannels() == 1) return ColorTools.makeRGB(255, 255, 255); switch (channel) { case 0: return ColorTools.makeRGB(255, 0, 0); case 1: return ColorTools.makeRGB(0, 255, 0); case 2: return ColorTools.makeRGB(0, 0, 255); default: return ColorTools.makeRGB(255, 255, 255); } }
/** * Get a Color object, possibly from a shared map (used to avoid creating too many objects unnecessarily). * @param r * @param g * @param b * @return */ public static Color getCachedColor(final int r, final int g, final int b) { return ColorToolsAwt.getCachedColor(ColorTools.makeRGB(r, g, b)); }
/** * Notify the object if it is currently being processed. * * This is used to update its color. * * @param isProcessing */ public void setIsProcessing(boolean isProcessing) { this.isProcessing = isProcessing; if (this.isProcessing) setColorRGB(ColorTools.makeRGB(255, 255, 0)); else setColorRGB(ColorTools.makeRGB(128, 128, 128)); }
/** * Scale the RGB channels for a color by a fixed amount. * * This is useful for brightening/darkening an input color. * * @param rgb * @param scale * @return */ public static int makeScaledRGB(final int rgb, final double scale) { return makeRGB( (int)Math.min(255, (ColorTools.red(rgb)*scale)), (int)Math.min(255, (ColorTools.green(rgb)*scale)), (int)Math.min(255, (ColorTools.blue(rgb)*scale))); }
public ParallelTileObject(final ROI pathROI, final PathObjectHierarchy hierarchy, final AtomicInteger countdown) { super(pathROI); this.bounds = getBounds2D(pathROI); this.hierarchy = hierarchy; this.countdown = countdown; setColorRGB(ColorTools.makeRGB(128, 128, 128)); }
} else { rgb = ColorTools.makeRGB( (int)(Math.random()*255), (int)(Math.random()*255),
/** * 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); }
setColorRGB(ColorTools.makeRGB(255, 0, 0));
/** * Determine median of RGB values. * The median of each channel is computed separately. * * @param name * @param rgb * @param redMax * @param greenMax * @param blueMax * @return */ public static int getMedianRGB(int[] rgb) { int n = rgb.length; // Extract medians for each channel int[] temp = new int[n]; for (int i = 0; i < rgb.length; i++) temp[i] = ColorTools.red(rgb[i]); int rMedian = getMedian(temp); for (int i = 0; i < rgb.length; i++) temp[i] = ColorTools.green(rgb[i]); int gMedian = getMedian(temp); for (int i = 0; i < rgb.length; i++) temp[i] = ColorTools.blue(rgb[i]); int bMedian = getMedian(temp); return ColorTools.makeRGB(rMedian, gMedian, bMedian); }
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)); } }
public void setLUTColor(int r, int g, int b) { // Create a LUT rgbLUT = new int[256]; byte[] rb = new byte[256]; byte[] gb = new byte[256]; byte[] bb = new byte[256]; for (int i = 0; i < 256; i++) { rgbLUT[i] = ColorTools.makeRGB( ColorTools.do8BitRangeCheck(r / 255.0 * i), ColorTools.do8BitRangeCheck(g / 255.0 * i), ColorTools.do8BitRangeCheck(b / 255.0 * i) ); rb[i] = (byte)ColorTools.do8BitRangeCheck(r / 255.0 * i); gb[i] = (byte)ColorTools.do8BitRangeCheck(g / 255.0 * i); bb[i] = (byte)ColorTools.do8BitRangeCheck(b / 255.0 * i); } cm = new IndexColorModel(8, 256, rb, gb, bb); this.rgb = (r << 16) + (g << 8) + b; // this.r = do8BitRangeCheck(r); // this.g = do8BitRangeCheck(g); // this.b = do8BitRangeCheck(b); // this.rgb = (r << 16) + (g << 8) + b; }