[ome-users] SCIFIO hangs reading on Windows
Joe Ping-Lin Hsiao
phsiao at cs.unc.edu
Tue May 28 20:40:05 BST 2013
I have a test program modified from an example I found online. It reads a
4-d image and extract the z-stack from each time step and save it as a
.ome.tiff.
The program works fine on Mac, but on Windows it hangs at
itksysProcess_WaitForData()
in itkSCIFIOImageIO.cxx.
I use the SCIFIO from ITK by enabling fetch_SCIFIO.
Here is the the code:
#if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include
<iostream> #include <fstream> #include "itkSCIFIOImageIO.h" #include
"itkImageFileReader.h" #include "itkImageFileWriter.h" #include
"itkImage.h" #include "itkRGBPixel.h" #include "itkMetaDataObject.h"
#include "itkExtractImageFilter.h" #include <itkImageIORegion.h> #if
defined(ITK_USE_MODULAR_BUILD) #define SPECIFIC_IMAGEIO_MODULE_TEST #endif
int main( int argc, char * argv [] ) { if( argc < 2) { std::cerr << "Usage:
" << argv[0] << " input"; return EXIT_FAILURE; } typedef unsigned short
PixelType; const unsigned int Dimension = 4; typedef itk::Image< PixelType,
Dimension > ImageType; typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageIORegion ImageIORegionType; typedef
itk::ImageFileWriter<ImageType> WriterType; typedef
itk::ExtractImageFilter<ImageType, ImageType> ExtractImageFilter; // This
ImageIO won't actually be used, it's just a reference to remember how many
// T-slices there are, as the extracted ImageIO will be truncated.
itk::SCIFIOImageIO::Pointer io = itk::SCIFIOImageIO::New(); io->DebugOn();
std::string inputFilename = argv[1]; std::cout << argv[1] << std::endl;
std::cout << "before setfilename" << std::endl; io->SetFileName(argv[1]);
std::cout << "after setfilename" << std::endl; io->ReadImageInformation();
std::cout << "after readImageInformation" << std::endl; unsigned int
numberOfDim = io->GetNumberOfDimensions(); // Similarly this region will be
reused to ensure when we know how big the image is when // we try to
extract a single T-slice ImageIORegionType region(4); for( unsigned long i
= 0; i < numberOfDim; i++ ) { std::cout << "Setting index: " << i << " to:
" << io->GetDimensions(i) << std::endl; region.SetIndex( i, 0 );
region.SetSize( i, io->GetDimensions(i) ); } ReaderType::Pointer reader =
ReaderType::New(); reader->SetFileName(argv[1]); reader->UseStreamingOn();
WriterType::Pointer writer = WriterType::New(); for( unsigned int i = 0; i
< region.GetSize( numberOfDim-1 ); i++ ) { std::cout << i << std::endl; //
When I was persisting these objects between iterations I ran into // I ran
into errors based on remembering the wrong region sizes
itk::SCIFIOImageIO::Pointer imageIO = itk::SCIFIOImageIO::New();
ExtractImageFilter::Pointer extractor = ExtractImageFilter::New();
imageIO->DebugOn(); imageIO->SetFileName(argv[1]);
imageIO->SetUseStreamedReading(true); imageIO->SetUseStreamedWriting(true);
// reset to the largest possible region, so that the extraction region is
contained imageIO->SetIORegion( region ); imageIO->ReadImageInformation();
reader->SetImageIO(imageIO); std::cout << "ImageIO Region: " << imageIO <<
std::endl; ImageType::IndexType start; ImageType::SizeType size; for(
unsigned int j = 0; j < numberOfDim; j++ ) { start[j] = 0; size[j] =
io->GetDimensions(j); } start[ numberOfDim-1 ] = i; //size[ numberOfDim-2 ]
= 1; size[ numberOfDim-1 ] = 1; ImageType::RegionType desiredRegion;
desiredRegion.SetSize(size); desiredRegion.SetIndex(start);
extractor->SetExtractionRegion(desiredRegion); std::cout << "Region of
extraction: " << extractor->GetExtractionRegion() << std::endl; std::cout
<< "Largest possible reader region, pre-update: " <<
reader->GetImageIO()->GetIORegion() << std::endl;
extractor->SetInput(reader->GetOutput()); extractor->Update(); std::cout <<
"Largest possible reader region, post-update: " <<
reader->GetImageIO()->GetIORegion() << std::endl; std::ostringstream
istream; istream << i << ".ome.tiff"; std::string fname = istream.str();
writer->SetFileName( fname.c_str() ); writer->SetImageIO(imageIO);
writer->SetInput(extractor->GetOutput()); try { writer->Update(); } catch
(itk::ExceptionObject &e) { std::cerr << e << std::endl; return
EXIT_FAILURE; } } return EXIT_SUCCESS; }
Best,
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-users/attachments/20130528/4fcd49e3/attachment.html>
More information about the ome-users
mailing list