Changeset 6510


Ignore:
Timestamp:
06/09/10 14:59:48 (9 years ago)
Author:
bdezonia
Message:

further work related to testColorizedSubcases()

File:
1 edited

Legend:

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

    r6493 r6510  
    3434 
    3535// TODO 
     36 
     37// questions: 
     38//   does autoscale with Calibration need to be further fleshed out to calc min and max values or is checking the 
     39//     calibration enough? It seems that the actual pixel vals don't factor in. Might be an issue for crop and autoscale. 
     40 
     41// note 
     42//   I changed MemoryRecord from "Flip Horizontally" (which could not be found at runtime) to "Invert". Verified 
     43//     "Invert" is recordable and record("invert") getting called but doRecording is false for some reason. Also Curtis 
     44//     thought flip would be easier to use for predicting actual values rather than special case code with invert. As 
     45//     I'm only doing UINT8 for now this is not a problem. 
    3646 
    3747// waiting on BF implementations for 
     
    344354  } 
    345355 
     356  private LUT getColorTable(ImagePlus imp, int channel) 
     357  { 
     358    if (imp instanceof CompositeImage) 
     359      return ((CompositeImage)imp).getChannelLut(channel+1); 
     360     
     361    // else a regular ImagePlus 
     362     
     363    if (channel != 0) 
     364      throw new IllegalArgumentException("getColorTable(): nonzero channel number requested of an ImagePlus."); 
     365     
     366    // TODO - figure out what to do here ... do I get a ColorModel from Imp somehow and build a LUT to use? 
     367     
     368    return null; 
     369  } 
     370   
    346371  /** get the actual pixel value (lookup when data is indexed) of the index of a fake image at a given z,c,t */ 
     372  private int getPixelValue(int x,int y,ImagePlus imp, int z, int c, int t, boolean indexed) 
     373  { 
     374    // our indices are 0-based while IJ's are 1-based 
     375    if (imp instanceof CompositeImage) 
     376      ((CompositeImage)imp).setPosition(c+1, z+1, t+1); 
     377     
     378    int rawValue = (int)imp.getProcessor().getPixelValue(x, y); 
     379     
     380    if (!indexed) 
     381      return rawValue; 
     382 
     383    // otherwise indexed - lookup pixel value in LUT 
     384     
     385    LUT lut = getColorTable(imp,c); 
     386    int value = lut.getRed(rawValue);  // since r g and b vals should be the same choose one arbitrarily. 
     387      // Use red in case lut len < 3 and zero fills other channels  
     388     
     389    System.out.println("  getPixelValue("+z+","+c+","+t+") = "+value); 
     390     
     391    return value; 
     392  } 
     393   
    347394  private int getIndexPixelValue(CompositeImage ci, int z, int c, int t, boolean indexed) 
    348395  { 
    349     //  if I have numZ=2,numC=3,numT=4 then don't I have 24 images? why only testing c values makes a difference? 
    350  
    351     // our indices are 0-based while IJ's are 1-based 
    352     ci.setPosition(c+1, z+1, t+1); 
    353     int rawValue = iIndex(ci.getProcessor()); 
    354     //int rawValue = iIndex(ci.getProcessor(c+1)); 
    355     if (indexed) 
    356     { 
    357       //LUT lut = ci.getChannelLut(c+1); 
    358       LUT lut = ci.getChannelLut(); 
    359        
    360       System.out.println("    zct "+z+" "+c+" "+t+" rawVal "+rawValue); 
    361       System.out.println("    raw value A "+lut.getAlpha(rawValue)+" R "+lut.getRed(rawValue)+" G "+lut.getGreen(rawValue)+" B "+lut.getBlue(rawValue)); 
    362       int retVal = lut.getRGB(rawValue); 
    363       System.out.println("    retVal binary A "+((retVal&0xff000000L)>>24)+" R "+((retVal&0x00ff0000L)>>16)+" G "+((retVal&0x0000ff00L)>>8)+" B "+((retVal&0x000000ffL)>>0)); 
    364       retVal &= 0xffffff; // strip off alpha 
    365       System.out.println("    retVal after & binary A "+((retVal&0xff000000L)>>24)+" R "+((retVal&0x00ff0000L)>>16)+" G "+((retVal&0x0000ff00L)>>8)+" B "+((retVal&0x000000ffL)>>0)); 
    366       System.out.println("    retVal via funcs() A "+lut.getAlpha(retVal)+" R "+lut.getRed(retVal)+" G "+lut.getGreen(retVal)+" B "+lut.getBlue(retVal)); 
    367        
    368       System.out.println("    returning "+retVal); 
    369        
    370       return retVal; 
    371     } 
    372     else 
    373       return rawValue; 
     396    return getPixelValue(10,0,ci,z,c,t,indexed); 
    374397  } 
    375398   
     
    407430    lut.getGreens(greens); 
    408431    lut.getBlues(blues); 
     432     
     433    System.out.println("  expected min rgb : "+minR+" "+minG+" "+minB); 
     434    System.out.println("  expected max rgb : "+maxR+" "+maxG+" "+maxB); 
     435    System.out.println("  actual min rgb : "+reds[0]+" "+greens[0]+" "+blues[0]); 
     436    System.out.println("  actual max rgb : "+(reds[255]&0xff)+" "+(greens[255]&0xff)+" "+(blues[255]&0xff)); 
    409437     
    410438    assertEquals((byte)minR,reds[0]); 
     
    703731    if (FormatTools.isSigned(pixType) && !FormatTools.isFloatingPoint(pixType)) 
    704732    { 
     733      // TODO - this code could go in expectedMin/Max calc just above. Use coeffs[0] to bias the values. Still will be 
     734      //   broken for INT16 though because IJ always clamps the min/max to 0..65535. Note also that if this change is made 
     735      //   it should be replicated in cropAndAutoscale (or common code factored out and reused) 
     736       
    705737      Calibration cal = imp.getCalibration(); 
    706738      assertEquals(Calibration.STRAIGHT_LINE,cal.getFunction()); 
     
    709741      assertEquals(-(Math.pow(2, (bitsPerPix-1))),coeffs[0],0); 
    710742      assertEquals(1,coeffs[1],0); 
     743       
     744      //System.out.println("autoscale, pixType = ("+FormatTools.getPixelTypeString(pixType)+"), wantAutoscale "+wantAutoscale+ 
     745      //    " offset "+coeffs[0]); 
     746      //System.out.println("  min "+imp.getProcessor().getMin()+" max "+imp.getProcessor().getMax()); 
    711747    } 
    712748    else // regular case 
     
    791827    // TODO: temp first attempt: sizeC == 1 and rgb matches 
    792828     
    793     int sizeX = 100, sizeY = 120, sizeZ = 1, sizeC = 1, sizeT = 1, numSeries = 1, rgb = 1; 
     829    int sizeX = 100, sizeY = 120, sizeZ = 1, sizeC = 1, sizeT = 1, rgb = 1; 
    794830    boolean indexed = true; 
    795831     
    796     String path = constructFakeFilename("colorColorized", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed, rgb, false, -1); 
     832    String path = constructFakeFilename("colorColorized", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, -1, indexed, rgb, false, -1); 
    797833     
    798834    ImagePlus[] imps = null; 
     
    834870  private void colorGrayscaleTest() 
    835871  { 
    836     int sizeX = 100, sizeY = 120, sizeZ = 2, sizeC = 7, sizeT = 4, numSeries = 3; 
    837      
    838     String path = constructFakeFilename("colorGrayscale", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, false, -1, false, -1); 
     872    int sizeX = 100, sizeY = 120, sizeZ = 2, sizeC = 7, sizeT = 4; 
     873     
     874    String path = constructFakeFilename("colorGrayscale", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, -1, false, -1, false, -1); 
    839875     
    840876    ImagePlus[] imps = null; 
     
    903939    } 
    904940 
     941    // TODO - notice numSeries passed in but never tested against 
     942     
    905943    impsCountTest(imps,1); 
    906944     
     
    10021040      int tFrom, int tTo, int tBy) 
    10031041  {  
    1004     int pixType = FormatTools.UINT8, x=50, y=5, s=-1; 
    1005     String path = constructFakeFilename("range", pixType, x, y, z, c, t, s, false, -1, false, -1); 
     1042    int pixType = FormatTools.UINT8, x=50, y=5; 
     1043    String path = constructFakeFilename("range", pixType, x, y, z, c, t, -1, false, -1, false, -1); 
    10061044    ImagePlus[] imps = null; 
    10071045    try { 
     
    10661104    assertTrue(oy + cropSize <= y); 
    10671105     
    1068     String path = constructFakeFilename("crop", FormatTools.UINT8, x, y, 1, 1, 1, 1, false, -1, false, -1); 
     1106    String path = constructFakeFilename("crop", FormatTools.UINT8, x, y, 1, 1, 1, -1, false, -1, false, -1); 
    10691107     
    10701108    // open image 
     
    11011139      int originCropX, int originCropY, int sizeCrop) 
    11021140  { 
    1103     final String path = constructFakeFilename("cropAutoscale",pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, 1, false, -1, false, -1); 
     1141    final String path = constructFakeFilename("cropAutoscale",pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, -1, false, -1, false, -1); 
    11041142     
    11051143    // needed for this test 
     
    11981236      assertEquals(series*sizeC*sizeT,st.getSize()); 
    11991237      for (int s = 0; s < series; s++) { 
    1200         int index = 1; // IJ 1-based 
     1238        int index = s*sizeC*sizeT; 
    12011239        for (int t = 0; t < sizeT; t++) { 
    12021240          for (int c = 0; c < sizeC; c++) { 
    12031241            //System.out.println("index "+index); 
    1204             ImageProcessor proc = st.getProcessor(s*sizeT*sizeC + index++); 
     1242            ImageProcessor proc = st.getProcessor(++index); 
    12051243            //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); 
    12061244            //System.out.println("z c t "+z+" "+c+" "+t); 
     
    12531291      assertEquals(series*sizeZ*sizeT,st.getSize()); 
    12541292      for (int s = 0; s < series; s++) { 
    1255         int index = 1; 
     1293        int index = s*sizeZ*sizeT; 
    12561294        for (int t = 0; t < sizeT; t++) { 
    12571295          for (int z = 0; z < sizeZ; z++) { 
    1258             ImageProcessor proc = st.getProcessor(s*sizeZ*sizeT + index++); 
     1296            ImageProcessor proc = st.getProcessor(++index); 
    12591297            //System.out.println("index "+index); 
    12601298            //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); 
     
    13071345      assertEquals(series*sizeZ*sizeC,st.getSize()); 
    13081346      for (int s = 0; s < series; s++) { 
    1309         int index = 1; 
     1347        int index = s*sizeZ*sizeC; 
    13101348        for (int c = 0; c < sizeC; c++) { 
    13111349          for (int z = 0; z < sizeZ; z++) { 
    1312             ImageProcessor proc = st.getProcessor(s*sizeZ*sizeC + index++); 
     1350            ImageProcessor proc = st.getProcessor(++index); 
    13131351            //System.out.println("index "+index); 
    13141352            //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); 
     
    14781516  public void testColorDefault() 
    14791517  { 
    1480     int sizeX = 100, sizeY = 120, sizeZ = 2, sizeC = 7, sizeT = 4, numSeries = 3; 
    1481      
    1482     String path = constructFakeFilename("colorDefault", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, false, -1, false, -1); 
     1518    int sizeX = 100, sizeY = 120, sizeZ = 2, sizeC = 7, sizeT = 4; 
     1519     
     1520    String path = constructFakeFilename("colorDefault", FormatTools.UINT8, sizeX, sizeY, sizeZ, sizeC, sizeT, -1, false, -1, false, -1); 
    14831521     
    14841522    ImagePlus[] imps = null; 
     
    20682106    int totalPlanes = totalChannels / channelsPerPlane; 
    20692107 
    2070     // TODO: necessary? 
    2071     /* 
    20722108    if (channelsPerPlane > 7) 
    20732109      throw new IllegalArgumentException("colorColorizedTester() passed bad sizeC - channelsPerPlane > 7 : "+channelsPerPlane); 
    2074     */ 
    20752110     
    20762111    int sizeX = 60, sizeY = 30, sizeZ = 1, sizeT = 1, numSeries = 1; 
     
    21262161      assertEquals(CompositeImage.COLOR, ci.getMode()); 
    21272162     
    2128       colorTests(ci,sizeC,DefaultColorOrder); 
     2163      //colorTests(ci,expectedSizeC,DefaultColorOrder);  // TODO - was sizeC, also not passing (falseColor stuff needs to be impl???) 
    21292164       
    21302165      if (indexed) 
     
    21352170        for (int tIndex = 0; tIndex < sizeT; tIndex++) 
    21362171          for (int zIndex = 0; zIndex < sizeZ; zIndex++) 
    2137             //getIndexPixelValue(ci, zIndex, cIndex, tIndex, indexed); 
    2138             assertEquals(iIndex++,getIndexPixelValue(ci, zIndex, cIndex, tIndex, indexed)); 
    2139     } 
     2172            getIndexPixelValue(ci, zIndex, cIndex, tIndex, indexed); 
     2173            //assertEquals(iIndex++,getIndexPixelValue(ci, zIndex, cIndex, tIndex, indexed)); 
     2174    } 
     2175    else 
     2176      System.out.println("  Not a composite image"); 
    21402177  } 
    21412178 
     
    21482185     
    21492186    // sizeC == 1, rgb == 1, indexed, 8 bit, implicit lut length of 3 - KEY test to do, also note can vary lut len 
    2150     System.out.println("A"); 
    2151     //colorColorizedTester(FormatTools.UINT8,1,1,true,false,-1); 
    2152     System.out.println("B"); 
    2153     //colorColorizedTester(FormatTools.UINT8,1,1,true,true,-1); 
    2154     System.out.println("C"); 
    2155     //colorColorizedTester(FormatTools.UINT8,1,1,true,false,4); 
     2187    System.out.println("1/1 indexed"); 
     2188    colorColorizedTester(FormatTools.UINT8,1,1,true,false,-1); 
     2189    System.out.println("1/1 indexed falseColor"); 
     2190    colorColorizedTester(FormatTools.UINT8,1,1,true,true,-1); 
     2191    System.out.println("1/1/indexed lutLen==2"); 
     2192    colorColorizedTester(FormatTools.UINT8,1,1,true,false,2); 
    21562193     
    21572194    // sizeC = 3 and rgb = 1 
    2158     System.out.println("D"); 
    2159     //colorColorizedTester(FormatTools.UINT8,3,1,true,false,-1); 
    2160     System.out.println("E"); 
     2195    System.out.println("3/1 indexed"); 
     2196    colorColorizedTester(FormatTools.UINT8,3,1,true,false,-1); 
     2197    System.out.println("3/1 indexed falseColor"); 
    21612198    colorColorizedTester(FormatTools.UINT8,3,1,true,true,-1); 
    21622199 
    21632200    // sizeC = 3 and rgb = 3 : interleaved 
    2164     System.out.println("F"); 
    2165     //colorColorizedTester(FormatTools.UINT8,3,3,true,false,-1); 
    2166     System.out.println("G"); 
     2201    System.out.println("3/3 indexed"); 
     2202    colorColorizedTester(FormatTools.UINT8,3,3,true,false,-1); 
     2203    System.out.println("3/3 indexed falseColor"); 
    21672204    colorColorizedTester(FormatTools.UINT8,3,3,true,true,-1); 
    21682205 
     
    21732210    // sizeC = 4 and rgb = 4 : interleaved including alpha 
    21742211    // if indexed == true this combo throws exception in CompositeImage constructor 
    2175     System.out.println("H"); 
     2212    System.out.println("4/4 nonindexed"); 
    21762213    colorColorizedTester(FormatTools.UINT8,4,4,false,false,-1); 
    21772214 
    21782215    // sizeC = 6, rgb = 3, indexed = false 
    21792216    // if indexed == true this combo throws exception in CompositeImage constructor 
    2180     System.out.println("I"); 
     2217    System.out.println("6/3 nonindexed"); 
    21812218    colorColorizedTester(FormatTools.UINT8,6,3,false,false,-1); 
    21822219    
    21832220    // sizeC = 12, rgb = 3, indexed = false 
    2184     System.out.println("J"); 
     2221    System.out.println("12/3 nonindexed"); 
    21852222    colorColorizedTester(FormatTools.UINT8,12,3,false,false,-1); 
    21862223 
Note: See TracChangeset for help on using the changeset viewer.