[Insight-users] Pad image with 0 but keep its type what ever it is

Luis Ibanez luis.ibanez at kitware.com
Thu Jan 28 17:00:57 EST 2010


Hi Lynx,


         What *exactly*
         is the problem that you are observing ?


I ran your code on one of the BrainWeb images and
obtained the expected output.

About th methods:

A) SetPadLowerBound : defines how many pixels are
     going to be added in the lower index side of the
     image.  (e.g. in 2D, this is the left and bottom side
     of the image).

B) SetPadUpperBound:  defines how many pixels are
     going to be added in the upper index side of the
     image.  (e.g. in 2D, this is the right and upper side
     of the image).

C) SetPadBound:  Sets both the Lower and Upper
     bounds to the same values.


One of the many great things about Open Source is
that you can answer many of this questions by simply
looking at the code.

For example:

1) ConstantPadImageFilter in
    Insight/Code/BasicFilters/itkConstantPadImageFilter.h
    will tell you that this filter derives from PadImageFilter.

2)  itkPadImageFilter.txx in lines 205-209 shows you how
     is that the lower and upper bound values redefine the
     size of the image.



     "Glimpsing at the Source,
      leaves no Doubt"

                                  Deng Min Dao


--


    Regards,


             Luis,


----------------------------------------------------------------
On Tue, Jan 26, 2010 at 4:23 PM,  <lynx.abraxas at freenet.de> wrote:
> Hello!
>
>
> Is  it  possible  to write a filter-program that takes any type of input image
> (eg. float, ushort, char...) and pads it with zeros which is an allowed  value
> in  any  image  type  (as  far as I know)? See below my code that give already
> trouble with mhd-images since the reader seems not to check if the input image
> type matches the type in the mhd-header. What can I do about that?
> I also wonder what is the difference between SetPadBound, SetPadLowerBound and
> SetPadUpperBound?
>
> Thanks for any help or hints
> Lynx
>
> ____________________________________
>
> #include <itkImageFileReader.h>
> #include <itkImageFileWriter.h>
>
> //#include <itkPadImageFilter.h>
> #include <itkConstantPadImageFilter.h>
> #include "itkFilterWatcher2.h"
>
> int main( int argc, char * argv[] )
>    {
>    if( argc != 4 )
>        {
>        std::cerr << "Usage: " << argv[0];
>        std::cerr << " inputImage";
>        std::cerr << " outputImage";
>        std::cerr << " pad";
>        std::cerr << std::endl;
>        return EXIT_FAILURE;
>        }
>
>    typedef  unsigned short InputPixelType;
>    typedef  unsigned short OutputPixelType;
>
>    const unsigned int Dimension = 3;
>
>    typedef itk::Image<InputPixelType,  Dimension>   InputImageType;
>    typedef itk::Image<OutputPixelType,  Dimension>   OutputImageType;
>
>    typedef itk::ImageFileReader<InputImageType>  ReaderType;
>    typedef itk::ImageFileWriter<OutputImageType>  WriterType;
>    WriterType::Pointer writer = WriterType::New();
>
>    ReaderType::Pointer reader = ReaderType::New();
>    reader->SetFileName(argv[1]);
>
>    typedef itk::ConstantPadImageFilter<InputImageType, OutputImageType> FilterType;
>    FilterType::Pointer filter = FilterType::New();
>
>    //filter->SetConstant(0);
>    unsigned long pad, padding[Dimension];
>    pad= atoi(argv[3]);
>    for (unsigned int i= 0; i < Dimension; i++)
>        padding[i]= pad;
>
>    filter->SetPadLowerBound(padding);
>    filter->SetPadUpperBound(padding);
>
>    filter->SetInput(reader->GetOutput());
>    FilterWatcher watcher(filter, "filter");
>    filter->Update();
>    //std::cout << std::endl;
>
>    writer->SetFileName(argv[2]);
>    writer->SetInput(filter->GetOutput());
>    writer->Update();
>
>    return EXIT_SUCCESS;
>    }
>
>
>
>
> _____________________________________
> 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
>


More information about the Insight-users mailing list