ITK/Examples/Images/ShrinkImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Procedures should be static for test driver)
Line 8: Line 8:
typedef itk::Image<unsigned char, 2>  ImageType;
typedef itk::Image<unsigned char, 2>  ImageType;


void CreateImage(ImageType::Pointer image);
static void CreateImage(ImageType::Pointer image);


int main(int, char *[])
int main(int, char *[])
Line 16: Line 16:


   std::cout << "Original size: " << image->GetLargestPossibleRegion().GetSize() << std::endl;
   std::cout << "Original size: " << image->GetLargestPossibleRegion().GetSize() << std::endl;
 
 
   typedef itk::ShrinkImageFilter <ImageType, ImageType>
   typedef itk::ShrinkImageFilter <ImageType, ImageType>
           ShrinkImageFilterType;
           ShrinkImageFilterType;
Line 60: Line 60:
     }
     }
}
}
</source>
</source>



Revision as of 16:37, 1 March 2011

ShrinkImageFilter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileWriter.h"
  3. include "itkRescaleIntensityImageFilter.h"
  4. include "itkShrinkImageFilter.h"

typedef itk::Image<unsigned char, 2> ImageType;

static void CreateImage(ImageType::Pointer image);

int main(int, char *[]) {

 ImageType::Pointer image = ImageType::New();
 CreateImage(image);
 std::cout << "Original size: " << image->GetLargestPossibleRegion().GetSize() << std::endl;
 typedef itk::ShrinkImageFilter <ImageType, ImageType>
         ShrinkImageFilterType;
 ShrinkImageFilterType::Pointer shrinkFilter
         = ShrinkImageFilterType::New();
 shrinkFilter->SetInput(image);
 shrinkFilter->SetShrinkFactor(0, 2); // shrink the first dimension by a factor of 2 (i.e. 100 gets changed to 50)
 shrinkFilter->SetShrinkFactor(1, 3); // shrink the second dimension by a factor of 3 (i.e. 100 gets changed to 33)
 shrinkFilter->Update();
 std::cout << "New size: " << shrinkFilter->GetOutput()->GetLargestPossibleRegion().GetSize() << std::endl;


 return EXIT_SUCCESS;

}

void CreateImage(ImageType::Pointer image) {

 // Create an image with 2 connected components
 ImageType::IndexType start;
 start.Fill(0);
 ImageType::SizeType size;
 size.Fill(100);
 ImageType::RegionType region(start, size);
 image->SetRegions(region);
 image->Allocate();
 image->FillBuffer(0);
 // Make a white square
 for(unsigned int r = 20; r < 80; r++)
   {
   for(unsigned int c = 20; c < 30; c++)
     {
     ImageType::IndexType pixelIndex;
     pixelIndex[0] = r;
     pixelIndex[1] = c;
     image->SetPixel(pixelIndex, 255);
     }
   }

} </source>

CMakeLists.txt

<source lang="cmake">

cmake_minimum_required(VERSION 2.6)

PROJECT(ShrinkImageFilter)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ShrinkImageFilter ShrinkImageFilter.cxx) TARGET_LINK_LIBRARIES(ShrinkImageFilter ITKBasicFilters ITKCommon ITKIO)

</source>