[Insight-users] Problem generating a 3D volume from a set of slices
Bill Lorensen
bill.lorensen at gmail.com
Wed May 18 12:52:49 EDT 2011
OK here is an example inspired by your questions.
http://itk.org/Wiki/ITK/Examples/IO/VolumeFromSlices
I built it, downloaded your data and ran it like this:
../bin/VolumeFromSlices.exe "/c/lorensen/Data/Dora/Dora00%02dd.png" 1 5
out.mhd
File: c:/lorensen/Data/Dora/Dora0001d.png
File: c:/lorensen/Data/Dora/Dora0002d.png
File: c:/lorensen/Data/Dora/Dora0003d.png
File: c:/lorensen/Data/Dora/Dora0004d.png
File: c:/lorensen/Data/Dora/Dora0005d.png
And it generated a .mhd containing this:
ObjectType = Image
NDims = 3
BinaryData = True
BinaryDataByteOrderMSB = False
CompressedData = False
TransformMatrix = 1 0 0 0 1 0 0 0 1
Offset = 0 0 0
CenterOfRotation = 0 0 0
AnatomicalOrientation = RAI
ElementSpacing = 1 1 1
DimSize = 500 348 5
ElementType = MET_UCHAR
ElementDataFile = out.raw
On Wed, May 18, 2011 at 12:49 PM, Bill Lorensen <bill.lorensen at gmail.com>wrote:
> And you pattern is wrong. It should be;
> Dora00%02dd.png
>
> The first "%02d" is part of the printf format, the second "d" is part of
> your filenames/
>
>
> On Wed, May 18, 2011 at 12:45 PM, Bill Lorensen <bill.lorensen at gmail.com>wrote:
>
>> I do not see the files listed in your screen dump. Are they in the same
>> directory as the .exe file?
>>
>>
>>
>>
>> On Wed, May 18, 2011 at 12:38 PM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>
>>>
>>> Nothing changed. There is exactly the same exception description, without
>>> any details.
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* Insight-Users <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 7:28 PM
>>>
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> I you remove the UpdateLargestPossibleRegion and just use
>>> writer->Update() you will probably get a more descriptive exception
>>> description.
>>>
>>>
>>> On Wed, May 18, 2011 at 12:12 PM, Bill Lorensen <bill.lorensen at gmail.com
>>> > wrote:
>>>
>>> I suspect that it is not finding the files. Show me the exact command
>>> line you are using to run your program. Also provide a directory listing of
>>> the directory containing the files.
>>>
>>> The names generator generates names, it does not check to see if the
>>> names are valid files.
>>>
>>> On Wed, May 18, 2011 at 11:54 AM, Bill Lorensen <bill.lorensen at gmail.com
>>> > wrote:
>>>
>>> Dora,
>>> Can you send to me the 5 png files? I just built an example similar to
>>> yours and it works.
>>>
>>> Bill
>>>
>>>
>>> On Wed, May 18, 2011 at 11:10 AM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> Ok. Thank you a lot!
>>>
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* "insight-users at itk.org" <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 5:30 PM
>>>
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> I'll try to reproduce the problem. Probably not until later though.
>>>
>>> On Wed, May 18, 2011 at 10:12 AM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> Yes. Exactly the same one.
>>>
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* "insight-users at itk.org" <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 5:06 PM
>>>
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> Do you get the same exception message?
>>>
>>> On Wed, May 18, 2011 at 9:07 AM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> It writes me the name of the files, but no .mhd ouput file.
>>>
>>> File: Dora0001.png
>>> File: Dora0002.png
>>> File: Dora0003.png
>>> File: Dora0004.png
>>> File: Dora0005.png
>>>
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* Insight-Users <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 3:27 PM
>>>
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> [please keep the mailing list involved]
>>> Try printing out the generated filenames. Something like:
>>>
>>> std::vector<std::string> names = nameGenerator->GetFileNames();
>>> std::vector<std::string>::iterator nit;
>>>
>>> for (nit = names.begin();
>>> nit != names.end();
>>> nit++)
>>> {
>>> std::cout << "File: " << (*nit).c_str() << std::endl;
>>> }
>>>
>>>
>>>
>>>
>>> On Wed, May 18, 2011 at 8:16 AM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> I've tried all the possibilities. Even if I run BrainModel.exe 1 5
>>> out.mhd the error appears and I don't know why.
>>>
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* Insight-Users <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 3:00 PM
>>>
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> But the program should be run as:
>>> BrainModel.exe 1 5 out.mhd
>>>
>>> at least according to the source you attached.
>>>
>>> On Wed, May 18, 2011 at 2:00 AM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> Hi Bill,
>>>
>>> Yes, the names of the files are correct, but the following error message
>>> appears:
>>> I have verified and the size of the pictures is the same. I don't know
>>> what could be the problem.
>>> Thank you!
>>>
>>> *D:\Lib\Project\Dora\bin\Debug>BrainModel.exe Dora0001d.png
>>> Dora0005d.png out.mhd*
>>> *ExceptionObject caught !*
>>> *
>>> *
>>> *itk::ExceptionObject (00B2F4D8)*
>>> *Location: "void __thiscall itk::ImageFileWriter<class
>>> itk::Image<unsigned char,3*
>>> *> >::Write(void)"*
>>> *File: d:\lib\_itk\source\code\io\itkImageFileWriter.txx*
>>> *Line: 271*
>>> *Description: itk::ERROR: ImageFileWriter(0012F3F8): Largest possible
>>> region does*
>>> * not fully contain requested paste IO regionPaste IO region:
>>> ImageIORegion (00B2*
>>> *F910)*
>>> * Dimension: 3*
>>> * Index: 0 0 0*
>>> * Size: 0 0 1*
>>> *Largest possible region: ImageRegion (00B2F9C4)*
>>> * Dimension: 3*
>>> * Index: [0, 0, 0]*
>>> * Size: [0, 0, 1]*
>>>
>>> ------------------------------
>>> *From:* Bill Lorensen <bill.lorensen at gmail.com>
>>> *To:* Dora Szasz <dora.szasz at yahoo.com>
>>> *Cc:* "insight-users at itk.org" <insight-users at itk.org>
>>> *Sent:* Wednesday, May 18, 2011 7:03 AM
>>> *Subject:* Re: [Insight-users] Problem generating a 3D volume from a set
>>> of slices
>>>
>>> Oops...
>>> Dora0001d.png
>>> Dora0002d.png
>>> Dora0003d.png
>>> ...
>>>
>>>
>>> On Wed, May 18, 2011 at 12:02 AM, Bill Lorensen <bill.lorensen at gmail.com
>>> > wrote:
>>>
>>> What are the names of the file? From your code they should be something
>>> like:
>>> Dora00001d.png
>>> Dora00002d.png
>>> Dora00003d.png
>>> ...
>>>
>>> Is that how your files are named?
>>>
>>> Bill
>>>
>>> On Tue, May 17, 2011 at 4:19 PM, Dora Szasz <dora.szasz at yahoo.com>wrote:
>>>
>>> Hello all,
>>>
>>> I am trying to make a 3D volume using a set of .png images. I want to
>>> obtain a 3D image (for example .mhd), but It doesn't generate any output.
>>> My code is the following:
>>>
>>> #include "itkImage.h"
>>> #include "itkImageSeriesReader.h"
>>> #include "itkImageFileWriter.h"
>>> #include "itkNumericSeriesFileNames.h"
>>> #include "itkPNGImageIO.h"
>>>
>>> int main( int argc, char ** argv )
>>> {
>>> // Verify the number of parameters in the command line
>>> if( argc < 4 )
>>> {
>>> std::cerr << "Usage: " << std::endl;
>>> std::cerr << argv[0] << " firstSliceValue lastSliceValue
>>> outputImageFile " << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>>
>>> typedef unsigned char PixelType;
>>> const unsigned int Dimension = 3;
>>>
>>> typedef itk::Image< PixelType, Dimension > ImageType;
>>> typedef itk::ImageSeriesReader< ImageType > ReaderType;
>>> typedef itk::ImageFileWriter< ImageType > WriterType;
>>>
>>> ReaderType::Pointer reader = ReaderType::New();
>>> WriterType::Pointer writer = WriterType::New();
>>>
>>> const unsigned int first = atoi( argv[1] );
>>> const unsigned int last = atoi( argv[2] );
>>>
>>> const char * outputFilename = argv[3];
>>>
>>> typedef itk::NumericSeriesFileNames NameGeneratorType;
>>>
>>> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
>>>
>>> nameGenerator->SetSeriesFormat( "Dora00%02d.png" );
>>>
>>> nameGenerator->SetStartIndex( first );
>>> nameGenerator->SetEndIndex( last );
>>> nameGenerator->SetIncrementIndex( 1 );
>>>
>>> reader->SetImageIO( itk::PNGImageIO::New() );
>>> reader->SetFileNames( nameGenerator->GetFileNames() );
>>>
>>> writer->SetFileName( outputFilename );
>>> writer->SetInput( reader->GetOutput() );
>>> try
>>> {
>>> writer->UpdateLargestPossibleRegion();
>>> writer->Update();
>>> }
>>> catch( itk::ExceptionObject & err )
>>> {
>>> std::cerr << "ExceptionObject caught !" << std::endl;
>>> std::cerr << err << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>> return EXIT_SUCCESS;
>>> }
>>>
>>> 1. How could I modify it in order to obtain the volume?
>>> 2. How could I modify it in order to use "itkImageToVTKImageFilter.h" to
>>> display it on vtk window?
>>>
>>> Thank you a lot!
>>>
>>>
>>> _____________________________________
>>> 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://www.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-users
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110518/90099c59/attachment-0001.htm>
More information about the Insight-users
mailing list