|
|
(4 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
| Note: You will need an ITK version as of 5/17/2011 for this functionality.
| | {{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. |
| | }} |
|
| |
|
| ==MultiplyByConstantImageFilter.cxx==
| | [https://itk.org/ITKExamples[ITK Sphinx Examples]] |
| <source lang="cpp">
| |
| #include "itkImage.h"
| |
| #include "itkMultiplyImageFilter.h"
| |
| #include "itkImageRegionConstIterator.h"
| |
| | |
| typedef itk::Image<unsigned char, 2> ImageType;
| |
| | |
| static 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::MultiplyImageFilter<ImageType, ImageType, ImageType> MultiplyImageFilterType;
| |
| MultiplyImageFilterType::Pointer multiplyImageFilter = MultiplyImageFilterType::New();
| |
| multiplyImageFilter->SetInput(image);
| |
| multiplyImageFilter->SetConstant2(3);
| |
| multiplyImageFilter->Update();
| |
| | |
| OutputImage(multiplyImageFilter->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>
| |
| | |
| {{ITKCMakeLists|MultiplyByConstantImageFilter|vtkHybrid}}
| |