Changeset 6529
 Timestamp:
 06/14/10 16:58:42 (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/components/lociplugins/test/loci/plugins/in/ImporterTest.java
r6528 r6529 37 37 38 38 // left off 39 // why does seriesInCorrectOrder() behave so differently depending upon how it loads index values? 40 // ImagePlus.setPosition() sets the slice based on CZT order. My other code assumes ZCT order and never messes with 41 // setPosition(). Somehow I have to look in order of stack but order not via czt but zct. I started changin getPixelValue() 42 // to lookup slices in ZCT order. My change did not work as I expected. It temporarily broke memorySpecRange(). 39 // got compositeTestSubcases to work using seriesInSpecificOrder(). Have not modified seriesInZctOrder() to work for indexed 40 // data (see TODO there and try again) 43 41 44 42 // seem broken but don't know status from Curtis … … 197 195 private int tIndex(ImageProcessor proc) { return (int) proc.getPixelValue(40, 0); } 198 196 199 @SuppressWarnings("unused") 197 /** Series number of the given ImagePlus at z,c,t index */ 198 private int sIndex(ImagePlus imp, int z, int c, int t, boolean indexed) 199 { 200 return getPixelValue(0,0,imp,z,c,t,indexed); 201 } 202 203 /** Image number of the given ImagePlus at z,c,t index */ 204 private int iIndex(ImagePlus imp, int z, int c, int t, boolean indexed) 205 { 206 return getPixelValue(10,0,imp,z,c,t,indexed); 207 } 208 209 /** Slice number of the given ImagePlus at z,c,t index */ 210 private int zIndex(ImagePlus imp, int z, int c, int t, boolean indexed) 211 { 212 return getPixelValue(20,0,imp,z,c,t,indexed); 213 } 214 215 /** Channel number of the given ImagePlus at z,c,t index */ 216 private int cIndex(ImagePlus imp, int z, int c, int t, boolean indexed) 217 { 218 return getPixelValue(30,0,imp,z,c,t,indexed); 219 } 220 221 /** Frame number of the given ImagePlus at z,c,t index */ 222 private int tIndex(ImagePlus imp, int z, int c, int t, boolean indexed) 223 { 224 return getPixelValue(40,0,imp,z,c,t,indexed); 225 } 226 227 @SuppressWarnings("unused") 200 228 private void printVals(ImageProcessor proc) 201 229 { … … 268 296 } 269 297 270 // note : for now assumes default ZCT ordering 271 /** Tests that an ImageStack is ordered according to specified from/to/by points of z/c/t */ 272 private boolean seriesInCorrectOrder(ImagePlus imp, boolean indexed, 298 /** 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, 273 300 int zFrom, int zTo, int zBy, 274 301 int cFrom, int cTo, int cBy, … … 283 310 if ((zs * cs * ts) != st.getSize()) 284 311 { 285 System.out.println("seriesIn CorrectOrder()  slices don't add up: z"+zs+" X c"+cs+" X t"+ts+" != "+st.getSize());312 System.out.println("seriesInZctOrder()  slices don't add up: z"+zs+" X c"+cs+" X t"+ts+" != "+st.getSize()); 286 313 return false; 287 314 } … … 296 323 // TODO  this code fails with C/Z calced in wrong order  determine why 297 324 298 zIndex = zIndex(imp,z,c,t,indexed);299 cIndex = cIndex(imp,z,c,t,indexed);300 tIndex = tIndex(imp,z,c,t,indexed);325 //zIndex = zIndex(imp,z,c,t,indexed); 326 //cIndex = cIndex(imp,z,c,t,indexed); 327 //tIndex = tIndex(imp,z,c,t,indexed); 301 328 302 329 //System.out.println(" after wrong way z("+imp.getSlice()+") c("+imp.getChannel()+") t("+imp.getFrame()+")"); … … 304 331 // TODO  this code works but can't support indexed data 305 332 306 //ImageProcessor proc = imp.getStack().getProcessor(procNum);333 ImageProcessor proc = imp.getStack().getProcessor(procNum); 307 334 308 //zIndex = zIndex(proc);309 //cIndex = cIndex(proc);310 //tIndex = tIndex(proc);335 zIndex = zIndex(proc); 336 cIndex = cIndex(proc); 337 tIndex = tIndex(proc); 311 338 312 339 //System.out.println(" after right way z("+imp.getSlice()+") c("+imp.getChannel()+") t("+imp.getFrame()+")"); … … 314 341 if ((zIndex != z)  (cIndex != c)  (tIndex != t)) 315 342 { 316 System.out.println("seriesIn CorrectOrder()  slices out of order: expZ("+z+") expC("+c+") expT("+t+") != actZ("+343 System.out.println("seriesInZctOrder()  slices out of order: expZ("+z+") expC("+c+") expT("+t+") != actZ("+ 317 344 zIndex+") actC("+cIndex+") actT("+tIndex+") for proc number "+procNum); 318 345 return false; 319 346 } 347 procNum++; 348 } 349 350 return true; 351 } 352 353 private int[][] indicesInZctOrder(int maxZ, int maxC, int maxT) 354 { 355 int[][] indices = new int[maxZ*maxC*maxT][3]; 356 357 int i = 0; 358 for (int t = 0; t < maxT; t++) 359 for (int c = 0; c < maxC; c++) 360 for (int z = 0; z < maxZ; z++) 361 { 362 indices[i][0] = z; 363 indices[i][1] = c; 364 indices[i][2] = t; 365 i++; 366 } 367 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 order 382 // TODO  verify this is correct behavior 383 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 320 410 procNum++; 321 411 } … … 423 513 { 424 514 // our indices are 0based while IJ's are 1based 425 //imp.setPosition(c+1, z+1, t+1); // TODO  old way426 mySetPos(imp,z,c,t,imp.getNSlices(),imp.getNChannels(),imp.getNFrames()); // TODO  why doesn't this result in correct behavior?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? 427 517 428 518 int rawValue = (int) (imp.getProcessor().getPixelValue(x, y)); … … 535 625 assertTrue(originCropX + sizeCrop <= sizeX); 536 626 assertTrue(originCropY + sizeCrop <= sizeY); 627 } 628 629 /** helper test that verifies the indices of a FakeFile[z,c,t] match passed in values*/ 630 private void indexValuesTest(ImagePlus imp, int z, int c, int t, boolean indexed, int es, int ei, int ez, int ec, int et) 631 { 632 assertEquals(es,sIndex(imp, z, c, t, indexed)); 633 assertEquals(ei,iIndex(imp, z, c, t, indexed)); 634 assertEquals(ez,zIndex(imp, z, c, t, indexed)); 635 assertEquals(ec,cIndex(imp, z, c, t, indexed)); 636 assertEquals(et,tIndex(imp, z, c, t, indexed)); 637 } 638 639 private void stackInSpecificOrderTest(ImagePlus imp, int maxZ, int maxC, int maxT, boolean indexed) 640 { 641 ImageStack st = imp.getStack(); 642 643 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 654 int iIndex = 0; 655 for (int t = 0; t < maxT; t++) 656 for (int z = 0; z < maxZ; z++) 657 for (int c = 0; c < maxC; c++) 658 { 659 int expectedS = 0; 660 int expectedI = iIndex; 661 int expectedZ = indices[iIndex][0]; 662 int expectedC = indices[iIndex][1]; 663 int expectedT = indices[iIndex][2]; 664 665 iIndex++; 666 667 indexValuesTest(imp,z,c,t,indexed,expectedS,expectedI,expectedZ,expectedC,expectedT); 668 } 537 669 } 538 670 … … 1179 1311 1180 1312 // should be in correct order 1181 assertTrue(seriesIn CorrectOrder(imp,false,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy));1313 assertTrue(seriesInZctOrder(imp,false,zFrom,zTo,zBy,cFrom,cTo,cBy,tFrom,tTo,tBy)); 1182 1314 } 1183 1315 … … 1451 1583 } 1452 1584 } 1585 } 1586 1587 1588 private void compositeTester(int sizeC, boolean indexed) 1589 { 1590 int pixType = FormatTools.UINT8, sizeX = 60, sizeY = 30, sizeZ = 2, sizeT = 3, numSeries = 1, rgb = 1, lutLen = 1; 1591 boolean falseColor = false; 1592 1593 String path = constructFakeFilename("colorComposite", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed, 1594 rgb, falseColor, lutLen); 1595 1596 ImagePlus[] imps = null; 1597 ImagePlus imp = null; 1598 CompositeImage ci = null; 1599 1600 try { 1601 ImporterOptions options = new ImporterOptions(); 1602 options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE); 1603 options.setId(path); 1604 imps = BF.openImagePlus(options); 1605 } 1606 catch (IOException e) { 1607 fail(e.getMessage()); 1608 } 1609 catch (FormatException e) { 1610 fail(e.getMessage()); 1611 } 1612 1613 impsCountTest(imps,1); 1614 1615 imp = imps[0]; 1616 1617 xyzctTest(imp,sizeX,sizeY,sizeZ,sizeC,sizeT); 1618 1619 assertTrue(imp.isComposite()); 1620 1621 ci = (CompositeImage)imp; 1622 1623 assertFalse(ci.hasCustomLuts()); 1624 1625 assertEquals(CompositeImage.COMPOSITE, ci.getMode()); 1626 1627 colorTests(ci,sizeC,DefaultColorOrder); 1628 1629 stackInSpecificOrderTest(imp,sizeZ,sizeC,sizeT,indexed); 1453 1630 } 1454 1631 … … 2344 2521 } 2345 2522 2346 private void compositeTester(int sizeC, boolean indexed)2347 {2348 System.out.println("compositeTest: sizeC = "+sizeC);2349 2350 int pixType = FormatTools.UINT8, sizeX = 60, sizeY = 30, sizeZ = 2, sizeT = 3, numSeries = 1, rgb = 1, lutLen = 1;2351 boolean falseColor = false;2352 2353 String path = constructFakeFilename("colorComposite", pixType, sizeX, sizeY, sizeZ, sizeC, sizeT, numSeries, indexed,2354 rgb, falseColor, lutLen);2355 2356 ImagePlus[] imps = null;2357 ImagePlus imp = null;2358 CompositeImage ci = null;2359 2360 try {2361 ImporterOptions options = new ImporterOptions();2362 options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);2363 options.setId(path);2364 imps = BF.openImagePlus(options);2365 }2366 catch (IOException e) {2367 fail(e.getMessage());2368 }2369 catch (FormatException e) {2370 fail(e.getMessage());2371 }2372 2373 impsCountTest(imps,1);2374 2375 imp = imps[0];2376 2377 /*2378 System.out.println(" Returned imp: Z = " +imp.getNSlices()+ " C = " +imp.getNChannels()+" T = "+imp.getNFrames());2379 for (int tIndex = 0; tIndex < imp.getNFrames(); tIndex++)2380 for (int zIndex = 0; zIndex < imp.getNSlices(); zIndex++)2381 for (int cIndex = 0; cIndex < imp.getNChannels(); cIndex++)2382 {2383 imp.setPosition(cIndex+1,zIndex+1,tIndex+1);2384 ImageProcessor proc = imp.getProcessor();2385 printVals(proc);2386 }2387 */2388 2389 xyzctTest(imp,sizeX,sizeY,sizeZ,sizeC,sizeT);2390 2391 assertTrue(imp.isComposite());2392 2393 ci = (CompositeImage)imp;2394 2395 assertFalse(ci.hasCustomLuts());2396 2397 assertEquals(CompositeImage.COMPOSITE, ci.getMode());2398 2399 colorTests(ci,sizeC,DefaultColorOrder);2400 2401 int iIndex = 0;2402 for (int tIndex = 0; tIndex < sizeT; tIndex++)2403 for (int zIndex = 0; zIndex < sizeZ; zIndex++)2404 for (int cIndex = 0; cIndex < sizeC; cIndex++)2405 {2406 //testIndexValues(imp,0,iIndex++,zIndex,cIndex,tIndex,indexed);2407 assertEquals(0,sIndex(imp,zIndex,cIndex,tIndex,indexed));2408 assertEquals(iIndex++,iIndex(imp,zIndex,cIndex,tIndex,indexed));2409 }2410 2411 assertTrue(seriesInCorrectOrder(imp,indexed,0,sizeZ1,1,0,sizeC1,1,0,sizeT1,1));2412 2413 // images from BF look to be in ZCT order2414 // however IJ likes CZT order2415 // seriesInCorrectOrder() is the touchpoint between both ways. See there.2416 }2417 2418 /** helper test that verifies the indices of a FakeFile[z,c,t] match passed in values*/2419 private void testIndexValues(ImagePlus imp, int s, int i, int z, int c, int t, boolean indexed)2420 {2421 String status = "Correct";2422 if ((z != zIndex(imp, z, c, t, indexed))  (c != cIndex(imp, z, c, t, indexed)))2423 status = "Wrong";2424 // System.out.println("expZ("+z+") expC("+c+") actZ("+zIndex(imp, z, c, t, indexed)+2425 // ") actC("+cIndex(imp, z, c, t, indexed)+")");2426 //else2427 // System.out.println("Z("+z+") C("+c+") correct!");2428 System.out.println("s("+sIndex(imp,z,c,t,indexed)+") i("+iIndex(imp,z,c,t,indexed)+") z("+zIndex(imp,z,c,t,indexed)+2429 ") c("+cIndex(imp,z,c,t,indexed)+") t("+tIndex(imp,z,c,t,indexed)+") expZ("+z+") expC("+c+") "+status);2430 assertEquals(s,sIndex(imp, z, c, t, indexed));2431 assertEquals(i,iIndex(imp, z, c, t, indexed));2432 //assertEquals(z,zIndex(imp, z, c, t, indexed));2433 //assertEquals(c,cIndex(imp, z, c, t, indexed));2434 assertEquals(t,tIndex(imp, z, c, t, indexed));2435 }2436 2437 private int sIndex(ImagePlus imp, int z, int c, int t, boolean indexed)2438 {2439 return getPixelValue(0,0,imp,z,c,t,indexed);2440 }2441 2442 private int iIndex(ImagePlus imp, int z, int c, int t, boolean indexed)2443 {2444 return getPixelValue(10,0,imp,z,c,t,indexed);2445 }2446 2447 private int zIndex(ImagePlus imp, int z, int c, int t, boolean indexed)2448 {2449 return getPixelValue(20,0,imp,z,c,t,indexed);2450 }2451 2452 private int cIndex(ImagePlus imp, int z, int c, int t, boolean indexed)2453 {2454 return getPixelValue(30,0,imp,z,c,t,indexed);2455 }2456 2457 private int tIndex(ImagePlus imp, int z, int c, int t, boolean indexed)2458 {2459 return getPixelValue(40,0,imp,z,c,t,indexed);2460 }2461 2462 2523 @Test 2463 2524 public void testCompositeSubcases() … … 2468 2529 if (!indexed) // TODO  remove in future; only doing nonindexed right now 2469 2530 compositeTester(channels,indexed); 2470 fail("unfinished ");2531 fail("unfinished but 2<=sizeC<=7 nonindexed working"); 2471 2532 } 2472 2533 }
Note: See TracChangeset
for help on using the changeset viewer.