Changeset 6534


Ignore:
Timestamp:
06/18/10 13:18:49 (9 years ago)
Author:
melissa
Message:

Fixed a few issues with 16-bit LUTs.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2/components/bio-formats/src/loci/formats/in/FV1000Reader.java

    r6503 r6534  
    200200  public short[][] get16BitLookupTable() { 
    201201    FormatTools.assertId(currentId, true, 1); 
    202     return lut == null ? null : lut[lastChannel]; 
     202    return lut == null || !isIndexed() ? null : lut[lastChannel]; 
    203203  } 
    204204 
  • branches/4.2/components/bio-formats/src/loci/formats/in/LIFReader.java

    r6495 r6534  
    179179  public byte[][] get8BitLookupTable() { 
    180180    FormatTools.assertId(currentId, true, 1); 
    181     if (getPixelType() != FormatTools.UINT8) return null; 
     181    if (getPixelType() != FormatTools.UINT8 || !isIndexed()) return null; 
    182182    return lastChannel < BYTE_LUTS.length ? BYTE_LUTS[lastChannel] : null; 
    183183  } 
     
    186186  public short[][] get16BitLookupTable() { 
    187187    FormatTools.assertId(currentId, true, 1); 
    188     if (getPixelType() != FormatTools.UINT16) return null; 
     188    if (getPixelType() != FormatTools.UINT16 || !isIndexed()) return null; 
    189189    return lastChannel < SHORT_LUTS.length ? SHORT_LUTS[lastChannel] : null; 
    190190  } 
  • branches/4.2/components/loci-plugins/src/loci/plugins/util/ImageProcessorReader.java

    r6524 r6534  
    231231    byte[][] byteTable = new byte[shortTable.length][256]; 
    232232    for (int c=0; c<byteTable.length; c++) { 
    233       int len = Math.min(byteTable.length, shortTable[c].length); 
    234       for (int i=0; i<len; i++) byteTable[c][i] = (byte) shortTable[c][i]; 
     233      int len = Math.min(byteTable[c].length, shortTable[c].length); 
     234 
     235      for (int i=0; i<len; i++) { 
     236        // NB: you could generate the 8-bit LUT by casting the first 256 samples 
     237        // in the 16-bit LUT to bytes.  However, this will not produce optimal 
     238        // results; in many cases, you will end up with a completely black 
     239        // 8-bit LUT even if the original 16-bit LUT contained non-zero samples. 
     240        // 
     241        // Another option would be to scale every 256th value in the 16-bit LUT; 
     242        // this may be a bit faster, but will be less accurate than the 
     243        // averaging approach taken below. 
     244 
     245        int valuesPerBin = shortTable[c].length / byteTable[c].length; 
     246        double average = 0; 
     247        for (int p=0; p<valuesPerBin; p++) { 
     248          average += shortTable[c][i * valuesPerBin + p]; 
     249        } 
     250        average /= valuesPerBin; 
     251        byteTable[c][i] = (byte) (255 * (average / 65535.0)); 
     252      } 
    235253    } 
    236254    return byteTable; 
  • trunk/components/bio-formats/src/loci/formats/in/FV1000Reader.java

    r6531 r6534  
    201201  public short[][] get16BitLookupTable() { 
    202202    FormatTools.assertId(currentId, true, 1); 
    203     return lut == null ? null : lut[lastChannel]; 
     203    return lut == null || !isIndexed() ? null : lut[lastChannel]; 
    204204  } 
    205205 
  • trunk/components/bio-formats/src/loci/formats/in/LIFReader.java

    r6495 r6534  
    179179  public byte[][] get8BitLookupTable() { 
    180180    FormatTools.assertId(currentId, true, 1); 
    181     if (getPixelType() != FormatTools.UINT8) return null; 
     181    if (getPixelType() != FormatTools.UINT8 || !isIndexed()) return null; 
    182182    return lastChannel < BYTE_LUTS.length ? BYTE_LUTS[lastChannel] : null; 
    183183  } 
     
    186186  public short[][] get16BitLookupTable() { 
    187187    FormatTools.assertId(currentId, true, 1); 
    188     if (getPixelType() != FormatTools.UINT16) return null; 
     188    if (getPixelType() != FormatTools.UINT16 || !isIndexed()) return null; 
    189189    return lastChannel < SHORT_LUTS.length ? SHORT_LUTS[lastChannel] : null; 
    190190  } 
  • trunk/components/loci-plugins/src/loci/plugins/util/ImageProcessorReader.java

    r6481 r6534  
    231231    byte[][] byteTable = new byte[shortTable.length][256]; 
    232232    for (int c=0; c<byteTable.length; c++) { 
    233       int len = Math.min(byteTable.length, shortTable[c].length); 
    234       for (int i=0; i<len; i++) byteTable[c][i] = (byte) shortTable[c][i]; 
     233      int len = Math.min(byteTable[c].length, shortTable[c].length); 
     234 
     235      for (int i=0; i<len; i++) { 
     236        // NB: you could generate the 8-bit LUT by casting the first 256 samples 
     237        // in the 16-bit LUT to bytes.  However, this will not produce optimal 
     238        // results; in many cases, you will end up with a completely black 
     239        // 8-bit LUT even if the original 16-bit LUT contained non-zero samples. 
     240        // 
     241        // Another option would be to scale every 256th value in the 16-bit LUT; 
     242        // this may be a bit faster, but will be less accurate than the 
     243        // averaging approach taken below. 
     244 
     245        int valuesPerBin = shortTable[c].length / byteTable[c].length; 
     246        double average = 0; 
     247        for (int p=0; p<valuesPerBin; p++) { 
     248          average += shortTable[c][i * valuesPerBin + p]; 
     249        } 
     250        average /= valuesPerBin; 
     251        byteTable[c][i] = (byte) (255 * (average / 65535.0)); 
     252      } 
    235253    } 
    236254    return byteTable; 
Note: See TracChangeset for help on using the changeset viewer.