当前位置: 首页 > news >正文

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

效果:

Video:

区域增加分割

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;
}

相关文章:

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

效果&#xff1a; Video: 区域增加分割 1、itkThresholdImageFilter 该类的主要功能是通过设置低阈值、高阈值或介于高低阈值之间&#xff0c;则将图像值输出为用户指定的值。 如果图像值低于、高于或介于设置的阈值之间&#xff0c;该类就将图像值设置为用户指定的“外部”值…...

2023.2.6

#include<stdio.h> #include<string.h> //冒泡排序 void bubb(int arr[],int len) {for(int i1;i<len;i){for(int j0;j<len-i1;j){if(arr[j1]<arr[j]){int tarr[j];arr[j]arr[j1];arr[j1]t;}}} } //select排序 void select(int arr[],int len) {int min0;…...

例39:使用List控件

建立一个EXE工程&#xff0c;在窗体上放一个文本框&#xff0c;一个列表框和三个按钮输入如下的代码&#xff1a; Sub Form1_Command1_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd)List1.AddItem(Text1.Text)End SubSub Form1_Command2_BN_Clicked(hWndForm As hWnd, h…...

浏览器内核的主要功能模块介绍

浏览器内核是浏览器的核心部分&#xff0c;负责解析网页内容、渲染页面和处理用户交互。一个典型的浏览器内核主要包括以下几个功能模块&#xff1a; 1. **解析器&#xff08;Parser&#xff09;**&#xff1a; 解析器负责解析网页内容&#xff0c;包括HTML…...

如何流畅进入Github

前言 以下软件是免费的&#xff0c;放心用 一、进入右边的下载链接https://steampp.net/ 二、点击下载 三、点击接受并下载 四、随便选一个下载链接进行下载 五、软件安装好打开后&#xff0c;找到Github 六、点击全部启用 七、再点击左上角的一键加速 八、这个时候你再进Git…...

docker磁盘不足!已解决~

目录 &#x1f35f;1.查看docker镜像目录 &#x1f9c2;2.停止docker服务 &#x1f953;3.创建新的目录 &#x1f32d;4.迁移目录 &#x1f37f;5.编辑迁移的目录 &#x1f95e;6.重新加载docker &#x1f354;7.检擦docker新目录 &#x1f373;8.删掉旧目录 1.查看doc…...

法国实习面试——计算机相关专业词汇

法语 1.Spcialit - 专业 2.Systme - 系统 3.Embarqus - 嵌入式 4.Logicielle - 软件 5.Distribus - 分布式 6.lectronique - 电子 7.nergie lectrique - 电能 8.Automatisation - 自动化 9.Une exprience de stage - 实习经验 10.Automobiles - 汽车 11.tre charg…...

LeetCode刷题计划

LeetCode刷题计划 推荐 代码随想录&#xff1a;https://github.com/youngyangyang04/leetcode-master 卡码网 练习ACM模式 https://kamacoder.com/ 01 #include <iostream> using namespace std;int main() {int a ,b;while(cin>>a>>b){cout<<ab<…...

2023全球云计算市场份额排名

关注卢松松&#xff0c;会经常给你分享一些我的经验和观点。 最近Synergy研究院发布了最新的全球云计算市场份额排名。 亚马逊依旧是以31%的的市场份额排名第一&#xff0c;微软azure24%排名第二&#xff0c;Google云11%排名第三&#xff0c;阿里云4%排名第四。腾讯云和IBM、…...

Oracle数据库

1. 请解释什么是分区表&#xff08;Partitioned Table&#xff09;以及它的优点。 分区表是一种数据库技术&#xff0c;它将一个大表分成多个小的、更易于管理的部分&#xff0c;每个部分称为一个分区。以下是Oracle分区表的一些优点&#xff1a; 提高查询性能&#xff1a;通…...

Spring Cloud Hystrix 参数配置、简单使用、DashBoard

Spring Cloud Hystrix 文章目录 Spring Cloud Hystrix一、Hystrix 服务降级二、Hystrix使用示例三、OpenFeign Hystrix四、Hystrix参数HystrixCommand.Setter核心参数Command PropertiesFallback降级配置Circuit Breaker 熔断器配置Metrix 健康统计配置Request Context 相关参数…...

