package io;

import java.io.File;
import java.io.IOException;

import org.janelia.utility.parse.ParseUtils;

import ij.IJ;
import ij.ImagePlus;
import io.nii.NiftiIo;
import loci.formats.FormatException;

public class SetResolution {

	public static void main(String[] args) throws FormatException, IOException
	{
		String imF = args[ 0 ];
		String out = args[ 1 ];
		double[] res = ParseUtils.parseDoubleArray( args[ 2 ] );
		
		String unit = null;
		if( args.length >= 4 )
			unit = args[ 3 ];
		
		ImagePlus ip = null;
		if( imF.endsWith( "nii" ))
		{
			ip = NiftiIo.readNifti( new File( imF ));
		}
		else
		{
			ip = IJ.openImage( imF );
		}

		ip.getCalibration().pixelWidth  = res[ 0 ];
		ip.getCalibration().pixelHeight = res[ 1 ];
		ip.getCalibration().pixelDepth  = res[ 2 ];
		
		if( unit != null )
			ip.getCalibration().setUnit( unit );

		IOHelper.write( ip, out );
	}

}

@@ -493,92 +493,67 @@
  %5D;%0A
-%09%09
 %0A%09%09I
-magePlus ip
+OHelper io
  = n
-ull;%0A%09%09if( imF.endsWith( %22nii%22 ))%0A%09%09%7B%0A%09%09%09ip = NiftiI
+ew IOHelper();%0A%09%09ImagePlus ip = i
 o.read
-Nifti
+Ip
 ( ne
@@ -571,56 +571,8 @@
  ));
-%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09ip = IJ.openImage( imF );%0A%09%09%7D
 %0A%0A%09%09

use iohelper in setresolution