Changeset 6626


Ignore:
Timestamp:
07/01/10 18:59:10 (9 years ago)
Author:
curtis
Message:

Backport r6625 to 4.2 branch.

Location:
branches/4.2
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • branches/4.2

    • Property svn:mergeinfo changed
      /trunkmerged: 6625
  • branches/4.2/components

  • branches/4.2/components/bio-formats/src

  • branches/4.2/components/bio-formats/src/loci/formats/ChannelFiller.java

  • branches/4.2/components/bio-formats/src/loci/formats/ImageTools.java

  • branches/4.2/components/bio-formats/src/loci/formats/in/FakeReader.java

  • branches/4.2/components/bio-formats/src/loci/formats/services

  • branches/4.2/components/loci-plugins

  • branches/4.2/components/loci-plugins/src/loci/plugins

  • branches/4.2/components/loci-plugins/src/loci/plugins/in/Colorizer.java

    r6605 r6626  
    2828import ij.CompositeImage; 
    2929import ij.ImagePlus; 
     30import ij.process.ColorProcessor; 
     31import ij.process.ImageProcessor; 
    3032import ij.process.LUT; 
    3133 
     
    3335import java.awt.image.ColorModel; 
    3436import java.awt.image.IndexColorModel; 
     37import java.io.IOException; 
     38import java.util.Arrays; 
    3539import java.util.List; 
    3640 
    3741import loci.formats.ChannelFiller; 
    3842import loci.formats.DimensionSwapper; 
     43import loci.formats.FormatException; 
     44import loci.formats.MinMaxCalculator; 
    3945import loci.formats.FormatTools; 
    4046import loci.formats.ImageReader; 
     
    7379 
    7480    for (int i=0; i<imps.size(); i++) { 
    75       final ImagePlus imp = imps.get(i); 
     81      ImagePlus imp = imps.get(i); 
    7682      final int series = (Integer) imp.getProperty(ImagePlusReader.PROP_SERIES); 
    7783      reader.setSeries(series); 
     
    9399      } 
    94100 
     101      // compute color mode and LUTs to use 
    95102      int mode = -1; 
    96103      LUT[] luts; 
     
    139146      } 
    140147 
     148      // apply color mode and LUTs 
    141149      final boolean doComposite = !options.isViewStandard() && 
    142150        mode != -1 && cSize > 1 && cSize <= 7; 
     
    145153        if (luts != null) compImage.setLuts(luts); 
    146154        imps.set(i, compImage); 
     155        imp = compImage; 
    147156      } 
    148157      else { 
     
    157166        } 
    158167      } 
     168 
     169      applyDisplayRanges(imp, series); 
    159170    } 
    160171    return imps; 
     
    162173 
    163174  // -- Helper methods -- 
     175 
     176  private void applyDisplayRanges(ImagePlus imp, int series) { 
     177    final ImporterOptions options = process.getOptions(); 
     178    final ImageProcessorReader reader = process.getReader(); 
     179 
     180    final int pixelType = reader.getPixelType(); 
     181    final boolean autoscale = options.isAutoscale() || 
     182      FormatTools.isFloatingPoint(pixelType); // always autoscale float data 
     183 
     184    final int cSize = imp.getNChannels(); 
     185    final double[] cMin = new double[cSize]; 
     186    final double[] cMax = new double[cSize]; 
     187    Arrays.fill(cMin, Double.NaN); 
     188    Arrays.fill(cMax, Double.NaN); 
     189 
     190    if (autoscale) { 
     191      // extract display ranges for autoscaling 
     192      final MinMaxCalculator minMaxCalc = process.getMinMaxCalculator(); 
     193      final int cBegin = process.getCBegin(series); 
     194      final int cEnd = process.getCEnd(series); 
     195      final int cStep = process.getCStep(series); 
     196      for (int c=0; c<cSize; c++) { 
     197        final int cIndex = cBegin + c * cStep; 
     198        Double cMinVal = null, cMaxVal = null; 
     199        try { 
     200          cMinVal = minMaxCalc.getChannelGlobalMinimum(cIndex); 
     201          cMaxVal = minMaxCalc.getChannelGlobalMaximum(cIndex); 
     202        } 
     203        catch (FormatException exc) { } 
     204        catch (IOException exc) { } 
     205        if (cMinVal != null) cMin[c] = cMinVal; 
     206        if (cMaxVal != null) cMax[c] = cMaxVal; 
     207      } 
     208    } 
     209 
     210    // fill in default display ranges as appropriate 
     211    final int bitDepth = reader.getBitsPerPixel(); 
     212    // NB: ImageJ does not directly support signed data (it is merely 
     213    // unsigned data shifted downward by half via a "calibration"), 
     214    // so the following min and max values also work for signed. 
     215    final double min = 0; 
     216    final double max = Math.pow(2, bitDepth) - 1; 
     217    for (int c=0; c<cSize; c++) { 
     218      if (Double.isNaN(cMin[c])) cMin[c] = min; 
     219      if (Double.isNaN(cMax[c])) cMax[c] = max; 
     220    } 
     221 
     222    // apply display ranges 
     223    if (imp instanceof CompositeImage) { 
     224      // apply channel display ranges 
     225      final CompositeImage compImage = (CompositeImage) imp; 
     226      for (int c=0; c<cSize; c++) { 
     227        LUT lut = compImage.getChannelLut(c + 1); 
     228        lut.min = cMin[c]; 
     229        lut.max = cMax[c]; 
     230      } 
     231    } 
     232    else { 
     233      // compute global display range from channel display ranges 
     234      double globalMin = Double.POSITIVE_INFINITY; 
     235      double globalMax = Double.NEGATIVE_INFINITY; 
     236      for (int c=0; c<cSize; c++) { 
     237        if (cMin[c] < globalMin) globalMin = cMin[c]; 
     238        if (cMax[c] > globalMax) globalMax = cMax[c]; 
     239      } 
     240 
     241      // apply global display range 
     242      ImageProcessor proc = imp.getProcessor(); 
     243      if (proc instanceof ColorProcessor) { 
     244        // NB: Should never occur. ;-) 
     245        final ColorProcessor colorProc = (ColorProcessor) proc; 
     246        colorProc.setMinAndMax(min, max, 3); 
     247      } 
     248      else proc.setMinAndMax(min, max); 
     249    } 
     250  } 
    164251 
    165252  private LUT[] makeLUTs(ColorModel[] cm, boolean colorize) { 
     
    209296    } 
    210297    LUT lut = new LUT(r, g, b); 
    211     lut.min = 0; 
    212     lut.max = 255; 
    213298    return lut; 
    214299  } 
     300 
    215301} 
  • branches/4.2/components/loci-plugins/src/loci/plugins/in/ImagePlusReader.java

    r6605 r6626  
    412412    boolean hyper = !options.isViewStandard(); 
    413413    imp.setOpenAsHyperStack(hyper); 
    414  
    415     // apply intensity scaling 
    416     int pixelType = reader.getPixelType(); 
    417     // always autoscale floating point image data 
    418     if (options.isAutoscale() || FormatTools.isFloatingPoint(pixelType)) { 
    419       ImagePlusTools.adjustColorRange(imp, process.getMinMaxCalculator()); 
    420     } 
    421     else { 
    422       // ImageJ may autoscale the images anyway, so we need to manually set 
    423       // the display range to the min/max values allowed for this pixel type 
    424       int bitDepth = reader.getBitsPerPixel(); 
    425       // NB: ImageJ does not directly support signed data (it is merely 
    426       // unsigned data shifted downward by half via a "calibration"), 
    427       // so the following min and max values also work for signed. 
    428       double min = 0; 
    429       double max = Math.pow(2, bitDepth) - 1; 
    430       imp.setDisplayRange(min, max); 
    431     } 
    432414 
    433415    return imp; 
  • branches/4.2/components/loci-plugins/src/loci/plugins/util/ImagePlusTools.java

    r6589 r6626  
    111111  } 
    112112 
    113   /** 
    114    * Autoscales the color range of the given image stack 
    115    * to match its global minimum and maximum. 
    116    */ 
    117   public static void adjustColorRange(ImagePlus imp, 
    118     MinMaxCalculator minMaxCalc) 
    119   { 
    120     double min = Double.POSITIVE_INFINITY; 
    121     double max = Double.NEGATIVE_INFINITY; 
    122  
    123     // try to grab min and max values from the MinMaxCalculator 
    124     if (minMaxCalc != null) { 
    125       for (int c=0; c<minMaxCalc.getSizeC(); c++) { 
    126         try { 
    127           Double cMin = minMaxCalc.getChannelGlobalMinimum(c); 
    128           Double cMax = minMaxCalc.getChannelGlobalMaximum(c); 
    129  
    130           if (cMin != null && cMin.doubleValue() < min) { 
    131             min = cMin.doubleValue(); 
    132           } 
    133           if (cMax != null && cMax.doubleValue() > max) { 
    134             max = cMax.doubleValue(); 
    135           } 
    136         } 
    137         catch (FormatException e) { } 
    138         catch (IOException e) { } 
    139       } 
    140     } 
    141  
    142     // couldn't find min and max values; determine manually 
    143     if (min == Double.POSITIVE_INFINITY && max == Double.NEGATIVE_INFINITY) { 
    144       ImageStack stack = imp.getStack(); 
    145       for (int i=0; i<stack.getSize(); i++) { 
    146         ImageProcessor p = stack.getProcessor(i + 1); 
    147         p.resetMinAndMax(); 
    148         if (p.getMin() < min) min = p.getMin(); 
    149         if (p.getMax() > max) max = p.getMax(); 
    150       } 
    151     } 
    152  
    153     // assign min/max range to the active image processor 
    154     ImageProcessor p = imp.getProcessor(); 
    155     if (p instanceof ColorProcessor) { 
    156       ((ColorProcessor) p).setMinAndMax(min, max, 3); 
    157     } 
    158     else p.setMinAndMax(min, max); 
    159     // HACK: refresh display 
    160     //imp.setProcessor(imp.getTitle(), p); 
    161   } 
    162  
    163113  /** Reorder the given ImagePlus's stack. */ 
    164114  public static ImagePlus reorder(ImagePlus imp, String origOrder, 
  • branches/4.2/components/loci-plugins/src/loci/plugins/util/ImageProcessorReader.java

    r6589 r6626  
    229229    final byte[] g = colors >= 2 ? byteTable[1] : new byte[samples]; 
    230230    final byte[] b = colors >= 3 ? byteTable[2] : new byte[samples]; 
    231     LUT lut = new LUT(8, samples, r, g, b); 
    232     lut.min = 0; 
    233     lut.max = 255; 
    234     return lut; 
     231    return new LUT(8, samples, r, g, b); 
    235232  } 
    236233 
  • branches/4.2/components/stubs

Note: See TracChangeset for help on using the changeset viewer.