[Insight-users] crop and flip images

Luis Ibanez luis . ibanez at kitware . com
Fri, 28 Nov 2003 11:06:27 -0500


Hi Stefan,

Thanks for letting us know that the program works for you.

I agree with you in that the initial display of the image
in ImageViewer is a bit confusing since it uses by default
a window size that is not associated to the actual image
size.

We should probably add an option to the ImageViewer in order
to scale the window to the image size or the image to the
window size.

Could you please log this as a "feature request" in the Bug
tracker  ?

The bug tracker is publicly available, you just need to
create your own account. Simply put your email, make up
your own password and click on the button "email password".

              http://www . itk . org/Bug/

Anybody can log bugs in this system. We visit the bug database
periodically and prioritize the entries in order to fix things.

Please let us know if you find any problem loging the bug entry.


Thanks


   Luis


----------------------------------------------
Stefan Lindenau wrote:
> Hi Luis,
> 
> you are right everything is working fine.
> 
> I was only confused by the output of the ImageViewer application from 
> InsightApplications.
> When you open some files (the 
> Insight/Examples/Data/BrainProtonDensitySlice.png is an example) it is 
> not showing the complete file. You first have to resize the window in 
> horizontal direction to see everything. As I did that, I saw that 
> everything was as expected.
> 
> Thanks
> Stefan
> 
> Luis Ibanez wrote:
> 
>>
>> Hi Stefan,
>>
>> Your program fine works for me.
>>
>> I tried using the image
>>
>>   Insight/Data/Examples/BrainProtonDensitySlice.png
>>
>> and setting the parameters of the region to
>>
>>   const int xStart=60,yStart=80,xExtent=100,yExtent=100;
>>
>> and uncommenting line 128
>>
>>   flipAxesSet[1]=true;
>>
>> The output image is as expected, the vertical flip
>> of the region starting at (60,80) and with size (100,100).
>> Your program is extracting the region and flipping it
>> as expected.
>>
>>
>> Can you describe in more detail what you find to be
>> incorrect in this output ?
>>
>> Thanks
>>
>>
>>   Luis.
>>
>>
>>
>> ----------------------------------
>>
>> Stefan Lindenau wrote:
>>
>>> Hi all,
>>>
>>> I have a little problem while processing my images.
>>> When I use RegionOfInterestImageFilter and FlipImageFilter one after 
>>> the other in the pipeline, the result is not the same image just 
>>> flipped along the specified axis.
>>>
>>> Is this the right way? I have my sourcecode attached. So you can  see 
>>> how I set up the pipeline and the region of interest.
>>>
>>> Thank you
>>> stefan
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>>
>>> #include "itkRGBPixel.h"
>>> #include "itkImage.h"
>>> #include "itkImageFileReader.h"
>>> #include "itkImageFileWriter.h"
>>> #include "itkMetaImageIO.h"
>>> #include "itkImageIOBase.h"
>>> #include "itkRegionOfInterestImageFilter.h"
>>> #include "itkFlipImageFilter.h"
>>>
>>>
>>>
>>>
>>> int main(int argc, char ** argv) {
>>>        //These parameters are hardcoded. This program is only for 
>>> helping purposes.
>>>     const int xStart=648,yStart=0,xExtent=464,yExtent=672;
>>>
>>>     std::cout << "This program resizes the input file with the 
>>> following parameters"<<std::endl;
>>>     std::cout << "x starting value: " << xStart<<std::endl;
>>>     std::cout << "y starting value: " << yStart<<std::endl;
>>>     std::cout << "x extension     : " << xExtent << std::endl;
>>>     std::cout << "y extension     : " << yExtent << std::endl;
>>>     std::cout << "==========================="<<std::endl<<std::endl;
>>>
>>>
>>>     if(argc!=3) {
>>>         std::cerr<<"Invalid command line options provided!"<<std::endl;
>>>         std::cerr<<"Pls use the program in the following 
>>> manner:"<<std::endl<<std::endl;
>>>         std::cerr<<argv[0]<<" inputFile outputFile"<<std::endl;
>>>         return -1;
>>>     }
>>>         /*
>>>     Typedefs to use the ITK in a fashionable manner
>>>         */
>>>     typedef itk::RGBPixel<unsigned char>    PixelType;
>>>     typedef itk::Image<PixelType, 2>        ImageType;
>>>
>>>     typedef itk::ImageFileReader< ImageType> ReaderType;
>>>     typedef itk::ImageFileWriter< ImageType> WriterType;
>>>
>>>     typedef itk::RegionOfInterestImageFilter<ImageType,ImageType> 
>>>                                              CropFilterType;
>>>     typedef itk::FlipImageFilter< ImageType> FlipType;
>>>        /*
>>>     Declaration of Variables and Pointers
>>>
>>>     */
>>>     ReaderType::Pointer reader = ReaderType::New();
>>>     WriterType::Pointer writer = WriterType::New();
>>>        CropFilterType::Pointer crop = CropFilterType::New();
>>>
>>>     ImageType::RegionType region;
>>>     ImageType::SizeType        size;
>>>     ImageType::IndexType    index;
>>>
>>>     FlipType::Pointer flip =FlipType::New();
>>>     FlipType::FlipAxesArrayType flipAxesSet;
>>>         /*
>>>     Setting of the filenames of the input and output files
>>>     currently command line options are used to determine them
>>>     */
>>>     std::string input  = argv[1];
>>>     std::string output = argv[2];
>>>
>>>         /*
>>>     Setting up and performing InputIO
>>>
>>>     */
>>>     reader->SetFileName( input.c_str() );
>>>     reader->ReleaseDataFlagOn();
>>>     try         {
>>>         reader->Update();
>>>         }     catch (itk::ExceptionObject &err)         {
>>>         std::cout<< "Exception caught:" << std::endl;
>>>         std::cout<< err <<std::endl;
>>>                return -1;
>>>         }
>>>         /*
>>>     Getting the region we want to extract. The Image is only cropped
>>>     in XY Dimensions the Z Dimension keeps unchanged
>>>
>>>     */
>>>     region=reader->GetOutput()->GetLargestPossibleRegion();
>>>     index=region.GetIndex();
>>>     size=region.GetSize();
>>>
>>>     index.SetElement(0,xStart);
>>>     index.SetElement(1,yStart);
>>>         size.SetElement(0,xExtent);
>>>     size.SetElement(1,yExtent);
>>>
>>>    
>>>     region.SetSize(size);
>>>     region.SetIndex(index);
>>>    
>>>     /*
>>>     Setup of crop ImageFilter
>>>
>>>     */
>>>     crop->SetInput(reader->GetOutput());
>>>     crop->SetRegionOfInterest(region);
>>>     crop->ReleaseDataFlagOn();
>>>
>>>     /*
>>>     We have to flip the Image in Y Direction.
>>>
>>>     */
>>>     flip->SetInput(crop->GetOutput());
>>>     flip->ReleaseDataFlagOn();
>>>         flipAxesSet=flip->GetFlipAxes();
>>>     //flipAxesSet[1]=true;
>>>     flip->SetFlipAxes(flipAxesSet);
>>>    
>>>     /*
>>>     Of course we want to write the image to the HDD
>>>
>>>     */
>>>     writer->SetFileName( output.c_str() );
>>>     writer->SetInput( flip->GetOutput() );
>>>
>>>         /*
>>>     The invocation of the pipeline should cause the execution of the 
>>> crop and flip
>>>     filters. The image should be read already and therefor resist in 
>>> the main memory.
>>>     */
>>>     try {
>>>         writer->Update();
>>>         }     catch (itk::ExceptionObject &err)         {
>>>         std::cout<< "Exception caught:" << std::endl;
>>>         std::cout<< err <<std::endl;
>>>                return -1;
>>>         }
>>>
>>>     return 0;
>>> }
>>
>>
>>
>>
>>
>>
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>