Changeset 6530
 Timestamp:
 06/15/10 14:59:01 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/components/lociplugins/test/loci/plugins/in/ImporterTest.java
r6529 r6530 37 37 38 38 // left off 39 // got compositeTestSubcases to work using seriesInSpecificOrder(). Have not modified seriesInZctOrder() to work for indexed 40 // data (see TODO there and try again) 39 // also maybe phase out *Index(ImageProcessor) to support indexed data 40 // also add pixelsTest() where necessary 41 // also expand compositeTestSubcases() to handle more pixTypes and indexed data 41 42 42 43 // seem broken but don't know status from Curtis … … 297 298 298 299 /** Tests that an ImageStack is ordered ZCT according to specified from/to/by points of z/c/t */ 299 private boolean seriesInZctOrder(ImagePlus imp, boolean indexed,300 private void seriesInZctOrderTest(ImagePlus imp, boolean indexed, 300 301 int zFrom, int zTo, int zBy, 301 302 int cFrom, int cTo, int cBy, … … 305 306 int cs = numInSeries(cFrom,cTo,cBy); 306 307 int ts = numInSeries(tFrom,tTo,tBy); 307 308 308 309 ImageStack st = imp.getStack(); 309 310 310 if ((zs * cs * ts) != st.getSize()) 311 { 312 System.out.println("seriesInZctOrder()  slices don't add up: z"+zs+" X c"+cs+" X t"+ts+" != "+st.getSize()); 313 return false; 314 } 315 316 int procNum = 1; 317 for (int t = tFrom; t <= tTo; t += tBy) 318 for (int c = cFrom; c <= cTo; c += cBy) 319 for (int z = zFrom; z <= zTo; z += zBy) 311 assertTrue((zs * cs * ts) == st.getSize()); 312 313 for (int t = 0; t < ts; t++) 314 for (int c = 0; c < cs; c++) 315 for (int z = 0; z < zs; z++) 320 316 { 321 int zIndex=0, cIndex=0, tIndex=0; 317 int zIndex = zIndex(imp,z,c,t,indexed); 318 int cIndex = cIndex(imp,z,c,t,indexed); 319 int tIndex = tIndex(imp,z,c,t,indexed); 322 320 323 // TODO  this code fails with C/Z calced in wrong order  determine why 324 325 //zIndex = zIndex(imp,z,c,t,indexed); 326 //cIndex = cIndex(imp,z,c,t,indexed); 327 //tIndex = tIndex(imp,z,c,t,indexed); 328 329 //System.out.println(" after wrong way z("+imp.getSlice()+") c("+imp.getChannel()+") t("+imp.getFrame()+")"); 330 331 // TODO  this code works but can't support indexed data 332 333 ImageProcessor proc = imp.getStack().getProcessor(procNum); 334 335 zIndex = zIndex(proc); 336 cIndex = cIndex(proc); 337 tIndex = tIndex(proc); 338 339 //System.out.println(" after right way z("+imp.getSlice()+") c("+imp.getChannel()+") t("+imp.getFrame()+")"); 340 341 if ((zIndex != z)  (cIndex != c)  (tIndex != t)) 342 { 343 System.out.println("seriesInZctOrder()  slices out of order: expZ("+z+") expC("+c+") expT("+t+") != actZ("+ 344 zIndex+") actC("+cIndex+") actT("+tIndex+") for proc number "+procNum); 345 return false; 346 } 347 procNum++; 321 int zVal = zFrom + z*zBy; 322 int cVal = cFrom + c*cBy; 323 int tVal = tFrom + t*tBy; 324 325 assertEquals(zVal,zIndex); 326 assertEquals(cVal,cIndex); 327 assertEquals(tVal,tIndex); 348 328 } 349 350 return true; 351 } 352 353 private int[][] indicesInZctOrder(int maxZ, int maxC, int maxT) 329 } 330 331 /** returns a set of indices ordered as ZCT */ 332 private int[][] getIndicesInZctOrder(int maxZ, int maxC, int maxT) 354 333 { 355 334 int[][] indices = new int[maxZ*maxC*maxT][3]; … … 366 345 } 367 346 return indices; 368 }369 370 /** one off method to test that stack order is correct */371 private boolean seriesInSpecificOrder(ImagePlus imp, boolean indexed, int maxZ, int maxC, int maxT)372 {373 ImageStack st = imp.getStack();374 375 if ((maxZ * maxC * maxT) != st.getSize())376 {377 System.out.println("seriesInSpecificOrder()  slices don't add up: z"+maxZ+" X c"+maxC+" X t"+maxT+" != "+st.getSize());378 return false;379 }380 381 // note  this is confusing here but the images are stored in CZT order but the image indices follow ZCT order382 // TODO  verify this is correct behavior383 384 int[][] indices = indicesInZctOrder(maxZ,maxC,maxT);385 386 int procNum = 0;387 for (int t = 0; t < maxT; t++)388 for (int z = 0; z < maxZ; z++)389 for (int c = 0; c < maxC; c++)390 {391 int sIndex = sIndex(imp,z,c,t,indexed);392 int iIndex = iIndex(imp,z,c,t,indexed);393 int zIndex = zIndex(imp,z,c,t,indexed);394 int cIndex = cIndex(imp,z,c,t,indexed);395 int tIndex = tIndex(imp,z,c,t,indexed);396 397 int expectedS = 0;398 int expectedI = procNum;399 int expectedZ = indices[procNum][0];400 int expectedC = indices[procNum][1];401 int expectedT = indices[procNum][2];402 403 if ((zIndex != expectedZ)  (cIndex != expectedC)  (tIndex != expectedT)  (iIndex != expectedI)  (sIndex != expectedS))404 {405 System.out.println("seriesInSpecificOrder()  slices out of order: expS("+expectedS+") expI("+expectedI+") expZ("+expectedZ+") expC("+expectedC+") expT("+406 expectedT+") != actS("+sIndex+") actI("+iIndex+") actZ("+zIndex+") actC("+cIndex+") actT("+tIndex+") for proc number "+(procNum+1));407 return false;408 }409 410 procNum++;411 }412 413 return true;414 347 } 415 348 … … 504 437 } 505 438 506 private void mySetPos(ImagePlus imp,int z, int c, int t, int maxZ, int maxC, int maxT) 507 { 508 imp.setSlice(t*maxC*maxZ + c*maxZ + z); 509 } 510 439 private void setCztPosition(ImagePlus imp, int z, int c, int t) 440 { 441 // czt order : should match the .setPosition(c,z,t) code 442 int sliceNumber = c + (z*imp.getNChannels()) + (t*imp.getNSlices()*imp.getNChannels()); 443 imp.setSlice(sliceNumber+1); 444 } 445 446 /** set an ImagePlus' position relative to ZCT ordering (rather than default CZT) */ 447 private void setZctPosition(ImagePlus imp, int z, int c, int t) 448 { 449 // zct order 450 int sliceNumber = z + (c*imp.getNSlices()) + (t*imp.getNSlices()*imp.getNChannels()); 451 imp.setSlice(sliceNumber+1); 452 } 453 511 454 /** get the actual pixel value (lookup when data is indexed) of the index of a fake image at a given z,c,t */ 512 455 private int getPixelValue(int x,int y, ImagePlus imp, int z, int c, int t, boolean indexed) 513 456 { 514 457 // our indices are 0based while IJ's are 1based 515 imp.setPosition(c+1, z+1, t+1); // TODO  old way 516 //mySetPos(imp,z,c,t,imp.getNSlices(),imp.getNChannels(),imp.getNFrames()); // TODO  why doesn't this result in correct behavior? 458 //imp.setPosition(c+1, z+1, t+1); 459 //setCztPosition(imp,z,c,t); 460 setZctPosition(imp,z,c,t); 517 461 518 462 int rawValue = (int) (imp.getProcessor().getPixelValue(x, y)); … … 637 581 } 638 582 583 /** tests that a FakeFile dataset has index values in ZCT order  needed for compositeTester() */ 639 584 private void stackInSpecificOrderTest(ImagePlus imp, int maxZ, int maxC, int maxT, boolean indexed) 640 585 { … … 642 587 643 588 if ((maxZ * maxC * maxT) != st.getSize()) 644 { 645 System.out.println("testStackInSpecificOrder()  slices don't add up: z"+maxZ+" X c"+maxC+" X t"+maxT+" != "+st.getSize()); 646 throw new IllegalArgumentException(); 647 } 648 649 // note  this is confusing here but the images are stored in CZT order but the image indices follow ZCT order 650 // TODO  verify this is correct behavior 651 652 int[][] indices = indicesInZctOrder(maxZ,maxC,maxT); 653 589 fail("testStackInSpecificOrder()  slices don't add up: z"+maxZ+" X c"+maxC+" X t"+maxT+" != "+st.getSize()); 590 654 591 int iIndex = 0; 655 592 for (int t = 0; t < maxT; t++) 656 for (int z = 0; z < maxZ; z++)657 for (int c = 0; c < maxC; c++)593 for (int c = 0; c < maxC; c++) 594 for (int z = 0; z < maxZ; z++) 658 595 { 659 596 int expectedS = 0; 660 597 int expectedI = iIndex; 661 int expectedZ = indices[iIndex][0];662 int expectedC = indices[iIndex][1];663 int expectedT = indices[iIndex][2];598 int expectedZ = z; 599 int expectedC = c; 600 int expectedT = t; 664 601 665 602 iIndex++; … … 667 604 indexValuesTest(imp,z,c,t,indexed,expectedS,expectedI,expectedZ,expectedC,expectedT); 668 605 } 606 } 607 608 /** tests that the pixel values of a FakeFile are as expected */ 609 private void pixelsTest(ImagePlus imp, int pixType, boolean indexed) 610 { 611 assertTrue(pixType == FormatTools.UINT8); // TODO  for now 612 assertTrue(imp.getHeight() > 10); 613 614 int max = imp.getWidth(); 615 if (max > 255) max = 255; 616 617 for (int t = 0; t < imp.getNFrames(); t++) 618 for (int c = 0; c < imp.getNChannels(); c++) 619 for (int z = 0; z < imp.getNSlices(); z++) 620 for (int i = 0; i < max; i++) 621 assertEquals(i,getPixelValue(i,10,imp,z,c,t,indexed)); 669 622 } 670 623 … … 1037 990 int index = 0; 1038 991 for (int t = 0; t < maxT; t++) 1039 for (int z = 0; z < maxZ; z++)1040 for (int c = 0; c < maxC; c++)992 for (int c = 0; c < maxC; c++) 993 for (int z = 0; z < maxZ; z++) 1041 994 assertEquals(index++, getIndexValue(ci,z,c,t,indexed)); // expected value from CZT order 1042 995 } … … 1307 1260 // should have the data in one series 1308 1261 impsCountTest(imps,1); 1262 1309 1263 ImagePlus imp = imps[0]; 1264 1310 1265 xyzctTest(imp,x,y,numInSeries(zFrom,zTo,zBy),numInSeries(cFrom,cTo,cBy),numInSeries(tFrom,tTo,tBy)); 1311 1266 1312 1267 // should be in correct order 1313 assertTrue(seriesInZctOrder(imp,false,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy));1268 seriesInZctOrderTest(imp,false,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy); 1314 1269 } 1315 1270 … … 1628 1583 1629 1584 stackInSpecificOrderTest(imp,sizeZ,sizeC,sizeT,indexed); 1585 1586 pixelsTest(imp,pixType,indexed); 1630 1587 } 1631 1588 … … 1887 1844 public void testColorAutoscale() 1888 1845 { 1889 // From BF:1890 // Autoscale  Stretches the histogram of the image planes to fit the data range. Does not alter underlying values in1891 // the image. If selected, histogram is stretched for each stack based upon the global minimum and maximum value1892 // throughout the stack.1893 1894 1846 for (int pixType : PixelTypes) 1895 1847 { … … 2531 2483 fail("unfinished but 2<=sizeC<=7 nonindexed working"); 2532 2484 } 2485 2486 /* 2487 @Test 2488 public void testOrderStuffTemporarily() 2489 { 2490 int pixType=FormatTools.UINT8, sizeX=60, sizeY=30, sizeZ=2, sizeC=3, sizeT=4, numSeries=1, rgb=1, lutLen=1; 2491 boolean indexed = false, falseColor = false; 2492 2493 String path = constructFakeFilename("tempJunk", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed, rgb, falseColor, lutLen); 2494 2495 ImagePlus[] imps = null; 2496 ImagePlus imp = null; 2497 CompositeImage ci = null; 2498 2499 try { 2500 ImporterOptions options = new ImporterOptions(); 2501 imps = BF.openImagePlus(path); 2502 } 2503 catch (IOException e) { 2504 fail(e.getMessage()); 2505 } 2506 catch (FormatException e) { 2507 fail(e.getMessage()); 2508 } 2509 2510 impsCountTest(imps,1); 2511 2512 imp = imps[0]; 2513 2514 // print out vals in stack order 2515 2516 // visit vals in czt order 2517 System.out.println("About to visit in CZT order"); 2518 for (int t = 0; t < sizeT; t++) 2519 for (int z = 0; z < sizeZ; z++) 2520 for (int c = 0; c < sizeC; c++) 2521 { 2522 int sliceNumber = c + (z*imp.getNChannels()) + (t*imp.getNSlices()*imp.getNChannels()); 2523 imp.setSlice(sliceNumber+1); 2524 ImageProcessor proc = imp.getProcessor(); 2525 System.out.println("Slice set to "+(sliceNumber+1)+" for ("+z+"z,"+c+"c,"+t+"t)"); 2526 printVals(proc); 2527 } 2528 2529 // visit vals in zct order 2530 System.out.println("About to visit in ZCT order"); 2531 for (int t = 0; t < sizeT; t++) 2532 for (int c = 0; c < sizeC; c++) 2533 for (int z = 0; z < sizeZ; z++) 2534 { 2535 int sliceNumber = z + (c*imp.getNSlices()) + (t*imp.getNSlices()*imp.getNChannels()); 2536 imp.setSlice(sliceNumber+1); 2537 ImageProcessor proc = imp.getProcessor(); 2538 System.out.println("Slice set to "+(sliceNumber+1)+" for ("+z+"z,"+c+"c,"+t+"t)"); 2539 printVals(proc); 2540 } 2541 2542 // notice: 2543 // slice indices are ordered in ZCT order 2544 // sliceNumber is the same for each loop regardless of loop order  due to calc of index differently. 2545 // in this calc the value ranges from 0..23. Basically == iIndex. 2546 } 2547 */ 2533 2548 }
Note: See TracChangeset
for help on using the changeset viewer.