/* * #%L * Bio-Formats plugin for the Insight Toolkit. * %% * Copyright (C) 2010 - 2012 Insight Software Consortium, and Open Microscopy * Environment: * - Board of Regents of the University of Wisconsin-Madison * - Glencoe Software, Inc. * - University of Dundee * %% * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are * those of the authors and should not be interpreted as representing official * policies, either expressed or implied, of any organization. * * ---------------------------------------------------------------- * Adapted from the Slicer3 project: http://www.slicer.org/ * http://viewvc.slicer.org/viewcvs.cgi/trunk/Libs/MGHImageIO/ * * See slicer-license.txt for Slicer3's licensing information. * * For more information about the ITK Plugin IO mechanism, see: * http://www.itk.org/Wiki/Plugin_IO_mechanisms * #L% */ #if defined(_MSC_VER) #pragma warning ( disable : 4786 ) #endif #include #include "itkBioFormatsImageIO.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImage.h" #include "itkRGBPixel.h" #include "itkMetaDataObject.h" #include "itkStreamingImageFilter.h" #include #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 char PixelType; const unsigned int Dimension = 3; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageFileReader ReaderType; typedef itk::ImageIORegion ImageIORegionType; typedef itk::StreamingImageFilter StreamingFilter; typedef itk::ImageFileWriter WriterType; itk::BioFormatsImageIO::Pointer io = itk::BioFormatsImageIO::New(); //io->DebugOn(); std::string inputFilename = argv[1]; io->SetFileName(argv[1]); io->ReadImageInformation(); unsigned int numberOfDim = io->GetNumberOfDimensions(); ImageIORegionType region(5); 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) ); } //region.SetSize( numberOfDim-2, 1 ); for( unsigned int i = 0; i < io->GetDimensions( numberOfDim-2 ); i++ ) { std::cout << i << std::endl; std::cout << region << std::endl; region.SetIndex( numberOfDim-2, i ); region.SetSize(numberOfDim-2, i+1); io->SetIORegion( region ); std::cout << region << std::endl; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->SetImageIO(io); reader->Update(); std::ostringstream istream; istream << i << ".ome.tiff"; std::string fname = istream.str(); WriterType::Pointer writer = WriterType::New(); writer->SetInput(reader->GetOutput()); writer->SetFileName( fname.c_str() ); std::cout << i << " writer region:\n" << writer->GetIORegion() << std::endl; try { writer->Update(); } catch (itk::ExceptionObject &e) { std::cerr << e << std::endl; return EXIT_FAILURE; } } return EXIT_SUCCESS; }