[Insight-users] Odd java wrappers behavior
Brian Eastwood
beastwoo at email.unc.edu
Fri May 28 12:28:18 EDT 2004
Hi Luis,
Here's a little background: I'm using registration to align a video
sequence. I have a class that generates a list of transforms, one for
each frame. I first ran across this problem when I tried to use this
list of transforms to generate a modified sequence (using
itkResampleImageFilter)--I first saw the problem when I was trying to
compose the transforms.
Now I simply save the transform data to a file--this works better for me
anyway, since I may want to use the same transforms on a different file
sequence that may not be otherwise registered (different image data,
same capturing method). One line of my output file looks like:
InsightToolkit.itkCenteredRigid2DTransform 5: -0.0054248555345777095,
111.99813266896304, 114.49967542970687, 0.14514270891024816,
-0.6813850112138921
So, we have the class name, the number of parameters, and then the
actual transform parameters. Here's the method I use to read this file:
public static List loadTransforms(String fileName)
{
List transforms = new ArrayList();
try
{
BufferedReader reader = new BufferedReader(new
FileReader(fileName));
String line;
String delims = " " + OBJECT_DELIM + ATTRIB_DELIM; // space,
colon, comma
while ((line = reader.readLine()) != null)
{
StringTokenizer tokenizer = new StringTokenizer(line,
delims);
String xformClass = tokenizer.nextToken(); // ignored
int paramCount = Integer.parseInt(tokenizer.nextToken());
// @todo Maybe handle other types of transforms?
itkCenteredRigid2DTransform_Pointer transform =
itkCenteredRigid2DTransform.itkCenteredRigid2DTransform_New();
transform.SetIdentity();
itkArrayD params = new itkArrayD(paramCount);
for (int i = 0; i < paramCount; i++)
{
params.SetElement(i,
Double.parseDouble(tokenizer.nextToken()));
}
transform.SetParameters(params);
transforms.add(transform.GetPointer());
}
reader.close();
}
catch (IOException ioe)
{
System.err.println("RegistrationOutput: IO exception
occurred:");
ioe.printStackTrace();
}
System.out.println(transforms.size() + " transforms read from
file " + fileName + ".");
return transforms;
}
With this list of transforms I run across the same problems as with the
list I obtain directly from registration--I can do certain things, but
at some point I might get that odd error. Here's an extended example of
the code block I gave yesterday:
System.out.println("\n--- Before ---");
TransformIO.printTranforms(transforms);
reader = itkImageFileReaderUS2.itkImageFileReaderUS2_New(); //
this one is instantiated
caster = null; //
itkCastImageFilterUS2F2.itkCastImageFilterUS2F2_New();
rescaler = null; //
itkRescaleIntensityImageFilterF2US2.itkRescaleIntensityImageFilterF2US2_New();
writer = null; // itkImageFileWriterUS2.itkImageFileWriterUS2_New();
System.out.println("\n--- After ---");
TransformIO.printTranforms(transforms);
if (true) return;
When I run this, all of the transforms print out from the "before"
group; six print out from the "after" group before it crashes. If I
instantiate the caster instead, only one transform prints out from the
"after" group. If I don't instantiate any objects, all transforms print
out. That's why I'm scratching my head so much on this one.
Thanks, again, for your help.
Cheers,
Brian
More information about the Insight-users
mailing list