itk中创建一个图像数据
来源:互联网 发布:拜占庭东罗马知乎 编辑:程序博客网 时间:2024/06/02 01:59
关于数据的创建,有几种不同的方法可以用。itk提供了一个专业的类:itkImportImageFilter。它实现了从N维数组转到一个itk类型的image数据。不过方法和之前文《itk中的基本图像操作》中的流程大同小异,分别设置了图像的4大要素:SetRegion(区域),SetOrigin(原点),SetSpacing(间距),SetImportPointer(数据)。这种方法的使用环境更适用于自定义数组数据结构与itk算法之间做接口。
详细如下:
typedef unsigned char PixelType; const unsigned int Dimension = 3; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType; ImportFilterType::Pointer importFilter = ImportFilterType::New(); ImportFilterType::SizeType size; size[0] = 200; // size along X size[1] = 200; // size along Y size[2] = 200; // size along Z ImportFilterType::IndexType start; start.Fill( 0 ); ImportFilterType::RegionType region; region.SetIndex( start ); region.SetSize( size ); importFilter->SetRegion( region ); double origin[ Dimension ]; origin[0] = 0.0; // X coordinate origin[1] = 0.0; // Y coordinate origin[2] = 0.0; // Z coordinate importFilter->SetOrigin( origin ); double spacing[ Dimension ]; spacing[0] = 1.0; // along X direction spacing[1] = 1.0; // along Y direction spacing[2] = 1.0; // along Z direction importFilter->SetSpacing( spacing ); const unsigned int numberOfPixels = size[0] * size[1] * size[2]; PixelType * localBuffer = new PixelType[ numberOfPixels ]; const double radius = 80.0; const double radius2 = radius * radius; PixelType * it = localBuffer; for(unsigned int z=0; z < size[2]; z++) { const double dz = static_cast<double>( z ) - static_cast<double>(size[2])/2.0; for(unsigned int y=0; y < size[1]; y++) { const double dy = static_cast<double>( y ) - static_cast<double>(size[1])/2.0; for(unsigned int x=0; x < size[0]; x++) { const double dx = static_cast<double>( x ) - static_cast<double>(size[0])/2.0; const double d2 = dx*dx + dy*dy + dz*dz; *it++ = ( d2 < radius2 ) ? 255 : 0; //画一个球 三木运算符 } } } const bool importImageFilterWillOwnTheBuffer = true; importFilter->SetImportPointer( localBuffer, numberOfPixels, importImageFilterWillOwnTheBuffer ); output_data = importFilter->GetOutput()
类的源码中有一个关键函数(这个方法的精髓在这里):
SetImportPointer(TPixel *ptr(输入数组的指针), unsigned long num(像素点个数), bool LetFilterManageMemory(让过滤器设置内存???没看懂呢?)){ if (ptr != m_ImportPointer) { if (m_ImportPointer && m_FilterManageMemory) { delete [] m_ImportPointer; } m_ImportPointer = ptr; this->Modified(); } m_FilterManageMemory = LetFilterManageMemory; m_Size = num;}数据生成函数:
GenerateData(){ // Normally, GenerateData() allocates memory. However, the application // provides the memory for this filter via the SetImportPointer() method. // Therefore, this filter does not call outputPtr->Allocate(). // get pointer to the output OutputImagePointer outputPtr = this->GetOutput(); // the output buffer size is set to the size specified by the user via the // SetRegion() method. outputPtr->SetBufferedRegion( outputPtr->GetLargestPossibleRegion() ); // pass the pointer down to the container during each Update() since // a call to Initialize() causes the container to forget the // pointer. Note that we tell the container NOT to manage the // memory itself. This filter will properly manage the memory (as // opposed to the container) if the user wants it to. outputPtr->GetPixelContainer()->SetImportPointer( m_ImportPointer, m_Size, false );}
用户需求,产品需求,技术需求;
基本需求,期望需求,兴奋需求;
紧急重要,紧急不重要,不紧急重要,不紧急不重要;
其实不多数事情都能通过产品需求分析使其量化,参数化,这样才能在做决策的时候尽量客观,使风险降到最低。
科学的管理方法是很有用的。
参考文献:
1.https://itk.org/Wiki/ITK/Examples/IO/ImportImageFilter
2.http://blog.csdn.net/ameyume/article/details/6326278
阅读全文
0 0
- itk中创建一个图像数据
- itk数据表达之 创建图像
- ITK: 读序列图像和裸数据
- 图像数据在ITK和VTK之间转换
- ITK IOBase 图像属性
- 利用ITK旋转图像
- itk中的图像归一化
- CMake创建ITK程序
- ITK读DICOM数据
- ITK数据表达
- 创建一个集合图像
- ITK图像配准介绍
- ITK图像分割三个示例
- ITK学习笔记:图像FFT
- ITK的图像配准
- 医学图像处理工具包ITK
- ITK resample图像重采样
- ITK图像读写及显示
- 001-第一个C程序,hello
- Java后台框架篇--使用SpringSocial 连接社交网络
- 一些爱不释手的 Chrome 插件
- Mysql安装步骤(1)源码编译
- IIC介绍(三)之主机介绍
- itk中创建一个图像数据
- oracle数据结构
- 洛谷 P3383 【模板】线性筛素数
- 使用VS2013编写Python程序时出现编码问题的解决办法
- 欢迎使用CSDN-markdown编辑器
- OpenStack 存储服务 Cinder存储节点部署NFS
- 利用Qt进行接口间通信
- Java移动框架篇--Spring mobile简单试用
- 电脑配置、硬件