[Insight-users] 3D level set segmentation: How to use the ImageSeriesWriter
Luis Ibanez
luis.ibanez at kitware.com
Wed Jul 23 10:34:24 EDT 2008
Hi John,
Please take a look at the examples:
Insigtht/Examples/IO
ImageSeriesReadWrite.cxx
ImageSeriesReadWrite2.cxx
and if you continue experiencing any problems
please post your source code to the mailing list.
Reading a series and writing a series should be
a very straight forward task.
Thanks
Luis
-------------------
John Dailey wrote:
> I am having problems with extending geodesic active contours to 3d as
> well. I am fairly certain that my problems are related to how I try
> to write the image out at the end of the pipeline.
>
> I sent the following message to the list a few days ago, but I haven't
> gotten any responses (actually no message I have sent to the list in
> the last month has gotten any responses, I am starting to wonder if
> there is something wrong with how I am sending to the list. Are you
> folks getting my emails?)
>
> Thanks,
> John
>
> <begin quoted message>
> I am having some problems using the itkImageSeriesWriter. I am quite
> certain that I must be setting things up wrong, or not understanding
> what it is supposed to be used for, or something.
>
> In debugging my 3d segmentation code, I realized that I can't even get
> the image series writer to work (and that might be why my segmentation
> isn't working).
>
> I wrote a little code that runs the ImageSeriesReader, casts the pixel
> type and then runs the ImageSeriesWriter (going to a different file
> name). The code doesn't do anything (it should result in a copy of my
> image series, right?), and I am hoping someone can help me figure out
> why. One thing I noticed that I think might be relevant is that when
> I just call update on the reader, or the caster instead of the writer,
> the runtime of the code is much longer. Like it is reading the images
> and casting them in the case where update is called on the caster
> rather than the writer, where when it is called on the writer, the
> code just returns...
>
> Any ideas?
>
> Thanks for helping me out, I am still trying to figure out how ITK works...
>
> -John
>
>
>
>
>
> Here is the program I wrote:
>
> #include "itkImage.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include <iostream>
> #include <string>
>
> #include "itkImageSeriesWriter.h"
> #include "itkImageSeriesReader.h"
> #include "itkNumericSeriesFileNames.h"
> #include "itkPNGImageIO.h"
>
>
> int main( int argc, char *argv[] )
> {
> if( argc < 4 )
> {
> std::cerr << "Missing Parameters " << std::endl;
> std::cerr << "Usage: " << argv[0];
> std::cerr << " inputImage outputImage #ofSlices" << std::endl;
> return 1;
> }
>
> typedef float InternalPixelType;
> const unsigned int Dimension = 3;
> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
>
> typedef unsigned char OutputPixelType;
> typedef itk::Image< OutputPixelType, Dimension-1 > OutputImageType;
> typedef itk::Image< OutputPixelType, Dimension > OutputSeriesType;
>
>
>
> // We instantiate reader and writer types in the following lines.
> //
> typedef itk::NumericSeriesFileNames NameGeneratorType;
>
> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
> const std::string infilebase = argv[1];
> const unsigned int first = 0;
> const unsigned int last = atoi( argv[3] );
>
> std::string seriesFormat = infilebase+"%03d.png";
> nameGenerator->SetSeriesFormat(seriesFormat.c_str());
> nameGenerator->SetStartIndex(first);
> nameGenerator->SetEndIndex(last);
> nameGenerator->SetIncrementIndex(1);
> std::cout <<"seriesFormat:"<<seriesFormat.c_str()<<std::endl;
>
> NameGeneratorType::Pointer outGenerator = NameGeneratorType::New();
> const std::string outfilebase = argv[2];
>
> std::string outFormat = outfilebase+"%03d.png";
> outGenerator->SetSeriesFormat(outFormat.c_str());
> outGenerator->SetStartIndex(first);
> outGenerator->SetEndIndex(last);
> outGenerator->SetIncrementIndex(1);
>
> typedef itk::ImageSeriesReader< InternalImageType > ReaderType;
> typedef itk::ImageSeriesWriter< OutputImageType, OutputSeriesType
>
>>WriterType;
>
>
> ReaderType::Pointer reader = ReaderType::New();
> WriterType::Pointer writer = WriterType::New();
>
> reader->SetImageIO(itk::PNGImageIO::New());
> reader->SetFileNames(nameGenerator->GetFileNames());
>
> writer->SetImageIO(itk::PNGImageIO::New());
> writer->SetFileNames(outGenerator->GetFileNames());
>
> typedef itk::RescaleIntensityImageFilter<
> InternalImageType,
> OutputImageType > CastFilterType;
>
> CastFilterType::Pointer casterA = CastFilterType::New();
> casterA->SetInput(reader->GetOutput() );
> writer->SetInput( casterA->GetOutput() );
>
>
> try
> {
> //casterA->Update();
> writer->UpdateLargestPossibleRegion();
> }
> catch( itk::ExceptionObject & excep )
> {
> std::cerr << "Exception caught !" << std::endl;
> std::cerr << excep << std::endl;
> }
>
>
> return 0;
> }
> <end quoted message>
>
>
>
>
> On Fri, Jul 18, 2008 at 7:48 AM, Luca Antiga <luca.antiga at gmail.com> wrote:
>
>>Dear Gokhan,
>> geodesic active contours have been widely used even in large datasets
>>(surely larger than the ones you're mentioning), provided you have enough
>>memory available.
>>One of two things may be happening:
>>1. you're not running out of memory and your operative system starts
>>swapping on the virtual memory
>>2. there's a problem with the way you extended the code to 3D.
>>The first point is easy to check (just look at a memory monitor or listen to
>>the sounds emitted by your hard drive). For the second, you'll have to post
>>a code snippet for us to take a look.
>>Regards
>>
>>Luca
>>
>>
>>
>>On Jul 18, 2008, at 4:35 PM, Gokhan Mustafa Uzunbas wrote:
>>
>>
>>>Dear ITK users I am tring to do a level set based segmentation using
>>>GeodesicActiveContourImageFilter.cxx sample in ITK. 2D works fine but when I
>>>try on 3D data I observed that fast marching filter can not initialize a
>>>simple sphere although I gave seed points and radius. It gets in a while
>>>loop in FastMarchingImageFilter to compute a signed distance function and
>>>can not get out.
>>>I do not know how much more I should wait but it seems it is not usable
>>>when image dimensions are 500 x 500 x 25.
>>>Are there anyone who could succeed to run those segmentation filters in
>>>3D?
>>>If anyone could help or point me, please? Thank you in advance.
>>>
>>>Gokhan
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
More information about the Insight-users
mailing list