Created
June 23, 2017 19:05
-
-
Save bogovicj/4b22195fde421652518be230f1180037 to your computer and use it in GitHub Desktop.
Convert image to nii with mipav
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mipavProject; | |
import java.io.File; | |
import java.io.IOException; | |
import gov.nih.mipav.model.file.FileIO; | |
import gov.nih.mipav.model.file.FileNIFTI; | |
import gov.nih.mipav.model.file.FileUtility; | |
import gov.nih.mipav.model.file.FileWriteOptions; | |
import gov.nih.mipav.model.structures.ModelImage; | |
import gov.nih.mipav.view.ViewUserInterface; | |
public class ResaveVolume | |
{ | |
public static void main( String[] args ) throws IOException | |
{ | |
String in = args[ 0 ]; | |
String out = args[ 1 ]; | |
File inF = new File( in ); | |
String imgDir = inF.getParent(); | |
File outF = new File( out ); | |
String outDir = outF.getParent(); | |
String outName = outF.getName(); | |
if( !imgDir.endsWith( File.separator )) | |
imgDir = imgDir + File.separator; | |
if( !outDir.endsWith( File.separator )) | |
outDir = outDir + File.separator; | |
ViewUserInterface vui = ViewUserInterface.create(); | |
vui.setDefaultDirectory( imgDir ); | |
FileIO fio = new FileIO(); | |
fio.setQuiet( true ); | |
System.out.println("reading: " + in ); | |
ModelImage img = fio.readImage( in ); | |
System.out.println( img ); | |
System.out.println("writing"); | |
FileWriteOptions opts = new FileWriteOptions( outName, outDir, true ); | |
opts.setFileType( FileUtility.NIFTI ); | |
opts.setNIFTIExtension( ".nii" ); | |
opts.setBeginSlice( 0 ); | |
opts.setEndSlice( img.getExtents()[ 2 ] - 1 ); // subtract one since EndSlice seems to be inclusive | |
opts.setMultiFile( false ); | |
FileNIFTI niif = new FileNIFTI( outName, outDir ); | |
niif.writeImage( img, opts ); | |
System.out.println("done"); | |
System.exit( 0 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment