|
|
(9 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
| ==MultiplyByConstantImageFilter.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 "itkMultiplyByConstantImageFilter.h"
| |
| #include "itkImageRegionConstIterator.h"
| |
|
| |
|
| typedef itk::Image<unsigned char, 2> ImageType;
| | [https://itk.org/ITKExamples[ITK Sphinx Examples]] |
| | |
| void OutputImage(ImageType::Pointer image);
| |
| | |
| int main( int argc, char *argv[])
| |
| {
| |
|
| |
| ImageType::Pointer image = ImageType::New();
| |
|
| |
| itk::Index<2> start;
| |
| start.Fill(0);
| |
| | |
| itk::Size<2> size;
| |
| size.Fill(3);
| |
| | |
| itk::ImageRegion<2> region(start, size);
| |
| | |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| image->FillBuffer(2);
| |
| | |
| OutputImage(image);
| |
| | |
| typedef itk::MultiplyByConstantImageFilter<ImageType, unsigned char, ImageType> MultiplyByConstantImageFilterType;
| |
| MultiplyByConstantImageFilterType::Pointer multiplyByConstantImageFilter = MultiplyByConstantImageFilterType::New();
| |
| multiplyByConstantImageFilter->SetInput(image);
| |
| multiplyByConstantImageFilter->SetConstant(3);
| |
| multiplyByConstantImageFilter->Update();
| |
| | |
| OutputImage(multiplyByConstantImageFilter->GetOutput());
| |
|
| |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void OutputImage(ImageType::Pointer image)
| |
| {
| |
| itk::ImageRegionConstIterator<ImageType> imageIterator(image,image->GetLargestPossibleRegion());
| |
| | |
| while(!imageIterator.IsAtEnd())
| |
| {
| |
| // Get the value of the current pixel
| |
| unsigned char val = imageIterator.Get();
| |
| std::cout << (int)val << std::endl;
| |
| | |
| ++imageIterator;
| |
| }
| |
| | |
| }
| |
| </source>
| |
| | |
| ==CMakeLists.txt==
| |
| <source lang="cmake">
| |
| cmake_minimum_required(VERSION 2.6)
| |
| | |
| PROJECT(MultiplyByConstantImageFilter)
| |
| | |
| FIND_PACKAGE(ITK REQUIRED)
| |
| INCLUDE(${ITK_USE_FILE})
| |
| | |
| ADD_EXECUTABLE(MultiplyByConstantImageFilter MultiplyByConstantImageFilter.cxx)
| |
| TARGET_LINK_LIBRARIES(MultiplyByConstantImageFilter ITKIO)
| |
| | |
| </source>
| |