ITK 图像分割(一):阈值ThresholdImageFilter

效果:

1、itkThresholdImageFilter

该类的主要功能是通过设置低阈值、高阈值或介于高低阈值之间,则将图像值输出为用户指定的值。

如果图像值低于、高于或介于设置的阈值之间,该类就将图像值设置为用户指定的“外部”值(默认情况下为“黑色”)。

该类并不对像素进行二值化处理,输出图像中的像素值可以是浮点型或整型。

常用的成员函数:

    Set/GetLower():设置/获取下限阈值Set/GetUpper():设置/获取上限阈值Set/GetOutsideValue():设置/获取“外部”像素值ThresholdAbove():将大于或等于该阈值的值设置为OutsideValueThresholdBelow():将小于或等于该阈值的值设置为OutsideValueThresholdOutside():将超出上下限阈值范围的值设置为 OutsideValue

 Example:

#include "itkImage.h"
#include "itkThresholdImageFilter.h";using namespace itk;const unsigned int  Dimension = 3;       //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;//图像进行阈值分割处理
bool thresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 200;      //设置下阈值const short upperThr = 1000;   //设置上阈值short outsideValue = 0; typedef ThresholdImageFilter<ShortImageType> thresholdFilterType;typename thresholdFilterType::Pointer thresholder = thresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(outsideValue);设置上下阈值//thresholder->SetLower(lowerThr);//thresholder->SetUpper(upperThr);//<下阈值的值均设为outsideValuethresholder->ThresholdBelow(lowerThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}//>上阈值的值均设为outsideValuethresholder->ThresholdAbove(upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}//介于阈值之外的值均设为outsideValuethresholder->ThresholdOutside(lowerThr, upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}

2、itkBinaryThresholdImageFilter

2、itkBinaryThresholdImageFilter

该类的主要功能是通过阈值处理,将输入图像进行二值化。

输出的图像像素只有两个值:OutsideValue或者InsideValue,具体取决于相应的输入图像像素是否位于高低阈值LowerThreshold和UpperThreshold之间,其中当像素值等于任一阈值时,被认为是在阈值之间。
 
 

注意:LowerThreshold不得大于UpperThreshold ,否则会引发异常。

因此,通常仅需要设置其中之一,具体取决于用户是否希望阈值高于或低于期望阈值。

常用的成员函数

    Set/GetInsideValue():设置/获取“内部”像素值Set/GetOutsideValue():设置/获取“外部”像素值Set/GetLowerThreshold():设置/获取低阈值Set/GetUpperThreshold():设置/获取高阈值

与itkThresholdImageFilter相比较,itkBinaryThresholdImageFilter更适用于将图像根据两个阈值进行二值化处理,而itkThresholdImageFilter适用于将图像中符合条件的像素值映射为特定的数值。

Example:

#include "itkImage.h"
#include "itkBinaryThresholdImageFilter.h";using namespace itk;const unsigned int  Dimension = 3;       //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;//图像进行二值化阈值分割处理
bool binaryThresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 0;      //设置二值化的下阈值const short upperThr = 1000;   //设置二值化的上阈值short backGround = 0;          //设置背景值short foreGround = 255;        //设置前景值typedef BinaryThresholdImageFilter<ShortImageType, ShortImageType> BThresholdFilterType;typename BThresholdFilterType::Pointer thresholder = BThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(backGround);thresholder->SetInsideValue(foreGround);thresholder->SetLowerThreshold(lowerThr);thresholder->SetUpperThreshold(upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}

3、itkOtsuThresholdImageFilter

该类的功能是使用最大类间方差法Otsu阈值设置图像阈值。

最大类间方差法:是由日本学者大津(Nobuyuki Otsu)于1979年提出的,是一种自适合于双峰情况的自动求取阈值的方法,又叫大津法,简称Otsu。是一种基于全局的二值化算法。

它是按图像的灰度特性,将图像分成背景和目标两部分。背景和目标之间的类间方差越大,说明构成图像的2部分的差别越大,当部分目标错分为背景或部分背景错分为目标都会导致2部分差别变小。因此,使类间方差最大的分割意味着错分概率最小。

常用的成员函数:

Set/GetInsideValue():设置/获取“内部”像素值
Set/GetOutsideValue():设置/获取“外部”像素值
Set/GetReturnBinMidpoint():设置/获取阈值是bin的中点还是最大值? 默认值是 bin 最大值
ReturnBinMidpointOn():设置/获取阈值是bin的中点还是最大值? 默认值是 bin 最大值
VerifyPreconditions():验证先决条件,验证过程对象是否已正确配置、所有必需的输入是否已设置以及所需的参数是否已正确设置, 如果无效,将抛出异常,在将 UpdateOutputInformation() 传播到输入之前调用此方法,ProcessObject 的实现验证 m_NumberOfRequiredInputs 是否已设置且不为空

Code

