/** Creates a color LUT from a Color. */ public static LUT createLutFromColor(Color 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 rIncr = ((double)red)/255d; double gIncr = ((double)green)/255d; double bIncr = ((double)blue)/255d; for (int i=0; i<256; ++i) { rLut[i] = (byte)(i*rIncr); gLut[i] = (byte)(i*gIncr); bLut[i] = (byte)(i*bIncr); } return new LUT(rLut, gLut, bLut); }
private LUT makeLUT(Color color) { final int red = color.getRed(); final int green = color.getGreen(); final int blue = color.getBlue(); final int lutLength = 256; final int lutDivisor = lutLength - 1; byte[] r = new byte[lutLength]; byte[] g = new byte[lutLength]; byte[] b = new byte[lutLength]; for (int i=0; i<lutLength; i++) { r[i] = (byte) (i * red / lutDivisor); g[i] = (byte) (i * green / lutDivisor); b[i] = (byte) (i * blue / lutDivisor); } LUT lut = new LUT(r, g, b); return lut; }
private LUT makeLUT(Color color) { final int red = color.getRed(); final int green = color.getGreen(); final int blue = color.getBlue(); final int lutLength = 256; final int lutDivisor = lutLength - 1; byte[] r = new byte[lutLength]; byte[] g = new byte[lutLength]; byte[] b = new byte[lutLength]; for (int i=0; i<lutLength; i++) { r[i] = (byte) (i * red / lutDivisor); g[i] = (byte) (i * green / lutDivisor); b[i] = (byte) (i * blue / lutDivisor); } LUT lut = new LUT(r, g, b); return lut; }
LUT createLutFromBytes(byte[] bytes) { if (bytes==null || bytes.length!=768) return createLutFromColor(Color.white); byte[] r = new byte[256]; byte[] g = new byte[256]; byte[] b = new byte[256]; for (int i=0; i<256; i++) r[i] = bytes[i]; for (int i=0; i<256; i++) g[i] = bytes[256+i]; for (int i=0; i<256; i++) b[i] = bytes[512+i]; return new LUT(r, g, b); }
/** Creates a color LUT from a Color. */ public static LUT createLutFromColor(Color 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 rIncr = ((double)red)/255d; double gIncr = ((double)green)/255d; double bIncr = ((double)blue)/255d; for (int i=0; i<256; ++i) { rLut[i] = (byte)(i*rIncr); gLut[i] = (byte)(i*gIncr); bLut[i] = (byte)(i*bIncr); } return new LUT(rLut, gLut, bLut); }
LUT createLutFromBytes(byte[] bytes) { if (bytes==null || bytes.length!=768) return createLutFromColor(Color.white); byte[] r = new byte[256]; byte[] g = new byte[256]; byte[] b = new byte[256]; for (int i=0; i<256; i++) r[i] = bytes[i]; for (int i=0; i<256; i++) g[i] = bytes[256+i]; for (int i=0; i<256; i++) b[i] = bytes[512+i]; return new LUT(r, g, b); }
public void setChannelColorModel(IndexColorModel cm) { setChannelLut(new LUT(cm,0.0,0.0)); }
public void setChannelColorModel(IndexColorModel cm) { setChannelLut(new LUT(cm,0.0,0.0)); }
private LUT createFireLUT(double maxVal) { byte[][] lut = ColorMaps.createFireLut(256); byte[] red = new byte[256]; byte[] green = new byte[256]; byte[] blue = new byte[256]; for (int i = 0; i < 256; i++) { red[i] = lut[i][0]; green[i] = lut[i][1]; blue[i] = lut[i][2]; } IndexColorModel cm = new IndexColorModel(8, 256, red, green, blue); return new LUT(cm, 0, maxVal); }
private LUT createFireLUT(double maxVal) { byte[][] lut = ColorMaps.createFireLut(256); byte[] red = new byte[256]; byte[] green = new byte[256]; byte[] blue = new byte[256]; for (int i = 0; i < 256; i++) { red[i] = lut[i][0]; green[i] = lut[i][1]; blue[i] = lut[i][2]; } IndexColorModel cm = new IndexColorModel(8, 256, red, green, blue); return new LUT(cm, 0, maxVal); }
/** * Create fire look-up table * @param maxVal maximum intensity value * @return fire look-up table */ private LUT createFireLUT(double maxVal) { byte[][] lut = ColorMaps.createFireLut(256); byte[] red = new byte[256]; byte[] green = new byte[256]; byte[] blue = new byte[256]; for (int i = 0; i < 256; i++) { red[i] = lut[i][0]; green[i] = lut[i][1]; blue[i] = lut[i][2]; } IndexColorModel cm = new IndexColorModel(8, 256, red, green, blue); return new LUT(cm, 0, maxVal); }
public LUT getLut() { ColorModel cm2 = getColorModel(); if (cm2!=null && (cm2 instanceof IndexColorModel)) return new LUT((IndexColorModel)cm2, getMin(), getMax()); else return null; }
public static LUT getLut(final ColorTable cTable) { final byte[] reds = new byte[256]; final byte[] greens = new byte[256]; final byte[] blues = new byte[256]; for (int i = 0; i < 256; i++) { reds[i] = (byte) cTable.getResampled(ColorTable.RED, 256, i); greens[i] = (byte) cTable.getResampled(ColorTable.GREEN, 256, i); blues[i] = (byte) cTable.getResampled(ColorTable.BLUE, 256, i); } return new LUT(reds, greens, blues); } }
public LUT getLut() { ColorModel cm2 = getColorModel(); if (cm2!=null && (cm2 instanceof IndexColorModel)) return new LUT((IndexColorModel)cm2, getMin(), getMax()); else return null; }
private LUT createColorModel() throws FormatException, IOException { // NB: If a color table is present, we might as well use it, // regardless of the value of isIndexed. //if (!isIndexed()) return null; byte[][] byteTable = get8BitLookupTable(); if (byteTable == null) byteTable = convertTo8Bit(get16BitLookupTable()); if (byteTable == null || byteTable.length == 0) return null; // extract red, green and blue elements final int colors = byteTable.length; final int samples = byteTable[0].length; final byte[] r = colors >= 1 ? byteTable[0] : new byte[samples]; final byte[] g = colors >= 2 ? byteTable[1] : new byte[samples]; final byte[] b = colors >= 3 ? byteTable[2] : new byte[samples]; return new LUT(8, samples, r, g, b); }
private LUT createColorModel() throws FormatException, IOException { // NB: If a color table is present, we might as well use it, // regardless of the value of isIndexed. //if (!isIndexed()) return null; byte[][] byteTable = get8BitLookupTable(); if (byteTable == null) byteTable = convertTo8Bit(get16BitLookupTable()); if (byteTable == null || byteTable.length == 0) return null; // extract red, green and blue elements final int colors = byteTable.length; final int samples = byteTable[0].length; final byte[] r = colors >= 1 ? byteTable[0] : new byte[samples]; final byte[] g = colors >= 2 ? byteTable[1] : new byte[samples]; final byte[] b = colors >= 3 ? byteTable[2] : new byte[samples]; return new LUT(8, samples, r, g, b); }
/** * Makes an 8-bit LUT from a ColorTable. * <p> * ColorTable16's are merely down-sampled. If this is a non-false-color * image (i.e. the data is in the palette entries) data will be lost. For * false-color images (data is in the indices, palette is just for * visualization) the default palette is typically a ramp so the ColorTable8 * version is functionally equivalent. */ private LUT make8BitLUT(final ColorTable cTable) { final byte[] reds = new byte[256]; final byte[] greens = new byte[256]; final byte[] blues = new byte[256]; for (int i = 0; i < 256; i++) { reds [i] = (byte) cTable.getResampled(ColorTable.RED, 256, i); greens[i] = (byte) cTable.getResampled(ColorTable.GREEN, 256, i); blues [i] = (byte) cTable.getResampled(ColorTable.BLUE, 256, i); } return new LUT(reds, greens, blues); }
public LUT createInvertedLut() { int mapSize = getMapSize(); byte[] reds = new byte[mapSize]; byte[] greens = new byte[mapSize]; byte[] blues = new byte[mapSize]; byte[] reds2 = new byte[mapSize]; byte[] greens2 = new byte[mapSize]; byte[] blues2 = new byte[mapSize]; getReds(reds); getGreens(greens); getBlues(blues); for (int i=0; i<mapSize; i++) { reds2[i] = (byte)(reds[mapSize-i-1]&255); greens2[i] = (byte)(greens[mapSize-i-1]&255); blues2[i] = (byte)(blues[mapSize-i-1]&255); } return new LUT(8, mapSize, reds2, greens2, blues2); }
public LUT createInvertedLut() { int mapSize = getMapSize(); byte[] reds = new byte[mapSize]; byte[] greens = new byte[mapSize]; byte[] blues = new byte[mapSize]; byte[] reds2 = new byte[mapSize]; byte[] greens2 = new byte[mapSize]; byte[] blues2 = new byte[mapSize]; getReds(reds); getGreens(greens); getBlues(blues); for (int i=0; i<mapSize; i++) { reds2[i] = (byte)(reds[mapSize-i-1]&255); greens2[i] = (byte)(greens[mapSize-i-1]&255); blues2[i] = (byte)(blues[mapSize-i-1]&255); } return new LUT(8, mapSize, reds2, greens2, blues2); }
/** gets the color table from any kind of ImagePlus (composite or not) - not for general use */ private LUT getColorTable(ImagePlus imp, int channel) { if (imp instanceof CompositeImage) return ((CompositeImage)imp).getChannelLut(channel+1); // else a regular ImagePlus IndexColorModel icm = (IndexColorModel)imp.getProcessor().getColorModel(); // TODO - maybe I can cast from IndexColorModel to LUT here - depends what IJ did. // otherwise make a LUT byte[] reds = new byte[256], greens = new byte[256], blues = new byte[256]; icm.getReds(reds); icm.getGreens(greens); icm.getBlues(blues); return new LUT(reds,greens,blues); }