Changeset 6295


Ignore:
Timestamp:
05/12/10 17:17:45 (10 years ago)
Author:
curtis
Message:

Fix autoscaling.

Location:
trunk/components/loci-plugins/src/loci/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/src/loci/plugins/in/ImagePlusReader.java

    r6284 r6295  
    335335    // concatenate compatible images 
    336336    if (options.isConcatenate()) imps = new Concatenator().concatenate(imps); 
    337      
     337 
    338338    // split dimensions, as appropriate 
    339339    boolean sliceC = options.isSplitChannels(); 
     
    381381    int tCount = options.getTCount(series); 
    382382    IFormatReader reader = process.getReader(); 
    383      
     383 
    384384    if (cCount == 0) cCount = reader.getEffectiveSizeC(); 
    385385    if (zCount == 0) zCount = reader.getSizeZ(); 
     
    405405    boolean hyper = options.isViewHyperstack() || options.isViewBrowser(); 
    406406    imp.setOpenAsHyperStack(hyper); 
    407     int nSlices = imp.getNSlices(); 
    408     int nFrames = imp.getNFrames(); 
    409  
    410     if (options.isAutoscale() && !options.isVirtual()) { 
    411       ImagePlusTools.adjustColorRange(imp, reader); 
     407 
     408    if (options.isAutoscale()) { 
     409      ImagePlusTools.adjustColorRange(imp, process.getMinMaxCalculator()); 
    412410    } 
    413411    else if (!(imp.getProcessor() instanceof ColorProcessor)) { 
     
    417415      imp.setDisplayRange(0, Math.pow(2, imp.getBitDepth()) - 1); 
    418416    } 
    419  
    420     imp.setDimensions(imp.getStackSize() / (nSlices * nFrames), 
    421       nSlices, nFrames); 
    422417 
    423418//    IFormatReader r = options.getReader(); 
  • trunk/components/loci-plugins/src/loci/plugins/in/ImportProcess.java

    r6293 r6295  
    4646import loci.formats.IFormatReader; 
    4747import loci.formats.ImageReader; 
     48import loci.formats.MinMaxCalculator; 
    4849import loci.formats.meta.IMetadata; 
    4950import loci.formats.services.OMEXMLService; 
     
    8889  private ChannelSeparator channelSeparator; 
    8990  private DimensionSwapper dimensionSwapper; 
     91  private MinMaxCalculator minMaxCalculator; 
    9092  private VirtualReader virtualReader; 
    9193  private ImageProcessorReader reader; 
     
    163165    assertStep(ImportStep.STACK); 
    164166    return dimensionSwapper; 
     167  } 
     168  /** Valid only after {@link ImportStep#STACK}. */ 
     169  public MinMaxCalculator getMinMaxCalculator() { 
     170    assertStep(ImportStep.STACK); 
     171    return minMaxCalculator; 
    165172  } 
    166173  /** Valid only after {@link ImportStep#STACK}. */ 
     
    359366    } 
    360367    r = dimensionSwapper = new DimensionSwapper(r); 
     368    r = minMaxCalculator = new MinMaxCalculator(r); 
    361369    r = virtualReader = new VirtualReader(r); 
    362370    reader = new ImageProcessorReader(r); 
  • trunk/components/loci-plugins/src/loci/plugins/util/ImagePlusTools.java

    r6279 r6295  
    174174 
    175175  /** 
    176    * Adjusts the color range of the given image stack 
     176   * Autoscales the color range of the given image stack 
    177177   * to match its global minimum and maximum. 
    178178   */ 
    179   public static void adjustColorRange(ImagePlus imp, IFormatReader r) { 
    180     ImageStack s = imp.getStack(); 
     179  public static void adjustColorRange(ImagePlus imp, 
     180    MinMaxCalculator minMaxCalc) 
     181  { 
    181182    double min = Double.MAX_VALUE; 
    182183    double max = Double.MIN_VALUE; 
    183184 
    184     if (r instanceof MinMaxCalculator) { 
    185       for (int c=0; c<r.getSizeC(); c++) { 
     185    // try to grab min and max values from the MinMaxCalculator 
     186    if (minMaxCalc != null) { 
     187      for (int c=0; c<minMaxCalc.getSizeC(); c++) { 
    186188        try { 
    187           Double cMin = ((MinMaxCalculator) r).getChannelGlobalMinimum(c); 
    188           Double cMax = ((MinMaxCalculator) r).getChannelGlobalMaximum(c); 
     189          Double cMin = minMaxCalc.getChannelGlobalMinimum(c); 
     190          Double cMax = minMaxCalc.getChannelGlobalMaximum(c); 
    189191 
    190192          if (cMin != null && cMin.doubleValue() < min) { 
     
    199201      } 
    200202    } 
     203 
     204    // couldn't find min and max values; determine manually 
    201205    if (min == Double.MAX_VALUE && max == Double.MIN_VALUE) { 
    202       for (int i=0; i<s.getSize(); i++) { 
    203         ImageProcessor p = s.getProcessor(i + 1); 
     206      ImageStack stack = imp.getStack(); 
     207      for (int i=0; i<stack.getSize(); i++) { 
     208        ImageProcessor p = stack.getProcessor(i + 1); 
    204209        p.resetMinAndMax(); 
    205210        if (p.getMin() < min) min = p.getMin(); 
     
    208213    } 
    209214 
     215    // assign min/max range to the active image processor 
    210216    ImageProcessor p = imp.getProcessor(); 
    211217    if (p instanceof ColorProcessor) { 
     
    213219    } 
    214220    else p.setMinAndMax(min, max); 
    215     imp.setProcessor(imp.getTitle(), p); 
     221    // HACK: refresh display 
     222    //imp.setProcessor(imp.getTitle(), p); 
    216223  } 
    217224 
Note: See TracChangeset for help on using the changeset viewer.