Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.

Ticket #3627: Test.java

File Test.java, 2.0 KB (added by cxallan, 13 years ago)

Test class which examines all planes for trivial inconsistencies in planar vs. block based binary data retrieval.

Line 
1import java.security.MessageDigest;
2import java.security.NoSuchAlgorithmException;
3
4import loci.common.DataTools;
5import loci.formats.ChannelFiller;
6import loci.formats.ChannelSeparator;
7import loci.formats.FormatTools;
8import loci.formats.IFormatReader;
9import loci.formats.ImageReader;
10import loci.formats.MinMaxCalculator;
11
12
13public class Test
14{
15  private static final String TARGET =
16    "/home/callan/testimages/lsm/2chZT.lsm";
17
18  public void parse(String id) throws Exception
19  {
20    IFormatReader reader = new ImageReader();
21    reader = new ChannelFiller(reader);
22    reader = new ChannelSeparator(reader);
23    reader = new MinMaxCalculator(reader);
24    reader.setId(id);
25
26    int sizeX = reader.getSizeX();
27    int sizeY = reader.getSizeY();
28    int sizeZ = reader.getSizeZ();
29    int sizeC = reader.getSizeC();
30    int sizeT = reader.getSizeT();
31    int bpp = FormatTools.getBytesPerPixel(reader.getPixelType());
32    int planeSize = sizeX * sizeY * bpp;
33
34    byte[] plane = new byte[planeSize];
35    byte[] halfPlane = new byte[planeSize / 2];
36    String planeDigest, halfPlaneDigest;
37    for (int i = 0; i < reader.getImageCount(); i++) {
38      reader.openBytes(i, plane);
39      reader.openBytes(i, halfPlane, 0, 0, sizeX, sizeY / 2);
40      planeDigest = md5(plane, 0, planeSize / 2);
41      halfPlaneDigest = md5(halfPlane, 0, planeSize / 2);
42      if (!planeDigest.equals(halfPlaneDigest)) {
43        System.err.println(String.format("MD5:%d %s != %s",
44            i, planeDigest, halfPlaneDigest));
45      }
46    }
47  }
48
49  /** Calculate the MD5 of a byte array. */
50  public static String md5(byte[] b, int offset, int len) {
51    try {
52      MessageDigest md = MessageDigest.getInstance("MD5");
53      md.reset();
54      md.update(b, offset, len);
55      byte[] digest = md.digest();
56      return DataTools.bytesToHex(digest);
57    }
58    catch (NoSuchAlgorithmException e) { }
59    return null;
60  }
61
62  public static void main(String[] args) throws Exception
63  {
64    Test t = new Test();
65    t.parse(TARGET);
66  }
67
68}

1.3.13-PRO © 2008-2011 Agilo Software all rights reserved (this page was served in: 0.34701 sec.)

We're Hiring!