|
||
Wrap ITKWrapping ITK for use with Java is not straight forward and varies with the system setup. Up to now we were able to build ITK for Windows 32bit only, due to limitations in the toolchain. Indications on how to build ITK for 64bit Windows and/or 32/64bit Linux are highly appreciated. While several comments and questions can be found on distinct mailing lists, there is no real "how to" and it may take severe problem-solving before the error stated in the question can finally be reproduced. As a consequence, we'd like to present our experiences with building ITK with Java wrappers. You will need:
Let the fun begin.
You should now be all set (test code is appended). Due to the restrictions introduced with the need for 32bit Java, a possibility to wrap it for 64bit would be highly appreciated. Note: We obtained errors for the ITK Level Set module and were not able to wrap it. This might work for later versions of ITK. We might be able to provide pre-compiled binaries and some minimal support. Please contact: mathias.unberath(at)fau.de
Test Codeimport org.itk.itkanisotropicsmoothing.itkCurvatureAnisotropicDiffusionImageFilterIF2IF2; import org.itk.itkcommon.itkImageUC2; import org.itk.itkcommon.itkIndex2; import org.itk.itkfastmarching.itkFastMarchingImageFilterIF2IF2; import org.itk.itkfastmarching.itkLevelSetNodeF2; import org.itk.itkfastmarching.itkVectorContainerUILSNF2; import org.itk.itkimagefilterbase.itkCastImageFilterIF2IUC2; import org.itk.itkimagefilterbase.itkCastImageFilterIUC2IF2; import org.itk.itkimagegradient.itkGradientMagnitudeImageFilterIF2IF2; import org.itk.itkimageintensity.itkSigmoidImageFilterIF2IF2; import org.itk.itkioimagebase.itkImageFileReaderIUC2; import org.itk.itkioimagebase.itkImageFileWriterIUC2; public class itkImageIO { // use .png images for this example
// more information: // www.itk.org/Doxygen/html/Examples_2Segmentation_2GeodesicActiveContourImageFilter_8cxx-example.html public static void main( String argv[] ) { String inFile = argv[0]; String outFile = argv[1];
itkImageFileReaderIUC2 reader = new itkImageFileReaderIUC2(); itkImageFileWriterIUC2 writer = new itkImageFileWriterIUC2(); reader.SetFileName( inFile ); reader.Update(); itkImageUC2 img = reader.GetOutput(); int sx = (int) img.GetLargestPossibleRegion().GetSize().GetElement(0); int sy = (int) img.GetLargestPossibleRegion().GetSize().GetElement(1); System.out.println("Dim x: " + Integer.valueOf(sx) + "\tDim y: " + Integer.valueOf(sy));
// cast unsigned char image to float for active contour level set segmentation System.out.println("Casting to float."); itkCastImageFilterIUC2IF2 castFloat = new itkCastImageFilterIUC2IF2(); castFloat.SetInput(reader.GetOutput()); castFloat.Update(); // instantiate objects //smoothing System.out.println("Smoothing image."); itkCurvatureAnisotropicDiffusionImageFilterIF2IF2 uniso = new itkCurvatureAnisotropicDiffusionImageFilterIF2IF2(); uniso.SetInput(castFloat.GetOutput()); uniso.SetTimeStep(0.125); uniso.SetNumberOfIterations(5); uniso.SetConductanceParameter(9); uniso.Update(); //gradient and sigmoid System.out.println("Calculating gradient magnitude."); itkGradientMagnitudeImageFilterIF2IF2 gradMag = new itkGradientMagnitudeImageFilterIF2IF2(); gradMag.SetInput(uniso.GetOutput()); gradMag.Update(); System.out.println("Applying sigmoid filter."); itkSigmoidImageFilterIF2IF2 sigmoid = new itkSigmoidImageFilterIF2IF2(); sigmoid.SetInput(gradMag.GetOutput()); sigmoid.SetAlpha(-0.3); sigmoid.SetBeta(2); sigmoid.SetOutputMinimum(0.0f); sigmoid.SetOutputMaximum(1.0f); sigmoid.Update(); //fast marching as level set initialization for active contours level set filter System.out.println("Starting fast marching image filter."); itkFastMarchingImageFilterIF2IF2 fast = new itkFastMarchingImageFilterIF2IF2(); fast.SetInput(sigmoid.GetOutput()); //56 92 5 1 -0,3 2,0 10 itkIndex2 idx = new itkIndex2(); itkLevelSetNodeF2 node = new itkLevelSetNodeF2(); idx.SetElement(0, 56); idx.SetElement(1, 92); node.SetIndex(idx); node.SetValue(-5); itkVectorContainerUILSNF2 container = new itkVectorContainerUILSNF2(); container.Initialize(); container.InsertElement(0, node); fast.SetTrialPoints(container); fast.SetSpeedConstant(1.0f); fast.SetOutputSize(castFloat.GetOutput().GetLargestPossibleRegion().GetSize()); fast.Update(); //cast back to unsigned char itkCastImageFilterIF2IUC2 castUC = new itkCastImageFilterIF2IUC2(); castUC.SetInput(fast.GetOutput()); castUC.Update(); //write to output writer.SetFileName( outFile ); writer.SetInput( castUC.GetOutput() ); writer.Update(); }
} |