|
|
(One intermediate revision by one other user not shown) |
Line 1: |
Line 1: |
| ==ClampImageFilter.cxx== | | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions. |
| <source lang="cpp">
| | }} |
| #include "itkImage.h"
| |
| #include "itkImageFileReader.h"
| |
| #include "itkClampImageFilter.h"
| |
| | |
| typedef itk::Image<float, 2> FloatImageType;
| |
| typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
| |
| | |
| static void CreateImage(FloatImageType* const image);
| |
| | |
| int main(int argc, char *argv[])
| |
| {
| |
| FloatImageType::Pointer image;
| |
| | |
| // No input image argument provided
| |
| if(argc < 2)
| |
| {
| |
| image = FloatImageType::New();
| |
| CreateImage(image);
| |
| }
| |
| else // Input image argument provided
| |
| {
| |
| typedef itk::ImageFileReader<FloatImageType> ReaderType;
| |
| ReaderType::Pointer reader = ReaderType::New();
| |
| reader->SetFileName(argv[1]);
| |
| reader->Update();
| |
| image = reader->GetOutput();
| |
| }
| |
| | |
| typedef itk::ClampImageFilter< FloatImageType, UnsignedCharImageType > ClampFilterType;
| |
| ClampFilterType::Pointer clampFilter = ClampFilterType::New();
| |
| clampFilter->SetInput(image);
| |
| clampFilter->Update();
| |
| | |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void CreateImage(FloatImageType* const image)
| |
| {
| |
| // Create an image with 2 connected components
| |
| FloatImageType::IndexType corner = {{0,0}};
| |
| | |
| FloatImageType::SizeType size;
| |
| unsigned int NumRows = 200;
| |
| unsigned int NumCols = 300;
| |
| size[0] = NumRows;
| |
| size[1] = NumCols;
| |
| | |
| FloatImageType::RegionType region(corner, size); | |
| | |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| | |
| // Make a square
| |
| for(unsigned int r = 40; r < 100; r++)
| |
| {
| |
| for(unsigned int c = 40; c < 100; c++)
| |
| {
| |
| FloatImageType::IndexType pixelIndex;
| |
| pixelIndex[0] = r;
| |
| pixelIndex[1] = c;
| |
| | |
| image->SetPixel(pixelIndex, 15);
| |
| }
| |
| }
| |
| }
| |
| | |
| </source>
| |
| | |
| {{ITKVTKCMakeLists|ClampImageFilter|}}
| |