|
|
(2 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| ==MovingHistogramImageFilter.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 "itkMovingHistogramImageFilter.h"
| |
| #include "itkFlatStructuringElement.h"
| |
|
| |
|
| typedef itk::Image<unsigned char, 2> ImageType;
| | [https://itk.org/ITKExamples[ITK Sphinx Examples]] |
|
| |
| void CreateImage(ImageType::Pointer image);
| |
| | |
| template <typename T>
| |
| class MyHistogram
| |
| {
| |
| public:
| |
| void AddPixel(T pixel)
| |
| {
| |
| std::cout << "AddPixel " << static_cast<int>(pixel) << std::endl;
| |
| }
| |
|
| |
| void AddBoundary()
| |
| {
| |
| std::cout << "AddBoundary" << std::endl;
| |
| }
| |
|
| |
| T GetValue(T pixel)
| |
| {
| |
| std::cout << "GetValue" << std::endl;
| |
| return 0;
| |
| }
| |
| | |
| void RemovePixel(T pixel)
| |
| {
| |
| std::cout << "RemovePixel " << static_cast<int>(pixel) << std::endl;
| |
| }
| |
| | |
| void RemoveBoundary()
| |
| {
| |
| std::cout << "RemoveBoundary" << std::endl;
| |
| }
| |
| };
| |
| | |
| int main(int argc, char*argv[])
| |
| {
| |
| typedef itk::FlatStructuringElement<2> StructuringElementType;
| |
| StructuringElementType::RadiusType elementRadius;
| |
| elementRadius.Fill(3); // a 7x7 kernel
| |
| StructuringElementType structuringElement = StructuringElementType::Box(elementRadius);
| |
|
| |
| typedef MyHistogram<unsigned char> HistogramType;
| |
| | |
| ImageType::Pointer image = ImageType::New();
| |
| CreateImage(image);
| |
|
| |
| typedef itk::MovingHistogramImageFilter< ImageType, ImageType, StructuringElementType, HistogramType > MovingHistogramImageFilterType;
| |
| MovingHistogramImageFilterType::Pointer movingHistogramImageFilter = MovingHistogramImageFilterType::New();
| |
| | |
| movingHistogramImageFilter->SetInput(image);
| |
| movingHistogramImageFilter->SetKernel(structuringElement);
| |
| movingHistogramImageFilter->Update();
| |
|
| |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| void CreateImage(ImageType::Pointer image)
| |
| {
| |
| ImageType::IndexType start;
| |
| start.Fill(0);
| |
| | |
| ImageType::SizeType size;
| |
| size.Fill(10);
| |
| | |
| ImageType::RegionType region(start, size);
| |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| image->FillBuffer(0);
| |
| | |
| itk::ImageRegionIterator<ImageType> imageIterator(image,region);
| |
| | |
| while(!imageIterator.IsAtEnd())
| |
| {
| |
| if(imageIterator.GetIndex()[0] < 5)
| |
| {
| |
| imageIterator.Set(255);
| |
| }
| |
| ++imageIterator;
| |
| }
| |
| | |
| }
| |
| | |
| </source>
| |
| | |
| {{ITKCMakeLists|MovingHistogramImageFilter}}
| |