当前位置:网站首页>itk neighbhood
itk neighbhood
2022-06-12 12:41:00 【April 16!】
#include "itkImage.h"
#include "itkNeighborhoodOperatorImageFunction.h"
#include "itkNeighborhoodOperator.h"
using UnsignedCharImageType = itk::Image<unsigned char, 3>;
static void
CreateImage(UnsignedCharImageType::Pointer image);
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
std::array<int, 6> elment6 = {4,10,12,14,16,22};
std::array<int, 18> elment18 = { 1,3,4,5,7,9,10,11,12,14,15,16,17,19,21,22,23,25 };
itk::Neighborhood<float, 3> neighborhood6, neighborhood18,neighborhood26;
neighborhood6.SetRadius(1);
neighborhood18.SetRadius(1);
neighborhood26.SetRadius(1);
for (unsigned int i = 0; i < neighborhood26.GetSize()[0] * neighborhood26.GetSize()[1]* neighborhood26.GetSize()[2]; ++i)
{
neighborhood18[i] = 0;
neighborhood6[i] = 0;
neighborhood26[i] = 1;
}
neighborhood26[13] = 0;
for (auto index : elment6)
{
neighborhood6[index] = 1;
}
for (auto index : elment18)
{
neighborhood18[index] = 1;
}
itk::Neighborhood<float, 3> neighborhood_6_18, neighborhood_18_26;
neighborhood_6_18.SetRadius(1);
neighborhood_18_26.SetRadius(1);
for (unsigned int i = 0; i < neighborhood26.GetSize()[0] * neighborhood26.GetSize()[1] * neighborhood26.GetSize()[2]; ++i)
{
neighborhood_6_18[i] = neighborhood18[i] - neighborhood6[i];
neighborhood_18_26[i] = neighborhood26[i] - neighborhood18[i];
}
std::cout << neighborhood6.GetOffset(4) << "\n";
// std::cout << neighborhood6.Get << "\n";
using NeighborhoodOperatorImageFunctionType = itk::NeighborhoodOperatorImageFunction<UnsignedCharImageType, float>;
auto neighborhoodOperatorImageFunction = NeighborhoodOperatorImageFunctionType::New();
neighborhoodOperatorImageFunction->SetOperator(neighborhood6);
neighborhoodOperatorImageFunction->SetInputImage(image);
auto neighborhoodOperatorImageFunction18 = NeighborhoodOperatorImageFunctionType::New();
neighborhoodOperatorImageFunction18->SetOperator(neighborhood18);
neighborhoodOperatorImageFunction18->SetInputImage(image);
auto neighborhoodOperatorImageFunction26 = NeighborhoodOperatorImageFunctionType::New();
neighborhoodOperatorImageFunction26->SetOperator(neighborhood26);
neighborhoodOperatorImageFunction26->SetInputImage(image);
auto neighborhoodOperatorImageFunction12 = NeighborhoodOperatorImageFunctionType::New();
neighborhoodOperatorImageFunction12->SetOperator(neighborhood_6_18);
neighborhoodOperatorImageFunction12->SetInputImage(image);
auto neighborhoodOperatorImageFunction8 = NeighborhoodOperatorImageFunctionType::New();
neighborhoodOperatorImageFunction8->SetOperator(neighborhood_18_26);
neighborhoodOperatorImageFunction8->SetInputImage(image);
{
itk::Index<3> index;
index.Fill(30);
float output6 = neighborhoodOperatorImageFunction->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output6 << std::endl;
float output18 = neighborhoodOperatorImageFunction18->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output18 << std::endl;
float output26 = neighborhoodOperatorImageFunction26->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output26 << std::endl;
float output12 = neighborhoodOperatorImageFunction12->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output12 << std::endl;
float output8 = neighborhoodOperatorImageFunction8->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output8 << std::endl;
}
return EXIT_SUCCESS;
}
void
CreateImage(UnsignedCharImageType::Pointer image)
{
// Create an image with 2 connected components
UnsignedCharImageType::IndexType start;
start.Fill(0);
UnsignedCharImageType::SizeType size;
size.Fill(100);
UnsignedCharImageType::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// Make a square
for (unsigned int r = 20; r < 80; r++)
{
for (unsigned int c = 20; c < 80; c++)
{
for (unsigned int u = 20; u < 80; u++)
{
UnsignedCharImageType::IndexType pixelIndex;
pixelIndex[0] = r;
pixelIndex[1] = c;
pixelIndex[2] = u;
image->SetPixel(pixelIndex, 10);
}
}
}
}
边栏推荐
- 关于派文的问题
- Simple picture preview
- Dom and BOM in JS
- Part of the fourth Zhejiang CTF finals
- AND THE BIT GOES DOWN: REVISITING THE QUANTIZATION OF NEURAL NETWORKS
- Records of gdcpc Guangdong Provincial Games in 22 years
- LDAP和SSO集成能实现什么效果?
- 快速下载谷歌云盘大文件的5种方法
- Congratulations to splashtop for winning the 2022 it Europa "vertical application solution of the year" award
- Binary tree (program)
猜你喜欢

Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference

Time series database - incluxdb2 docker installation

When to use binary search

Attack and defense world re (New 1 hand zone) questions 1-12

数组——双指针技巧秒杀七道数组题目

C语言进阶篇——万字详解指针和qsort函数

一个ES设置操作引发的“血案”

提升管道效率:你需要知道如何识别CI/CD管道中的主要障碍

Binary tree (thoughts)

Object. Detailed explanation of assign()
随机推荐
Rust language learning
机器人雅可比求解
【C语言】关键字static&&多文件&&猜字游戏
When to use binary search
机械臂雅可比矩阵IK
Numpy numerical calculation basis
常数时间删除/查找数组中的任意元素
ITK Examples/RegistrationITKv4/DeformableRegistration
OpenMAX (OMX)框架
Invalid date of moment conversion timestamp
Micro task, macro task and event loop of JS
AGCO AI frontier promotion (6.12)
Brush questions [de1ctf 2019]shellshellshell
Binary tree (construction)
数组——双指针技巧秒杀七道数组题目
Tron API wave field transfer query interface PHP version package based on thinkphp5 attached interface document 20220602 version deployed interface applicable to any development language
SWI-Prolog的下载与使用
Native JS implements the copy text function
二叉树(思路篇)
Kdd2022 | edge information enhancement graph transformer