Skip to content

Commit

Permalink
Add test for Issue #1: MetaImage Reader/Writer should respect `Origin…
Browse files Browse the repository at this point in the history
…` tag.
  • Loading branch information
jpsacha committed Mar 30, 2016
1 parent da26a4d commit 38d459b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
51 changes: 35 additions & 16 deletions src/test/java/net/sf/ij_plugins/io/metaimage/MiDecoderTest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
/*
* Image/J Plugins
* Copyright (C) 2002-2011 Jarek Sacha
* Author's email: jsacha at users dot sourceforge dot net
* IJ-Plugins
* Copyright (C) 2002-2016 Jarek Sacha
* Author's email: jpsacha at gmail dot com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Latest release available at http://sourceforge.net/projects/ij-plugins/
* Latest release available at http://sourceforge.net/projects/ij-plugins/
*/

package net.sf.ij_plugins.io.metaimage;

import ij.ImagePlus;
import ij.measure.Calibration;
import org.junit.Test;

import java.io.File;
Expand All @@ -48,7 +49,6 @@ public void testRead1() throws Exception {
assertEquals(256, imp.getHeight());
assertEquals(1, imp.getStackSize());
assertEquals(ImagePlus.GRAY8, imp.getType());

}


Expand Down Expand Up @@ -93,5 +93,24 @@ public void mhaNoVirtualStack() throws MiException {
assertEquals(ImagePlus.GRAY8, imp.getType());
}

@Test
public void testReadOffset() throws Exception {
final File inFile = new File("test/data/Issue_001/fixed.mhd");
final ImagePlus[] imps = MiDecoder.open(inFile);
assertNotNull(imps);
assertEquals(1, imps.length);
final ImagePlus imp = imps[0];
assertEquals("width", 305, imp.getWidth());
assertEquals("heights", 311, imp.getHeight());
assertEquals("slices", 11, imp.getStackSize());
assertEquals("image type", ImagePlus.GRAY32, imp.getType());

// Test if origin is read correctly, Issue #1.
final Calibration cal = imp.getCalibration();
assertEquals("xOrigin", 0, cal.xOrigin, 0.001);
assertEquals("yOrigin", 0, cal.yOrigin, 0.001);
assertEquals("zOrigin", 10.4, cal.zOrigin, 0.001);
}


}
13 changes: 13 additions & 0 deletions test/data/Issue_001/fixed.mhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 10.4
CenterOfRotation = 0 0 0
AnatomicalOrientation = RAI
ElementSpacing = 0.04 0.04 0.04
DimSize = 305 311 11
ElementType = MET_FLOAT
ElementDataFile = fixed.raw
Binary file added test/data/Issue_001/fixed.raw
Binary file not shown.

0 comments on commit 38d459b

Please sign in to comment.