Changeset 6518


Ignore:
Timestamp:
06/10/10 15:26:16 (10 years ago)
Author:
bdezonia
Message:

further work on various methods

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/components/loci-plugins/test/loci/plugins/in/ImporterTest.java

    r6513 r6518  
    3636// TODO 
    3737 
    38 // questions: 
    39 //   does autoscale with Calibration need to be further fleshed out to calc min and max values or is checking the 
    40 //     calibration enough? It seems that the actual pixel vals don't factor in. Might be an issue for crop and autoscale. 
     38// seem broken but don't know status from Curtis 
     39//   colorized: 1/1/indexed (all indices 0 for all images), 3/1/indexed (iIndex,cIndex) (although w/ falseColor its okay), 
     40//     6/3/nonindexed (iIndex,cIndex), 12/3/nonindexed (iIndex,cIndex), 3/3/indexed (iIndex,cIndex) 
     41//   concat and split (returns wrong number of images per imp) 
     42//   record does not work 
     43 
     44// broken 
     45//   comboCropAndAutoscale for INT32. I think its a limitation of Fake. The values of the cropped image are outside 
     46//   the minimum represntable value of an int as a float. So when we make a FloatProcessor on the int[] data the 
     47//   huge negative values get clamped to the lowest representable point and thus max and min are not set correctly 
     48//   by IJ. I have verified that the pixel data that is sent to FloatProcessor() is correct. Limitation we'll live 
     49//   with I guess. 
     50 
     51// testable code according to my notes 
     52//   composite, gray, custom: working for 2 <= sizeC <= 7 and nonindexed (not yet tested) 
     53 
     54// unwritten 
     55//   color grayscale and color custom : hoping to adapt a working color colorized method for these. 
     56//   color composite: I don't remember Curtis telling me how this should work 
     57//   color default : Curtis never explained how this should work and code probably not in place 
    4158 
    4259// note 
     
    7693  private enum Axis {Z,C,T}; 
    7794   
    78   private enum ChannelOrder {ZTC, ZCT, CZT, CTZ, TZC, TCZ}; 
     95  private enum ChannelOrder {ZCT, ZTC, CZT, CTZ, TZC, TCZ}; 
    7996   
    8097  private static final boolean[] BooleanStates = new boolean[] {false, true}; 
    8198   
    8299  private static final int[] PixelTypes = new int[] { 
     100      FormatTools.FLOAT, FormatTools.DOUBLE, 
    83101      FormatTools.UINT8, FormatTools.UINT16, FormatTools.UINT32, 
    84       FormatTools.INT8,  FormatTools.INT16,  FormatTools.INT32, 
    85       FormatTools.FLOAT, FormatTools.DOUBLE 
     102      FormatTools.INT8,  FormatTools.INT16,  FormatTools.INT32 
    86103      }; 
    87104   
     
    355372  } 
    356373 
     374  // note - this code relies on setPosition(c,z,t) being called previously. Otherwise regular ImagePlus case won't work. 
     375  //   In general this method not designed for general use but actually just for use by getPixelValue(). 
     376   
    357377  private LUT getColorTable(ImagePlus imp, int channel) 
    358378  { 
     
    362382    // else a regular ImagePlus 
    363383     
    364     //if (channel != 0) 
    365     //  throw new IllegalArgumentException("getColorTable(): nonzero channel number requested of an ImagePlus."); 
    366      
    367     System.out.println("In here!!!!!"); 
    368      
    369     IndexColorModel icm = (IndexColorModel)imp.getStack().getColorModel(); 
     384    System.out.println("  getting color table from a regular ImagePlus."); 
     385     
     386    IndexColorModel icm = (IndexColorModel)imp.getProcessor().getColorModel(); 
    370387     
    371388    byte[] reds = new byte[256], greens = new byte[256], blues = new byte[256]; 
     
    382399  { 
    383400    // our indices are 0-based while IJ's are 1-based 
    384     if (imp instanceof CompositeImage) 
    385       ((CompositeImage)imp).setPosition(c+1, z+1, t+1); 
    386      
    387     int rawValue = (int)imp.getProcessor().getPixelValue(x, y); 
     401    imp.setPosition(c+1, z+1, t+1); 
     402     
     403    int rawValue = (int) (imp.getProcessor().getPixelValue(x, y)); 
    388404     
    389405    if (!indexed) 
     
    394410    LUT lut = getColorTable(imp,c); 
    395411    int value = lut.getRed(rawValue);  // since r g and b vals should be the same choose one arbitrarily. 
    396       // Use red in case lut len < 3 and zero fills other channels  
    397      
    398     System.out.println("  getPixelValue("+z+","+c+","+t+") = "+value); 
     412      // OR Use red in case lut len < 3 and zero fills other channels 
     413     
     414    System.out.println("  getPixelValue("+z+","+c+","+t+") = "+value+" (rawValue = "+rawValue+")"); 
    399415     
    400416    return value; 
     
    739755    } 
    740756 
    741     // workaround for IJ nonsupport of signed data 
     757    // if signed make sure Calibration is setup correctly 
    742758    if (FormatTools.isSigned(pixType) && !FormatTools.isFloatingPoint(pixType)) 
    743759    { 
    744       // TODO - this code could go in expectedMin/Max calc just above. Use coeffs[0] to bias the values. Still will be 
    745       //   broken for INT16 though because IJ always clamps the min/max to 0..65535. Note also that if this change is made 
    746       //   it should be replicated in cropAndAutoscale (or common code factored out and reused) 
    747        
    748760      Calibration cal = imp.getCalibration(); 
    749761      assertEquals(Calibration.STRAIGHT_LINE,cal.getFunction()); 
     
    753765      assertEquals(1,coeffs[1],0); 
    754766       
    755       //System.out.println("autoscale, pixType = ("+FormatTools.getPixelTypeString(pixType)+"), wantAutoscale "+wantAutoscale+ 
    756       //    " offset "+coeffs[0]); 
    757       //System.out.println("  min "+imp.getProcessor().getMin()+" max "+imp.getProcessor().getMax()); 
    758     } 
    759     else // regular case 
     767      // note - IJ clamps min and max to a range for ShortProcessor (unlike all other processors) 
     768      if (pixType == FormatTools.INT16)  // hack : clamp like IJ does 
     769      { 
     770        if (expectedMin < 0) 
     771          expectedMin = 0; 
     772        if (expectedMax > 65535) 
     773          expectedMax = 65535; 
     774      } 
     775    } 
     776     
     777    for (int i = 0; i < numSlices; i++) 
    760778    { 
    761       //System.out.println("Checking max/min of each processor"); 
    762       for (int i = 0; i < numSlices; i++) 
    763       { 
    764         //System.out.println("Trying proc #"+i+" of "+numSlices); 
    765         ImageProcessor proc = st.getProcessor(i+1); 
    766         assertEquals(expectedMax,proc.getMax(),0.1); 
    767         assertEquals(expectedMin,proc.getMin(),0.1); 
    768       } 
    769     } 
    770   } 
    771    
    772   private void colorCompositeTest(int pixType, boolean indexed, int rgb, boolean falseColor, int sizeX, int sizeY, int sizeZ, int sizeC, int sizeT, int numSeries) 
    773   { 
     779      ImageProcessor proc = st.getProcessor(i+1); 
     780      assertEquals(expectedMax,proc.getMax(),0.1); 
     781      assertEquals(expectedMin,proc.getMin(),0.1); 
     782    } 
     783  } 
     784   
     785  private void colorCompositeTest(int pixType, boolean indexed, int rgb, boolean falseColor, int sizeC, int numSeries) 
     786  { 
     787     
     788    int sizeX = 55, sizeY = 71, sizeZ = 3, sizeT = 4; 
     789     
    774790    // reportedly works in BF for 2<=sizeC<=7 and also numSeries*sizeC*3 <= 25 
    775791     
     
    803819     
    804820    imp = imps[0]; 
    805      
    806     xyzctTest(imp,sizeX,sizeY,sizeZ,sizeC,sizeT); 
     821 
     822    int lutLen = 3; 
     823     
     824    int expectedSizeC = sizeC; 
     825 
     826    if (indexed) 
     827    { 
     828      if (falseColor) 
     829        expectedSizeC /= rgb; 
     830      else // not falseColor 
     831        expectedSizeC *= lutLen; 
     832    } 
     833 
     834    xyzctTest(imp,sizeX,sizeY,sizeZ,expectedSizeC,sizeT); 
    807835     
    808836    assertTrue(imp.isComposite()); 
     
    814842    assertEquals(CompositeImage.COMPOSITE, ci.getMode()); 
    815843     
    816     colorTests(ci,sizeC,DefaultColorOrder); 
     844    colorTests(ci,expectedSizeC,DefaultColorOrder); 
    817845 
    818846    ci.reset();  // force the channel processors to get initialized, otherwise nullptr  - TODO : does this point out a IJ bug? 
     
    826854     
    827855    // check that each image in the overall series has the correct iIndex value 
    828     for (int z = 0; z < maxZ; z++) 
    829       for (int c = 0; c < maxC; c++) 
    830         for (int t = 0; t < maxT; t++) 
    831         { 
    832           assertEquals((maxZ*maxC*t + maxC*z + c), getIndexPixelValue(ci,z,c,t,indexed));  // expected value from CZT order 
    833         } 
     856    int index = 0; 
     857    for (int t = 0; t < maxT; t++) 
     858      for (int z = 0; z < maxZ; z++) 
     859        for (int c = 0; c < maxC; c++) 
     860          assertEquals(index++, getIndexPixelValue(ci,z,c,t,indexed));  // expected value from CZT order 
    834861  } 
    835862   
     
    839866     
    840867    int sizeX = 100, sizeY = 120, sizeZ = 1, sizeC = 1, sizeT = 1, rgb = 1; 
    841     boolean indexed = true; 
     868    boolean indexed = true, falseColor = false; 
    842869     
    843870    String path = constructFakeFilename("colorColorized", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, -1, indexed, rgb, false, -1); 
     
    864891    imp = imps[0]; 
    865892     
    866     xyzctTest(imp,sizeX,sizeY,sizeZ,sizeC,sizeT); 
     893    int lutLen = 3; 
     894     
     895    int expectedSizeC = sizeC; 
     896 
     897    if (indexed) 
     898    { 
     899      if (falseColor) 
     900        expectedSizeC /= rgb; 
     901      else // not falseColor 
     902        expectedSizeC *= lutLen; 
     903    } 
     904 
     905    xyzctTest(imp,sizeX,sizeY,sizeZ,expectedSizeC,sizeT); 
    867906     
    868907    assertTrue(imp.isComposite()); 
     
    874913    assertEquals(CompositeImage.COLOR, ci.getMode()); 
    875914     
    876     colorTests(ci,sizeC,DefaultColorOrder); 
     915    colorTests(ci,expectedSizeC,DefaultColorOrder); 
    877916 
    878917    fail("unfinished"); 
     
    11931232    long expectedMin = minPixelValue(pixType) + originCropX; 
    11941233 
     1234    // make sure Calibration is set correctly 
    11951235    if (FormatTools.isSigned(pixType) && !FormatTools.isFloatingPoint(pixType)) 
    11961236    { 
     
    12011241      assertEquals(-(Math.pow(2, (bitsPerPix-1))),coeffs[0],0); 
    12021242      assertEquals(1,coeffs[1],0); 
    1203     } 
    1204     else 
    1205       for (int i = 0; i < numSlices; i++) 
     1243       
     1244      // note - IJ clamps min and max to a range for ShortProcessor (unlike all other processors) 
     1245      if (pixType == FormatTools.INT16)  // hack : clamp like IJ does 
    12061246      { 
    1207         ImageProcessor proc = st.getProcessor(i+1); 
    1208         assertEquals(expectedMin,proc.getMin(),0.1); 
    1209         assertEquals(expectedMax,proc.getMax(),0.1); 
     1247        if (expectedMin < 0) 
     1248          expectedMin = 0; 
     1249        if (expectedMax > 65535) 
     1250          expectedMax = 65535; 
    12101251      } 
     1252    } 
     1253 
     1254    /* 
     1255    System.out.println("comboCropAutoScale :: PixType("+FormatTools.getPixelTypeString(pixType)+")"); 
     1256    System.out.println("  imp max min "+(long)imp.getProcessor().getMax()+" "+(long)imp.getProcessor().getMin()); 
     1257    System.out.println("  exp max min "+expectedMax+" "+expectedMin); 
     1258    */ 
     1259     
     1260    for (int i = 0; i < numSlices; i++) 
     1261    { 
     1262      ImageProcessor proc = st.getProcessor(i+1); 
     1263      assertEquals(expectedMin,proc.getMin(),0.1); 
     1264      assertEquals(expectedMax,proc.getMax(),0.1); 
     1265    } 
    12111266  } 
    12121267   
     
    12161271    // run split and concat at same time 
    12171272 
    1218     final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 3; 
     1273    final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 4; 
    12191274    final String path = constructFakeFilename("concatSplitZ", 
    12201275      FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, series, false, -1, false, -1); 
     
    12711326    // run split and concat at same time 
    12721327 
    1273     final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 3; 
     1328    final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 4; 
    12741329    final String path = constructFakeFilename("concatSplitC", 
    12751330      FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, series, false, -1, false, -1); 
     
    13251380    // run split and concat at same time 
    13261381 
    1327     final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 3; 
     1382    final int sizeX = 50, sizeY = 20, sizeZ = 5, sizeC = 3, sizeT = 7, series = 4; 
    13281383    final String path = constructFakeFilename("concatSplitT", 
    13291384      FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, series, false, -1, false, -1); 
     
    15661621 
    15671622    // these here to simplify debugging 
    1568     colorCompositeTest(FormatTools.UINT8,false,1,false,55,44,2,3,4,1); 
    1569     colorCompositeTest(FormatTools.UINT8,true,1,false,55,44,2,3,4,1); 
     1623    colorCompositeTest(FormatTools.UINT8,false,1,false,3,1); 
     1624    colorCompositeTest(FormatTools.UINT8,true,1,false,3,1); 
    15701625 
    15711626    int[] pixTypes = new int[] {FormatTools.UINT8}; 
    1572     int[] xs = new int[] {56}; 
    1573     int[] ys = new int[] {41}; 
    1574     int[] zs = new int[] {1,2}; 
    15751627    int[] cs = new int[] {2,3,4,5,6,7};  // all that BF/IJ supports right now 
    15761628    int[] ts = new int[] {1,2}; 
    15771629    int[] series = new int[] {1,2,3,4}; 
     1630    int[] rgbs = new int[]{1,2,3}; 
    15781631     
    15791632    for (int pixFormat : pixTypes) 
    1580       for (int x : xs) 
    1581         for (int y : ys) 
    1582           for (int z : zs) 
    1583             for (int c : cs) 
    1584               for (int t : ts) 
    1585                 for (int s : series) 
    1586                   if ((c*s*3) <= 25)  // IJ slider limitation 
    1587                     for (boolean indexed : BooleanStates) 
    1588                     { 
    1589                       //System.out.println("indexed "+indexed+" format "+pixFormat+" x "+x+" y "+y+" z "+z+" c "+c+" t "+t+" s "+s); 
    1590                       //colorCompositeTest(indexed,pixFormat,x,y,z,c,t,s); 
    1591                     } 
     1633      for (int c : cs) 
     1634        for (int t : ts) 
     1635          for (int s : series) 
     1636            if ((c*s*3) <= 25)  // IJ slider limitation 
     1637              for (int rgb : rgbs) 
     1638                for (boolean indexed : BooleanStates) 
     1639                  for (boolean falseColor : BooleanStates) 
     1640                  { 
     1641                    //System.out.println(" format "+pixFormat+"indexed "+indexed+" rgb "+rgb+" fasleColor "+falseColor+" c "+c+" s "+s); 
     1642                    colorCompositeTest(pixFormat,indexed,rgb,falseColor,c,s); 
     1643                  } 
    15921644  } 
    15931645   
     
    20052057  { 
    20062058    // try a simple test: single small byte type image  
    2007     comboCropAndAutoscaleTest(FormatTools.UINT8,100,80,1,1,1,70,40,25); 
     2059    comboCropAndAutoscaleTest(FormatTools.UINT8,240,240,1,1,1,70,40,25); 
    20082060     
    20092061    // try multiple dimensions 
    2010     comboCropAndAutoscaleTest(FormatTools.UINT8,84,63,4,3,2,51,15,13); 
     2062    comboCropAndAutoscaleTest(FormatTools.UINT8,240,240,4,3,2,51,15,13); 
    20112063     
    20122064    // try various pixTypes 
    20132065    for (int pixType : PixelTypes) 
    2014       comboCropAndAutoscaleTest(pixType,96,96,2,2,2,70,60,10); 
     2066      comboCropAndAutoscaleTest(pixType,240,240,2,2,2,225,225,10); 
    20152067  } 
    20162068   
     
    20222074 
    20232075  @Test 
    2024   public void testComboConcatSplit() 
     2076  public void testComboConcatSplitZ() 
    20252077  { 
    20262078    comboConcatSplitFocalPlanesTest(); 
     2079  } 
     2080 
     2081  @Test 
     2082  public void testComboConcatSplitC() 
     2083  { 
    20272084    comboConcatSplitChannelsTest(); 
     2085  } 
     2086 
     2087  @Test 
     2088  public void testComboConcatSplitT() 
     2089  { 
    20282090    comboConcatSplitTimepointsTest(); 
    20292091  } 
     
    21452207    imp = imps[0]; 
    21462208    
     2209    System.out.println("  Returned imp: Z = " +imp.getNSlices()+ " C = " +imp.getNChannels()+" T = "+imp.getNFrames()); 
     2210    for (int cIndex = 0; cIndex < imp.getNChannels(); cIndex++) 
     2211      for (int zIndex = 0; zIndex < imp.getNSlices(); zIndex++) 
     2212        for (int tIndex = 0; tIndex < imp.getNFrames(); tIndex++) 
     2213        { 
     2214          imp.setPosition(cIndex+1,zIndex+1,tIndex+1); 
     2215          ImageProcessor proc = imp.getProcessor(); 
     2216          printVals(proc); 
     2217        } 
     2218     
    21472219    int expectedSizeC = sizeC; 
    21482220     
     
    21732245      assertEquals(CompositeImage.COLOR, ci.getMode()); 
    21742246     
    2175       //colorTests(ci,expectedSizeC,DefaultColorOrder);  // TODO - was sizeC, also not passing (falseColor stuff needs to be impl???) 
     2247      // TODO - falseColor stuff needs to be impl 
     2248      if (!falseColor) 
     2249        colorTests(ci,expectedSizeC,DefaultColorOrder); 
    21762250       
    21772251    } 
    21782252    else 
    21792253      System.out.println("  Not a composite image"); 
    2180  
    2181     // TODO - this code was pulled out to allow mixing of CompImg and ImagePlus test code. Not working. 
    2182      
    2183     if (indexed) 
    2184       System.out.println("  colorColorizedTester() - MaxZ MaxC MaxT "+sizeZ+" "+expectedSizeC+" "+sizeT); 
    21852254 
    21862255    int iIndex = 0; 
     
    21882257      for (int tIndex = 0; tIndex < sizeT; tIndex++) 
    21892258        for (int zIndex = 0; zIndex < sizeZ; zIndex++) 
    2190           //getIndexPixelValue(imp, zIndex, cIndex, tIndex, indexed); 
    2191           assertEquals(iIndex++,getIndexPixelValue(imp, zIndex, cIndex, tIndex, indexed)); 
     2259          getIndexPixelValue(imp, zIndex, cIndex, tIndex, indexed); 
     2260          //assertEquals(iIndex++,getIndexPixelValue(imp, zIndex, cIndex, tIndex, indexed)); 
    21922261  } 
    21932262 
     
    22402309 
    22412310    /* 
    2242     for (int sizeC : new int[] {2,3,4,6,12})  // TODO: notice 1 not handled: IJ will not return a composite image of 1 chann - will need special test 
     2311    for (int sizeC : new int[] {1,2,3,4,6,12}) 
    22432312      for (int rgb : new int[] {1,2,3,4}) 
    22442313        if (sizeC % rgb == 0) 
    22452314          for (int pixType : new int[] {FormatTools.UINT8}) // TODO - add later FormatTools.UINT16 
    22462315            for (boolean indexed : BooleanStates) 
    2247               if (!indexed)  // if !indexed make sure falseColor is false to avoid illegal combo 
     2316              for (boolean falseColor : BooleanStates) 
    22482317              { 
    2249                 System.out.println("Colorized: pixT sizeC rgb indexed falseColor "+FormatTools.getPixelTypeString(pixType)+" "+sizeC+" "+rgb+" "+indexed+" "+false); 
    2250                 colorColorizedTester(pixType,sizeC,rgb,indexed,false,-1); 
     2318                if (!indexed && falseColor)  // if !indexed make sure falseColor is false to avoid illegal combo 
     2319                  continue; 
     2320                System.out.println("Colorized: pixType("+FormatTools.getPixelTypeString(pixType)+") sizeC("+sizeC+") rgb("+rgb+") indexed("+indexed+") falseColor("+falseColor+")"); 
     2321                colorColorizedTester(pixType,sizeC,rgb,indexed,falseColor,-1); 
    22512322              } 
    2252               else  // indexed == true 
    2253                 for (boolean falseColor : BooleanStates) 
    2254                 { 
    2255                   System.out.println("Colorized: pixT sizeC rgb indexed falseColor "+FormatTools.getPixelTypeString(pixType)+" "+sizeC+" "+rgb+" "+indexed+" "+falseColor); 
    2256                   colorColorizedTester(pixType,sizeC,rgb,indexed,falseColor,-1); 
    2257                 } 
    22582323    System.out.println("testColorizeSubcases() - past all cases"); 
    22592324    */ 
Note: See TracChangeset for help on using the changeset viewer.