阿里云服务器4核16G配置报价和CPU内存性能参数表

阿里云4核16G服务器优惠价格ECS云服务器经济型e实例26元1个月、149元半年、79元3个月&#xff0c;4核16G通用算力u1服务器、通用型g7、通用型g8i、AMD通用型g8a、性能增强通用型g8ae、高主频通用型hfg8i、AMD通用型g7a、内存型r7p等均提供4核16G配置。阿里云服务器网aliyunfuwu…...

数据结构:图文详解 队列 | 循环队列 的各种操作(出队,入队,获取队列元素,判断队列状态)

目录 队列的概念 队列的数据结构 队列的实现 入队 出队 获取队头元素 获取队列长度 循环队列的概念 循环队列的数据结构 循环队列的实现 判断队列是否为空 判断队列是否已满 入队 出队 得到队头元素 得到队尾元素 队列的概念 队列&#xff08;Queue&#xff0…...

Debezium发布历史130

原文地址&#xff1a; https://debezium.io/blog/2022/10/10/debezium-2.0-cr1-released/ 欢迎关注留言&#xff0c;我是收集整理小能手&#xff0c;工具翻译&#xff0c;仅供参考&#xff0c;笔芯笔芯. Debezium 2.0.0.CR1 Released October 10, 2022 by Chris Cranford rel…...

【笔记】Harmony学习:下载安装 DevEco Studio 开发工具IDE

IDE 安装 从官网下载DevEco Studio 安装包后进行安装&#xff0c; 安装完毕后&#xff0c;本地环境可能要配置相关工具&#xff0c;可以通过下面的诊断检测一下本地环境&#xff0c;通过蓝色“Set it up now” 可以快速安装。 1. Node.js (for ohpm) 2. ohpm 下载op的包管理&a…...

Electron实战之入门

一、Electron简介 1.1 Electron是什么 Electron是一个使用 JavaScript、HTML 和 CSS 构建桌面应用程序的技术框架。 嵌入 Chromium 和 Node.js 到 二进制的 Electron 允许开发者使用 JavaScript 代码来创建允许在Windows、macOS和Linux等平台。 1.2 发展历程 2013 年的时候…...

飞机大作战(c语言)

前言&#xff1a; 飞机大作战游戏是一种非常受欢迎的射击类游戏&#xff0c;玩家需要控制一架战斗机在屏幕上移动&#xff0c;击落敌机以获得分数。本游戏使用C语言编写&#xff0c;旨在帮助初学者了解游戏开发的基本概念和技巧。 在开始编写代码之前&#xff0c;我们需要先了…...

服务器操作系统windows和linux区别对比

阿里云服务器镜像Windows和Linux操作系统有什么区别&#xff1f;性能有差异吗&#xff1f;有&#xff0c;同配置下Linux性能要优于Windows&#xff0c;但这与阿里云无关&#xff0c;仅仅是linux和windows之间的区别。另外&#xff0c;阿里云提供的windows和linux操作系统均为正…...

吉他学习:识谱,认识节奏,视唱节奏,节拍器的使用

第九课 识谱https://m.lizhiweike.com/lecture2/29362692 第十课 基础乐理(二)——节奏篇https://mp.csdn.net/mp_blog/creation/editor?spm=1011.2124.3001.6192...

[前端开发] JavaScript基础知识 [下]

上篇&#xff1a;JavaScript基础知识 [上] JavaScript基础知识 [下] 字符串数组函数对象 字符串 字符串语法规则&#xff1a;单引号、双引号和反引号的使用 利用双引号"或者单引号所括起来双引号中不能嵌套双引号,单引号中不能嵌套单引号如果要在双引号中嵌套双引号或者…...

RimWorld模组管理终极指南:3步掌握RimSort智能排序,告别游戏崩溃烦恼

RimWorld模组管理终极指南&#xff1a;3步掌握RimSort智能排序&#xff0c;告别游戏崩溃烦恼 【免费下载链接】RimSort RimSort is an open source mod manager for the video game RimWorld. There is support for Linux, Mac, and Windows, built from the ground up to be a…...

