Changeset 6532
 Timestamp:
 06/17/10 14:49:00 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/components/lociplugins/test/loci/plugins/in/ImporterTest.java
r6530 r6532 37 37 38 38 // left off 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 39 // maybe phase out *Index(ImageProcessor) to support indexed data 40 // add pixelsTest() where necessary 41 // expand compositeTestSubcases() to handle more pixTypes and indexed data 42 // finish the colorize tests 43 // implement more combo tests 42 44 43 45 // seem broken but don't know status from Curtis … … 49 51 // broken 50 52 // comboCropAndAutoscale for INT32. I think its a limitation of Fake. The values of the cropped image are less 51 // than the minimum representable value of an int as a float. So when we make a FloatProcessor on the int[] data52 // the huge negative values get clamped to the lowest representable point and thus max and min are not set correctly53 // by IJ. I have verified that the pixel data that is sent to FloatProcessor() is correct. Limitation we'll live54 // with I guess.53 // than the minimum representable value of an int as a float. So when we make a FloatProcessor on the int[] data 54 // the huge negative values get clamped to the lowest representable point and thus max and min are not set correctly 55 // by IJ. I have verified that the pixel data that is sent to FloatProcessor() is correct. Limitation we'll live 56 // with I guess. 55 57 56 58 // testable code according to my notes … … 123 125 124 126 //String template = "test_C%s_TP%s&sizeX=50&sizeY=20&sizeZ=7.fake"; 125 String template = constructFakeFilename("test_C%s_TP%s", FormatTools.INT32, 50, 20, FakePlaneCount, 1, 1, 1, false, 1, false, 1); 126 // BDZ  INT32 is desirable for the color tests 127 String template = constructFakeFilename("test_C%s_TP%s", FormatTools.UINT8, 50, 20, FakePlaneCount, 1, 1, 1, false, 1, false, 1); 127 128 128 129 FAKE_FILES = new String[] { … … 297 298 } 298 299 299 /** Tests that an ImageStack is ordered ZCT according to specified from/to/by points of z/c/t */300 private void seriesInZctOrderTest(ImagePlus imp, boolean indexed,301 int zFrom, int zTo, int zBy,302 int cFrom, int cTo, int cBy,303 int tFrom, int tTo, int tBy)304 {305 int zs = numInSeries(zFrom,zTo,zBy);306 int cs = numInSeries(cFrom,cTo,cBy);307 int ts = numInSeries(tFrom,tTo,tBy);308 309 ImageStack st = imp.getStack();310 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++)316 {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);320 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);328 }329 }330 331 /** returns a set of indices ordered as ZCT */332 private int[][] getIndicesInZctOrder(int maxZ, int maxC, int maxT)333 {334 int[][] indices = new int[maxZ*maxC*maxT][3];335 336 int i = 0;337 for (int t = 0; t < maxT; t++)338 for (int c = 0; c < maxC; c++)339 for (int z = 0; z < maxZ; z++)340 {341 indices[i][0] = z;342 indices[i][1] = c;343 indices[i][2] = t;344 i++;345 }346 return indices;347 }348 349 300 // this next method useful to avoid changes to instance vars of ImagePlus by query functions 350 301 /** Gets values of private instance variable ints from an ImagePlus */ … … 455 406 private int getPixelValue(int x,int y, ImagePlus imp, int z, int c, int t, boolean indexed) 456 407 { 457 // our indices are 0based while IJ's are 1based458 //imp.setPosition(c+1, z+1, t+1);459 //setCztPosition(imp,z,c,t);460 408 setZctPosition(imp,z,c,t); 461 409 … … 476 424 } 477 425 478 /** gets the value of the index of a fake file doing LUT lookup if needed */ 479 private int getIndexValue(ImagePlus imp, int z, int c, int t, boolean indexed) 480 { 481 return getPixelValue(10,0,imp,z,c,t,indexed); 482 } 483 426 484 427 /** calculate the effective size C of an image given various params */ 485 428 private int effectiveC(int sizeC, int rgb, int lutLen, boolean indexed, boolean falseColor) … … 581 524 } 582 525 583 /** tests that a FakeFile dataset has index values in ZCT order  needed for compositeTester() */ 584 private void stackInSpecificOrderTest(ImagePlus imp, int maxZ, int maxC, int maxT, boolean indexed) 585 { 586 ImageStack st = imp.getStack(); 587 588 if ((maxZ * maxC * maxT) != st.getSize()) 589 fail("testStackInSpecificOrder()  slices don't add up: z"+maxZ+" X c"+maxC+" X t"+maxT+" != "+st.getSize()); 526 /** tests that a FakeFile dataset has index values in ZCT order */ 527 private void stackInZctOrderTest(ImagePlus imp, int maxZ, int maxC, int maxT, boolean indexed) 528 { 529 assertEquals(imp.getStack().getSize(),(maxZ * maxC * maxT)); 590 530 591 531 int iIndex = 0; … … 606 546 } 607 547 548 /** tests that a FakeFile dataset has index values in ZCT order repeated once per series */ 549 private void multipleSeriesInZtcOrderTest(ImagePlus imp, int numSeries, int maxZ, int maxC, int maxT) 550 { 551 ImageStack st = imp.getStack(); 552 553 // make sure the number of slices in stack is a sum of all series 554 assertEquals(st.getSize(), (numSeries*maxZ*maxC*maxT)); 555 556 int slice = 0; 557 for (int sIndex = 0; sIndex < numSeries; sIndex++) { 558 for (int tIndex = 0; tIndex < maxT; tIndex++) { 559 for (int cIndex = 0; cIndex < maxC; cIndex++) { 560 for (int zIndex = 0; zIndex < maxZ; zIndex++) { 561 ImageProcessor proc = st.getProcessor(++slice); 562 assertEquals(sIndex, sIndex(proc)); 563 assertEquals(zIndex, zIndex(proc)); 564 assertEquals(cIndex, cIndex(proc)); 565 assertEquals(tIndex, tIndex(proc)); 566 } 567 } 568 } 569 } 570 } 571 608 572 /** tests that the pixel values of a FakeFile are as expected */ 609 573 private void pixelsTest(ImagePlus imp, int pixType, boolean indexed) … … 622 586 } 623 587 588 private void groupedFilesTest(ImagePlus imp, int numDatasets, int numImagesPerDataset) 589 { 590 ImageStack st = imp.getStack(); 591 592 assertEquals(st.getSize(),numDatasets*numImagesPerDataset); 593 594 int slice = 0; 595 for (int fnum = 0; fnum < FAKE_FILES.length; fnum++) 596 { 597 for (int plane = 0; plane < FakePlaneCount; plane++) 598 { 599 ImageProcessor proc = st.getProcessor(++slice); 600 //printVals(proc); 601 assertEquals(0,sIndex(proc)); 602 assertEquals(plane,iIndex(proc)); // TODO: is this correct. it passes but looks wrong. 603 assertEquals(plane,zIndex(proc)); 604 assertEquals(0,cIndex(proc)); 605 assertEquals(0,tIndex(proc)); 606 } 607 } 608 } 609 610 private void swappedZtTest(ImagePlus imp, int originalZ, int originalC, int originalT) 611 { 612 ImageStack st = imp.getStack(); 613 int numSlices = st.getSize(); 614 assertEquals(numSlices,(originalZ*originalC*originalT)); 615 616 // verify that the dimensional extents were swapped 617 final int actualSizeZ = imp.getNSlices(); 618 final int actualSizeC = imp.getNChannels(); 619 final int actualSizeT = imp.getNFrames(); 620 assertEquals(originalT, actualSizeZ); // Z<>T swapped 621 assertEquals(originalC, actualSizeC); 622 assertEquals(originalZ, actualSizeT); // Z<>T swapped 623 624 // verify that every plane appears in the swapped order 625 int slice = 0; 626 for (int tIndex = 0; tIndex < actualSizeT; tIndex++) 627 for (int cIndex = 0; cIndex < actualSizeC; cIndex++) 628 for (int zIndex = 0; zIndex < actualSizeZ; zIndex++) 629 { 630 ImageProcessor proc = st.getProcessor(++slice); 631 final int actualZ = tIndex(proc); // Z<>T swapped 632 final int actualC = cIndex(proc); 633 final int actualT = zIndex(proc); // Z<>T swapped 634 assertEquals(zIndex, actualZ); 635 assertEquals(cIndex, actualC); 636 assertEquals(tIndex, actualT); 637 } 638 } 639 640 /** Tests that an ImageStack is ordered ZCT according to specified from/to/by points of z/c/t */ 641 private void seriesInZctOrderTest(ImagePlus imp, boolean indexed, 642 int zFrom, int zTo, int zBy, 643 int cFrom, int cTo, int cBy, 644 int tFrom, int tTo, int tBy) 645 { 646 int zs = numInSeries(zFrom,zTo,zBy); 647 int cs = numInSeries(cFrom,cTo,cBy); 648 int ts = numInSeries(tFrom,tTo,tBy); 649 650 ImageStack st = imp.getStack(); 651 652 assertTrue((zs * cs * ts) == st.getSize()); 653 654 for (int t = 0; t < ts; t++) 655 for (int c = 0; c < cs; c++) 656 for (int z = 0; z < zs; z++) 657 { 658 int zIndex = zIndex(imp,z,c,t,indexed); 659 int cIndex = cIndex(imp,z,c,t,indexed); 660 int tIndex = tIndex(imp,z,c,t,indexed); 661 662 int zVal = zFrom + z*zBy; 663 int cVal = cFrom + c*cBy; 664 int tVal = tFrom + t*tBy; 665 666 assertEquals(zVal,zIndex); 667 assertEquals(cVal,cIndex); 668 assertEquals(tVal,tIndex); 669 } 670 } 671 624 672 // ******** specific testers ********************************** 625 673 … … 679 727 assertEquals(z*c*t,numSlices); 680 728 681 int procNum = 1;729 int slice = 0; 682 730 //System.out.println(order); 683 731 Axis fastest = axis(chOrder,0); … … 691 739 for (int k = 0; k < maxK; k++) 692 740 { 693 ImageProcessor proc = st.getProcessor( procNum++);741 ImageProcessor proc = st.getProcessor(++slice); 694 742 //printVals(proc); 695 743 assertNotNull(proc); … … 729 777 xyzctTest(imp,x,y,t,c,z); // Z<>T swapped 730 778 731 ImageStack st = imp.getStack(); 732 int numSlices = st.getSize(); 733 assertEquals(z*c*t,numSlices); 734 735 // verify that the dimensional extents were swapped 736 final int actualSizeZ = imp.getNSlices(); 737 final int actualSizeC = imp.getNChannels(); 738 final int actualSizeT = imp.getNFrames(); 739 assertEquals(t, actualSizeZ); // Z<>T swapped 740 assertEquals(c, actualSizeC); 741 assertEquals(z, actualSizeT); // Z<>T swapped 742 743 // verify that every plane appears in the swapped order 744 int p = 1; 745 for (int tIndex = 0; tIndex < actualSizeT; tIndex++) 746 for (int cIndex = 0; cIndex < actualSizeC; cIndex++) 747 for (int zIndex = 0; zIndex < actualSizeZ; zIndex++) 748 { 749 ImageProcessor proc = st.getProcessor(p++); 750 final int actualZ = tIndex(proc); // Z<>T swapped 751 final int actualC = cIndex(proc); 752 final int actualT = zIndex(proc); // Z<>T swapped 753 assertEquals(zIndex, actualZ); 754 assertEquals(cIndex, actualC); 755 assertEquals(tIndex, actualT); 756 } 779 swappedZtTest(imp,z,c,t); 757 780 } 758 781 … … 834 857 835 858 impsCountTest(imps,1); 836 ImageStack st = imps[0].getStack(); 837 838 // make sure the number of slices in stack is a sum of all series 839 assertEquals(z*c*t*s, st.getSize()); 840 841 int index = 1; 842 for (int sIndex = 0; sIndex < s; sIndex++) { 843 for (int tIndex = 0; tIndex < t; tIndex++) { 844 for (int cIndex = 0; cIndex < c; cIndex++) { 845 for (int zIndex = 0; zIndex < z; zIndex++) { 846 ImageProcessor proc = st.getProcessor(index++); 847 assertEquals(sIndex, sIndex(proc)); 848 assertEquals(zIndex, zIndex(proc)); 849 assertEquals(cIndex, cIndex(proc)); 850 assertEquals(tIndex, tIndex(proc)); 851 } 852 } 853 } 854 } 859 860 multipleSeriesInZtcOrderTest(imps[0],s,z,c,t); 855 861 } 856 862 … … 987 993 //System.out.println("maxes z c t = "+maxZ+" "+maxC+" "+maxT); 988 994 995 /* 989 996 // check that each image in the overall series has the correct iIndex value 990 997 int index = 0; … … 993 1000 for (int z = 0; z < maxZ; z++) 994 1001 assertEquals(index++, getIndexValue(ci,z,c,t,indexed)); // expected value from CZT order 1002 //indexValuesTest(ci, z, c, t, indexed, 0, index++, z, c, t); 1003 */ 1004 stackInZctOrderTest(imp,sizeZ,expectedSizeC,sizeT,indexed); 995 1005 } 996 1006 … … 1413 1423 assertEquals(series*sizeC*sizeT,st.getSize()); 1414 1424 for (int s = 0; s < series; s++) { 1415 int index= s*sizeC*sizeT;1425 int slice = s*sizeC*sizeT; 1416 1426 for (int t = 0; t < sizeT; t++) { 1417 1427 for (int c = 0; c < sizeC; c++) { 1418 1428 //System.out.println("index "+index); 1419 ImageProcessor proc = st.getProcessor(++ index);1429 ImageProcessor proc = st.getProcessor(++slice); 1420 1430 //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); 1421 1431 //System.out.println("z c t "+z+" "+c+" "+t); … … 1468 1478 assertEquals(series*sizeZ*sizeT,st.getSize()); 1469 1479 for (int s = 0; s < series; s++) { 1470 int index= s*sizeZ*sizeT;1480 int slice = s*sizeZ*sizeT; 1471 1481 for (int t = 0; t < sizeT; t++) { 1472 1482 for (int z = 0; z < sizeZ; z++) { 1473 ImageProcessor proc = st.getProcessor(++ index);1483 ImageProcessor proc = st.getProcessor(++slice); 1474 1484 //System.out.println("index "+index); 1475 1485 //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); … … 1522 1532 assertEquals(series*sizeZ*sizeC,st.getSize()); 1523 1533 for (int s = 0; s < series; s++) { 1524 int index= s*sizeZ*sizeC;1534 int slice = s*sizeZ*sizeC; 1525 1535 for (int c = 0; c < sizeC; c++) { 1526 1536 for (int z = 0; z < sizeZ; z++) { 1527 ImageProcessor proc = st.getProcessor(++ index);1537 ImageProcessor proc = st.getProcessor(++slice); 1528 1538 //System.out.println("index "+index); 1529 1539 //System.out.println("s z c t "+s+" "+z+" "+c+" "+t); … … 1582 1592 colorTests(ci,sizeC,DefaultColorOrder); 1583 1593 1584 stackIn SpecificOrderTest(imp,sizeZ,sizeC,sizeT,indexed);1594 stackInZctOrderTest(imp,sizeZ,sizeC,sizeT,indexed); 1585 1595 1586 1596 pixelsTest(imp,pixType,indexed); … … 1630 1640 1631 1641 impsCountTest(imps,1); 1632 1633 ImageStack st = imps[0].getStack(); 1634 1635 assertEquals(FAKE_FILES.length*FakePlaneCount,st.getSize()); 1636 1637 int slice = 1; 1638 for (int fnum = 0; fnum < FAKE_FILES.length; fnum++) 1639 { 1640 for (int plane = 0; plane < FakePlaneCount; plane++) 1641 { 1642 ImageProcessor proc = st.getProcessor(slice++); 1643 //printVals(proc); 1644 assertEquals(0,sIndex(proc)); 1645 assertEquals(plane,iIndex(proc)); 1646 assertEquals(plane,zIndex(proc)); 1647 assertEquals(0,cIndex(proc)); 1648 assertEquals(0,tIndex(proc)); 1649 } 1650 } 1642 1643 groupedFilesTest(imps[0], FAKE_FILES.length, FakePlaneCount); 1651 1644 } 1652 1645 … … 2098 2091 ImageStack st = imp.getStack(); 2099 2092 assertEquals(sizeZ * sizeT,st.getSize()); 2100 int index= 0;2093 int slice = 0; 2101 2094 for (int t = 0; t < sizeT; t++) { 2102 2095 for (int z = 0; z < sizeZ; z++) { 2103 ImageProcessor proc = st.getProcessor(++ index);2096 ImageProcessor proc = st.getProcessor(++slice); 2104 2097 // test the values 2105 2098 assertEquals(z,zIndex(proc)); … … 2142 2135 ImageStack st = imp.getStack(); 2143 2136 assertEquals(sizeC * sizeT,st.getSize()); 2144 int index= 0;2137 int slice = 0; 2145 2138 for (int t = 0; t < sizeT; t++) { 2146 2139 for (int c = 0; c < sizeC; c++) { 2147 ImageProcessor proc = st.getProcessor(++ index);2140 ImageProcessor proc = st.getProcessor(++slice); 2148 2141 // test the values 2149 2142 assertEquals(z,zIndex(proc)); … … 2186 2179 ImageStack st = imp.getStack(); 2187 2180 assertEquals(sizeZ * sizeC,st.getSize()); 2188 int index= 0;2181 int slice = 0; 2189 2182 for (int c = 0; c < sizeC; c++) { 2190 2183 for (int z = 0; z < sizeZ; z++) { 2191 ImageProcessor proc = st.getProcessor(++ index);2184 ImageProcessor proc = st.getProcessor(++slice); 2192 2185 // test the values 2193 2186 assertEquals(z,zIndex(proc)); … … 2300 2293 assertEquals(sizeZ*numC,st.getSize()); // sizeZ = C, numC = T 2301 2294 2302 int p = 1;2295 int slice = 0; 2303 2296 for (int tIndex = start; tIndex < sizeC; tIndex += stepBy) 2304 2297 for (int cIndex = 0; cIndex < sizeZ; cIndex++) 2305 2298 { 2306 ImageProcessor proc = st.getProcessor( p++);2299 ImageProcessor proc = st.getProcessor(++slice); 2307 2300 2308 2301 assertEquals(cropSizeX,proc.getWidth()); … … 2361 2354 2362 2355 System.out.println(" Returned imp: Z = " +imp.getNSlices()+ " C = " +imp.getNChannels()+" T = "+imp.getNFrames()); 2363 for (int cIndex = 0; cIndex < imp.getNChannels(); cIndex++)2364 for (int zIndex = 0; zIndex < imp.getNSlices(); zIndex++)2365 for (int tIndex = 0; tIndex < imp.getNFrames(); tIndex++)2356 for (int tIndex = 0; tIndex < imp.getNFrames(); tIndex++) 2357 for (int cIndex = 0; cIndex < imp.getNChannels(); cIndex++) 2358 for (int zIndex = 0; zIndex < imp.getNSlices(); zIndex++) 2366 2359 { 2367 imp.setPosition(cIndex+1,zIndex+1,tIndex+1);2360 setZctPosition(imp,zIndex,cIndex,tIndex); 2368 2361 ImageProcessor proc = imp.getProcessor(); 2369 2362 printVals(proc); … … 2398 2391 System.out.println(" Not a composite image"); 2399 2392 2393 /* 2394 */ 2400 2395 int iIndex = 0; 2401 2396 for (int cIndex = 0; cIndex < expectedSizeC; cIndex++) 2402 2397 for (int tIndex = 0; tIndex < sizeT; tIndex++) 2403 2398 for (int zIndex = 0; zIndex < sizeZ; zIndex++) 2404 getIndexValue(imp, zIndex, cIndex, tIndex, indexed); 2405 //assertEquals(iIndex++,getIndexValue(imp, zIndex, cIndex, tIndex, indexed)); 2406 // testValues(imp,0,zIndex,cIndex,tIndex,iIndex,indexed); 2399 getPixelValue(10,0,imp,zIndex,cIndex,tIndex,indexed); 2400 //assertEquals(iIndex++,getPixelValue(10,0,imp,zIndex,cIndex,tIndex,indexed)); 2401 2402 // TODO  replace above nested loop with this when this test debugged : 2403 //stackInZctOrderTest(imp,sizeZ,expectedSizeC,sizeT,indexed); 2407 2404 } 2408 2405 … … 2484 2481 } 2485 2482 2486 /*2487 @Test2488 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 order2515 2516 // visit vals in czt order2517 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 order2530 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 order2544 // 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 */2548 2483 }
Note: See TracChangeset
for help on using the changeset viewer.