halcon求图像灰度最大值和最小值——min_max_gray

前言

我们在图像处理中有时候需要求图像的最小灰度和最大灰度,本文就来介绍如何实现。

1、halcon算子应用

csharp 复制代码
dev_clear_window()
gen_image_const (Image, 'byte', 3, 3)
get_image_size (Image, Width, Height)
for rowIndex := 1 to Height by 1
    for columnIndex := 1 to Width by 1
        if(rowIndex=1 and columnIndex=1)
             set_grayval (Image, rowIndex-1, columnIndex-1,1)
        endif
        if(rowIndex=1 and columnIndex=2)
             set_grayval (Image, rowIndex-1, columnIndex-1,2)
        endif
        if(rowIndex=1 and columnIndex=3)
             set_grayval (Image, rowIndex-1, columnIndex-1,30)
        endif
        if(rowIndex=2 and columnIndex=1)
             set_grayval (Image, rowIndex-1, columnIndex-1,100)
        endif
        if(rowIndex=2 and columnIndex=2)
             set_grayval (Image, rowIndex-1, columnIndex-1,150)
        endif
        if(rowIndex=2 and columnIndex=3)
             set_grayval (Image, rowIndex-1, columnIndex-1,190)
        endif
        if(rowIndex=3 and columnIndex=1)
             set_grayval (Image, rowIndex-1, columnIndex-1,210)
        endif
        if(rowIndex=3 and columnIndex=2)
             set_grayval (Image, rowIndex-1, columnIndex-1,225)
        endif
        if(rowIndex=3 and columnIndex=3)
             set_grayval (Image, rowIndex-1, columnIndex-1,250)
        endif
    endfor
endfor

threshold (Image, Region, 0, 255)
min_max_gray (Region, Image, 20, Min, Max, Range)

min_max_gray算子用于计算图像最小灰度和最大灰度,该算子有6的参数

参数1是指定计算的区域范围

参数2是输入图像

参数3是截断百分比,取值范围 用于控制从灰度直方图两端移除的像素比例,比如上面的代码的图像总共有9个像素,参数3是20,则灰度直方图两边需要移除的像素个数是9*20%=1.8个像素,4舍5入,需要移除2个像素,灰度直方图中像素从小到大的排列是1、2、30、100、150、190、210、225、250,移除掉灰度小的一边的2个像素1、2,移除掉灰度大的一边的2个像素225、250,所以最终得到的灰度最小值是30,灰度最大值210,灰度范围是210-30=180.

参数4是灰度最小值,参考参数3中描述的计算方式

参数5是灰度最大值,参考参数3中描述的计算方式

参数6是灰度范围,参考参数3中描述的计算方式

2、算子应用后效果


马工撰写的年入30万+C#上位机项目实战必备教程(点击下方链接即可访问文章目录)

1、《C#串口通信从入门到精通》

2、《C#与PLC通信从入门到精通 》

3、《C# Modbus通信从入门到精通》

4、《C#Socket通信从入门到精通 》

5、《C# MES通信从入门到精通》

6、《winform控件从入门到精通》

7、《C#操作MySql数据库从入门到精通》

以上教程CSDN订阅已超过2000+~

相关推荐
康康的AI博客4 小时前
腾讯王炸:CodeMoment - 全球首个产设研一体 AI IDE
ide·人工智能
中达瑞和-高光谱·多光谱4 小时前
中达瑞和LCTF:精准调控光谱,赋能显微成像新突破
人工智能
mahtengdbb14 小时前
【目标检测实战】基于YOLOv8-DynamicHGNetV2的猪面部检测系统搭建与优化
人工智能·yolo·目标检测
Pyeako4 小时前
深度学习--BP神经网络&梯度下降&损失函数
人工智能·python·深度学习·bp神经网络·损失函数·梯度下降·正则化惩罚
清 澜4 小时前
大模型面试400问第一部分第一章
人工智能·大模型·大模型面试
不大姐姐AI智能体5 小时前
搭了个小红书笔记自动生产线,一句话生成图文,一键发布,支持手机端、电脑端发布
人工智能·经验分享·笔记·矩阵·aigc
虹科网络安全5 小时前
艾体宝方案 | 释放数据潜能 · 构建 AI 驱动的自动驾驶实时数据处理与智能筛选平台
人工智能·机器学习·自动驾驶
Deepoch5 小时前
Deepoc数学大模型:发动机行业的算法引擎
人工智能·算法·机器人·发动机·deepoc·发动机行业
2501_940198695 小时前
从“数据孤岛”到“智慧医脑”:实战 MCP 协议安全接入 HIS 系统,构建医疗级 AI 辅助诊断合规中台
人工智能·安全·asp.net