精准识别胡椒成熟度!YOLO-AVCA-CBAMNet 让智慧农业更高效

点击蓝字 关注我们 关注并星标 从此不迷路 计算机视觉研究院 公众号ID&#xff5c;计算机视觉研究院 学习群&#xff5c;扫码在主页获取加入方式 https://pmc.ncbi.nlm.nih.gov/articles/PMC12830288/ 计算机视觉研究院专栏 Column of Computer Vision Institute 本文提出YOLO-…...

京沪高铁涨价了,传说中的“牛马专列”要坐不起了?

一直以来&#xff0c;京沪高铁因为其连通北京上海这两大重要城市&#xff0c;成为了最受关注的高铁线路&#xff0c;然而就在最近京沪高铁的涨价引发了市场的热议&#xff0c;让人不禁想问传说中的“牛马专列”要坐不起了&#xff1f; 一、京沪高铁涨价了&#xff1f; 据南方都…...

GitHub中文插件终极指南:3分钟让英文GitHub变母语界面

GitHub中文插件终极指南&#xff1a;3分钟让英文GitHub变母语界面 【免费下载链接】github-chinese GitHub 汉化插件&#xff0c;GitHub 中文化界面。 (GitHub Translation To Chinese) 项目地址: https://gitcode.com/gh_mirrors/gi/github-chinese 还在为GitHub的英文…...

给工程师的傅里叶变换:从信号处理到图像压缩,用Python代码理解核心推导

给工程师的傅里叶变换&#xff1a;从信号处理到图像压缩&#xff0c;用Python代码理解核心推导 当你在Spotify上听歌时&#xff0c;算法如何从嘈杂环境中分离人声&#xff1f;手机拍照时&#xff0c;JPEG压缩为何能大幅减小文件体积却保持清晰&#xff1f;这些看似不相关的技术…...

量子化学计算中的自旋适应算符与费米子激发算符

1. 量子化学计算中的自旋适应算符基础在量子化学模拟领域&#xff0c;保持电子波函数的自旋对称性是一个根本性挑战。传统计算方法中&#xff0c;我们使用Slater行列式来表示多电子波函数&#xff0c;这种方法虽然直观&#xff0c;但无法保证波函数是总自旋算符Ŝ的本征态。自旋…...

2026河北钢制防火门多少钱一平米?甲乙丙级最新报价

在建筑消防工程中&#xff0c;钢制防火门是厂房、小区、商场、地下室必不可少的消防设施。很多河北河间、任丘本地工程采购、施工方&#xff0c;最关心的就是钢制防火门最新平米价格。结合2026年河北消防建材市场行情&#xff0c;简单清晰讲解甲乙丙级钢制防火门市场价与选购要…...

NIC-400周期模型构建失败分析与解决方案

1. 问题概述&#xff1a;NIC-400周期模型构建失败场景分析最近在Arm IP Exchange平台上构建NIC-400周期模型时&#xff0c;不少工程师遇到了构建失败的问题。作为Arm CoreLink系列网络互连控制器的重要验证工具&#xff0c;周期模型的正确构建直接影响后续系统级验证的效率。根…...

芯片Signoff中的不确定性风险管理:工艺角、蒙特卡洛与签核验证

1. 项目概述&#xff1a;芯片Signoff中的不确定性风险管理在芯片设计的最后阶段&#xff0c;也就是我们常说的Signoff&#xff08;签核&#xff09;&#xff0c;工程师们面临的最大挑战之一&#xff0c;就是如何与无处不在的“不确定性”共舞。这里的“不确定性”&#xff0c;专…...

告别JNI内存泄漏:实战中那些容易踩坑的字符串与数组操作(附完整代码示例)

告别JNI内存泄漏&#xff1a;实战中那些容易踩坑的字符串与数组操作&#xff08;附完整代码示例&#xff09; 在Android NDK开发和高性能Java服务中&#xff0c;JNI&#xff08;Java Native Interface&#xff09;作为连接Java与C的桥梁&#xff0c;其重要性不言而喻。然而&…...