#include "itkImage.h"
#include "itkOtsuThresholdImageFilter.h"using namespace itk;const unsigned int  Dimension = 3;       //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;bool OtsuThresholdImage(ShortImageType* image, ShortImageType* outImage)
{short outsideValue = 0;    //设置前景背景值short insideValue = 255;typedef OtsuThresholdImageFilter<ShortImageType, ShortImageType> OtsuThresholdFilterType;typename OtsuThresholdFilterType::Pointer thresholder = OtsuThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(outsideValue);thresholder->SetInsideValue(insideValue);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}

4、itkConnectedThresholdImageFilter

该类的功能是标记连接到种子并位于值范围内的像素。

该类使用ReplaceValue标记连接到初始种子且位于阈值下限和上限范围内的像素。

与itkThresholdImageFilter等前几个类相比,它们虽然都是根据不同像素的灰度值或像素特征将图像分割成不同的区域,但是此类不同的是基于连接像素的原理,通过选择与种子像素相连的像素来进行分割,分割的结果是连通区域,可以灵活地选择不同的种子点和连接条件,得到不同的连通区域。

itkConnectedThresholdImageFilter适用于分割具有明显边界的目标,可以得到分割结果中目标区域的边界比较平滑。而itkThresholdImageFilter/itkBinaryThresholdImageFilter适用于分割目标灰度值较高或较低的区域,可以得到目标区域与背景的清晰分割

常用的成员函数

AddSeed():增加种子点
ClearSeeds():清除种子列表
SetSeed():设置种子点
GetSeeds():获取种子容器
Set/GetLower():设置/获取下限阈值
Set/GetUpper():设置/获取上限阈值
Set/GetUpperInput():设置/获取连接到管道的上阈值输入
Set/GetLowerInput():设置/获取连接到管道的下阈值输入
SetConnectivity():要使用的连接类型(完全连接或 4(2D)、6(3D)、2*N(ND) 连接)
Set/GetReplaceValue():设置/获取值以替换阈值像素, 介于Lower和Upper(含)内的像素将被替换为该值, 默认值为 1

Code:

#include "itkImage.h"
#include "itkConnectedThresholdImageFilter.h"using namespace itk;const unsigned int  Dimension = 3;       //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;bool connectedThresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 0;      //设置二值化的上下阈值const short upperThr = 1000;const short replaceValue = 255;ShortImageType::IndexType seed;seed[0] = 100;     //该值必须在图像的三维大小范围内seed[1] = 100;seed[2] = 25;typedef ConnectedThresholdImageFilter<ShortImageType, ShortImageType> ConnectedThresholdFilterType;typename ConnectedThresholdFilterType::Pointer thresholder = ConnectedThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetLower(lowerThr);thresholder->SetUpper(upperThr);thresholder->SetReplaceValue(replaceValue);thresholder->SetSeed(seed);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/681955.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【电路笔记】-并联电感

并联电感 文章目录 并联电感1、概述2、并联电感示例13、互耦并联电感器4、并联电感示例25、并联电感示例36、总结当电感器的两个端子分别连接到另一个或多个电感器的每个端子时,电感器被称为并联连接在一起。 1、概述 所有并联电感器上的压降将是相同的。 然后,并联的电感器…

如何写好一个简历

如何编写求职简历 论Java程序员求职中简历的重要性 好简历的作用 在求职过程中&#xff0c;一份好的简历是非常重要的&#xff0c;它甚至可以直接决定能否被面试官认可。一份出色或者说是成功的个人简历&#xff0c;最根本的作用是能让看这份简历的人产生一定要见你的强烈愿…

【lesson53】线程控制

文章目录 线程控制 线程控制 线程创建 代码&#xff1a; 运行代码&#xff1a; 强调一点&#xff0c;线程和进程不一样&#xff0c;进程有父进程的概念&#xff0c;但在线程组里面&#xff0c;所有的线程都是对等关系。 错误检查: 传统的一些函数是&#xff0c;成功返回0&…

Java基于 SpringBoot 的高校校园点餐系统,附源码

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝12w、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;…

BTC破5W+QAQ

比特币突破5万美元 创2021年来最高 比特币在龙年伊始涨超6.8%。在大年初四&#xff08;2月13日&#xff09;一度最高涨至5万零383美元。 今年1月&#xff0c;当市场期待已久的现货比特币交易所挂牌基金&#xff08;ETF&#xff09;推出后&#xff0c;比特币遭抛售&#xff0c…

01.数据结构篇-链表

1.找出两个链表的交点 160. Intersection of Two Linked Lists (Easy) Leetcode / 力扣 例如以下示例中 A 和 B 两个链表相交于 c1&#xff1a; A: a1 → a2↘c1 → c2 → c3↗ B: b1 → b2 → b3 但是不会出现以下相交的情况&#xff0c;因为每个节点只有一个…

python从入门到精通(二十二):python爬虫框架使用

selenium自动化 scrapy框架 pyspider框架 爬虫验证码 动态渲染页面爬取 模拟登录 AutoScraper

代码随想录算法训练营DAY17 | 二叉树 (4)

一、LeetCode 110 平衡二叉树 题目链接: 110.平衡二叉树https://leetcode.cn/problems/balanced-binary-tree/ 思路&#xff1a;设置深度计算函数&#xff0c;进行递归处理。 class Solution {public boolean isBalanced(TreeNode root) {if(root null){return true;}boolean…

如何在 JavaScript 中比较两个日期 – 技术、方法和最佳实践

在 JavaScript 中&#xff0c;您可以使用 date 对象有效地处理应用程序中的日期、时间和时区。 Date 对象可帮助您有效地操作数据、处理各种与日期相关的任务&#xff0c;并在创建实际应用程序时执行一些计算。 &#xff08;本文内容参考&#xff1a;java567.com&#xff09;…

幻兽帕鲁服务器配置参数说明(Palworld官方汉化)

创建幻兽帕鲁服务器配置参数说明&#xff0c;Palworld服务器配置参数与解释&#xff0c;阿腾云atengyun.com分享&#xff1a; 自建幻兽帕鲁服务器教程&#xff1a; 阿里云教程 https://t.aliyun.com/U/bLynLC腾讯云教程 https://curl.qcloud.com/oRMoSucP 幻兽帕鲁服务器 幻…

基于Keras和LSTM单参数预测中兴通讯股票走势,结果震惊,含代码数据集

1.前言 昨天用分类算法预测大A各个股票的第二天行情&#xff0c;预测结果出现了千股下跌的场景&#xff0c;结果着实让我震惊&#xff0c;预测结果如下图&#xff0c;有没有可能预测第二天究竟涨了多少或者跌了多少呢&#xff1f;毕竟短线交易见好就收呢&#xff1f; 通过查找…

短路在JavaScript中是如何工作的?

在 JavaScript 中&#xff0c;理解真实和虚假的值是编写高效简洁代码的基础。结合短路的概念&#xff0c;开发人员可以编写优雅的解决方案来应对常见的编程挑战。 在本实践指南中&#xff0c;我们将探讨真实值和虚假值&#xff0c;并了解 JavaScript 中短路的机制。 您可以从…

爬虫——ajax和selenuim总结

为什么要写这个博客呢&#xff0c;这个代码前面其实都有&#xff0c;就是结束了。明天搞个qq登录&#xff0c;这个就结束了。 当然也会更新小说爬取&#xff0c;和百度翻译&#xff0c;百度小姐姐的爬取&#xff0c;的对比爬取。总结嘛&#xff01;&#xff01;&#xff01;加…

第七篇:SQL语法-DML-数据操作语言

DML英文全称是Data Manipulation Language(数据操作语言)&#xff0c;用来对数据库中表的数据记录进行增删改操作。它主要包含以下操作&#xff0c; 添加数据(INSERT)修改数据(UPDATE)删除数据(DELETE) 一&#xff0c;添加数据(INSERT) 注意&#xff1a; 插入数据时&#xff0c…

解析基于检索排序的知识图谱问答系统

目录 前言1 问句的表示与语义理解1.1 问句表示的重要性1.2 端到端网络的优势 2 知识图谱中的排序问题2.1 知识图谱的核心作用2.2 查询匹配的转化与排序问题2.3 实体链接的关键性2.4 路径的构建与系统优化 3 难点与挑战3.1 实体链接、命名实体识别和消歧3.2 排序模型的挑战 4 优…

【C++】模版初阶

目录 泛函编程 函数模版 概念 格式 原理 实例化 模版函数的匹配原则 类模板 定义格式 泛函编程 如何实现一个通用的交换函数呢&#xff1f; void Swap(int& left, int& right) {int temp left;left right;right temp; } void Swap(double& left, dou…

Java中锁的应用

文章目录 前言一、场景描述二、加锁1.synchronized2.ReentrantLock 三、扩展1.ThreadLocal 总结 前言 在多线程场景下&#xff0c;多个线程同时对共享变量进行操作是存在风险的&#xff0c;这时候就需要加锁来保证数据的正确性。 一、场景描述 我这里有5个无人机,准备卖到乌克…

去除vue自带的边距

使用vue时发现总有去不掉的外边距&#xff0c;在index.vue里面怎样设置样式都不管用 查阅资料后发现要在vue项目自带的index.html文件内添加下面的样式代码才行 <style>*{margin: 0;padding: 0;}body,html{margin: 0;padding: 0;} </style>

代码随想录算法训练营day50 || 57. 爬楼梯,322. 零钱兑换,279.完全平方数

讲解链接&#xff1a; 代码随想录 动态规划之完全背包&#xff0c;装满背包最少的物品件数是多少&#xff1f;| LeetCode&#xff1a;322.零钱兑换_哔哩哔哩_bilibili 动态规划之完全背包&#xff0c;换汤不换药&#xff01;| LeetCode&#xff1a;279.完全平方数_哔哩哔哩_bil…

多表查询

目录 统计出一张数据表中的数据量 查询 dept 表中的数据量 查询 emp 表中的数据量 实现 emp 与 dept 的多表查询 笛卡尔积 消除笛卡尔积 把数据表 emp 的别名定为 e&#xff0c;数据表 dept 的别名定为 d&#xff0c;然后在查询中分别使用 e 和 d 代替这两个表 Oracle从…