[Insight-developers] Odd filter/writer behavior

Michael Stauffer mstauff at verizon.net
Mon Nov 1 13:42:15 EDT 2010


Hi Luis,

Mainly I've been writing out .nii.gz, but have tried other formats, with the same result.

In my original post I attached source code and a test exe - maybe attachments don't get through to the list. I've attached again. Is there another way to post code to the list?

Note that in the attached itkComposeAffineTransformWithHeaderTransformImageFilter.txx, changing 'SetNthOutput()' to 'GraftOutput()' fixes the problem.

Thanks,
Michael


Oct 31, 2010 05:12:55 PM, luis.ibanez at kitware.com wrote:

===========================================


Hi Michael,

What file format are you trying to use to write the image out ?

Could you please post your current source code ?

In that way we can try to reproduce the problem.

    Thanks


          Luis


-------------------------------------------------------------------------
On Fri, Oct 29, 2010 at 4:05 PM, Michael Stauffer (Circular Logic)  wrote:






Thanks Luis, I'm understanding what I can from 
itKChangeInformationFilter. I put the modifications in GenerateData() because I 
was duplicating the image before modifying the header, and wasn't sure that 
GenerateOutputInformation() was only called once the object/filter was being 
processed. But I've seen since then that's it's called during 
filter/pipeline processing. But in any case, duplicating the image isn't the way 
to go, as you say.
 
Also, I got the filter to work as-is, simply by changing the call to 
SetNthOutput() in GenerateData() to GraftOutput(). Interesting, but not that I 
understand why.
 
It seems so odd still that the image would show the expected values when 
returned from my filter, but then not write out to file properly. Do you have an 
idea why that might be? I'm still just getting started here, so the details of 
the itk process are still largely automagical to me.
 
Cheers,
Michael


  
  
  From: Luis Ibanez 
  [mailto:luis.ibanez at kitware.com] 
Sent: Wednesday, October 27, 2010 
  3:38 PM
To: Michael Stauffer
Subject: Re: 
  [Insight-developers] Odd filter/writer behavior


  Hi Michael,

I think that the problem is related to the fact 
  that
inside GenerateData() you are instantiating a 
new Output image, 
  and putting it on top of 
the Output #0.

For the particular filter 
  that you are implementing,
the actual modification should mostly go in 
  the
method

B B B B B B GenerateOutputInformation()

instead of 
  the GenerateData() method.

This is because, what you are modifying is 
  the
"orientation" matrix, which is part ofB the metadata.
You are not 
  modifying the actual pixel values of 
the image.

You will find 
  useful to follow the example of the
filter:

B 
  ITK/Code/BasicFilters/
B B B B 
  itkChangeInformationImageFilter.txx

You will notice in this filter that 
  the GenerateData()
method doesn't create another image.B In general,
by 
  the time the GenerateData() method is called,
the filter base classes will 
  have already created an
image for you, based on the information that 
  you
set in the GenerateOutputInformation() method.


B B B B 
  Regards,


B B B B B B B B B 
  Luis

------------------------------------------------------------

  On Mon, Oct 25, 2010 at 2:45 PM, Michael Stauffer  
wrote:

  Mac 
    OSX 10.5.8
GCC 4.0.1
ITK 3.20

Hi,

I'm seeing odd 
    behavior with a simple filter I made. The filter simply moidifies the 
    Direction and Origin members of an input image and returns a new 
    image.

The printing the new image's modified Direction to stdout 
    shows the correct values. But when I then write to a new image file, the 
    modified Direction and Origin values only show up if the filter had been 
    instantiated and used within a code block. I've attached source files for 
    the filter and test, and included the relevant source snippet 
    below.

Note that in the second case, outputImage2->GetDirection() 
    B prints with correct values, but the files that's subsequently written does 
    not. Seems very odd. I see the same behavior in another test 
    program.

Anyone have any ideas?

source:

B typedef 
    itk::ComposeAffineTransformWithHeaderTransformImageFilter ComposeFilterType;

B 
    /////////////////////////////////////////////////////////////////////////
B 
    std::cout << "test2DHeader... filter code in block..." <SetInput( 
    inputImage );
B composeFilter->SetTransform( transform );
B 
    composeFilter->Update();

B // Create output
B outputImage1 = 
    composeFilter->GetOutput();
B }

B std::cout << 
    "test2DHeader... outputImage1.Direction: " << std::endl;
B 
    std::cout <GetDirection() << 
    std::endl;

B // write it out
B typedef 
    itk::ImageFileWriter WriterType;
B WriterType::Pointer 
    writer1 = WriterType::New();
B writer1->SetFileName( 
    "testBlock_"+outputfilename );
B writer1->SetInput( outputImage1 
    );
B writer1->Update();

B 
    /////////////////////////////////////////////////////////////////////////
B 
    std::cout << "test2DHeader... filter code WITHOUT block..." <SetInput( inputImage 
    );
B composeFilter->SetTransform( transform );
B 
    composeFilter->Update();

B // Create output
B outputImage2 = 
    composeFilter->GetOutput();

B std::cout << "test2DHeader... 
    outputImage2.Direction: " << std::endl;
B std::cout <GetDirection() << std::endl;

B // write it 
    out
B //typedef itk::ImageFileWriter WriterType;
B 
    WriterType::Pointer writer2 = WriterType::New();
B 
    writer2->SetFileName( "testNoBlock_"+outputfilename );
B 
    writer2->SetInput( outputImage2 );
B 
    writer2->Update();

_______________________________________________
Powered 
    by www.kitware.com

Visit other Kitware open-source 
    projects at
http://www.kitware.com/opensource/opensource.html

Kitware 
    offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.html

Please 
    keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to 
    subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers





-------------- next part --------------
A non-text attachment was scrubbed...
Name: HeaderWriteProblem.zip
Type: application/octet-stream
Size: 5951 bytes
Desc: not available
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20101101/28c9e38a/attachment.obj>


More information about the Insight-developers mailing list