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

python 归一化_python-OpenCV之normalize(归一化 )函数详解

归一化就是要把需要处理的数据经过处理后(通过某种算法)限制在你需要的一定范围内。

归一化的目的,是使得没有可比性的数据变得具有可比性,同时又保持相比较的两个数据之间的相对关系,如大小关系;或是为了作图,原来很难在一张图上作出来,归一化后就可以很方便的给出图上的相对位置等。

接下来主要讲述python_opencv中的normalize()函数,其原型为:

def normalize(src, dst, alpha=None, beta=None, norm_type=None, dtype=None, mask=None): # real signature unknown; restored from __doc__

"""

normalize(src, dst[, alpha[, beta[, norm_type[, dtype[, mask]]]]]) -> dst

.   @brief Normalizes the norm or value range of an array.

.

.   The function cv::normalize normalizes scale and shift the input array elements so that

.   \f[\| \texttt{dst} \| _{L_p}= \texttt{alpha}\f]

.   (where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that

.   \f[\min _I  \texttt{dst} (I)= \texttt{alpha} , \, \, \max _I  \texttt{dst} (I)= \texttt{beta}\f]

.

.   when normType=NORM_MINMAX (for dense arrays only). The optional mask specifies a sub-array to be

.   normalized. This means that the norm or min-n-max are calculated over the sub-array, and then this

.   sub-array is modified to be normalized. If you want to only use the mask to calculate the norm or

.   min-max but modify the whole array, you can use norm and Mat::convertTo.

.

.   In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this,

.   the range transformation for sparse matrices is not allowed since it can shift the zero level.

.

.   Possible usage with some positive example data:

.   @code{.cpp}

.   vector positiveData = { 2.0, 8.0, 10.0 };

.   vector normalizedData_l1, normalizedData_l2, normalizedData_inf, normalizedData_minmax;

.

.   // Norm to probability (total count)

.   // sum(numbers) = 20.0

.   // 2.0      0.1     (2.0/20.0)

.   // 8.0      0.4     (8.0/20.0)

.   // 10.0     0.5     (10.0/20.0)

.   normalize(positiveData, normalizedData_l1, 1.0, 0.0, NORM_L1);

.

.   // Norm to unit vector: ||positiveData|| = 1.0

.   // 2.0      0.15

.   // 8.0      0.62

.   // 10.0     0.77

.   normalize(positiveData, normalizedData_l2, 1.0, 0.0, NORM_L2);

.

.   // Norm to max element

.   // 2.0      0.2     (2.0/10.0)

.   // 8.0      0.8     (8.0/10.0)

.   // 10.0     1.0     (10.0/10.0)

.   normalize(positiveData, normalizedData_inf, 1.0, 0.0, NORM_INF);

.

.   // Norm to range [0.0;1.0]

.   // 2.0      0.0     (shift to left border)

.   // 8.0      0.75    (6.0/8.0)

.   // 10.0     1.0     (shift to right border)

.   normalize(positiveData, normalizedData_minmax, 1.0, 0.0, NORM_MINMAX);

.   @endcode

.

.   @param src input array.

.   @param dst output array of the same size as src .

.   @param alpha norm value to normalize to or the lower range boundary in case of the range

.   normalization.

.   @param beta upper range boundary in case of the range normalization; it is not used for the norm

.   normalization.

.   @param norm_type normalization type (see cv::NormTypes).

.   @param dtype when negative, the output array has the same type as src; otherwise, it has the same

.   number of channels as src and the depth =CV_MAT_DEPTH(dtype).

.   @param mask optional operation mask.

.   @sa norm, Mat::convertTo, SparseMat::convertTo

"""

pass

可能有些同学看不懂注释,没关系,我们通过几个例子来详细阐述该函数是如何实现归一化的。

在做图像处理的过程中,我们有时会对图像增强,增加其对比度,在增强之后就会利用该函数进行取值范围归一化。

cv2.normalize(img,img,0,255,cv2.NORM_MINMAX)

注:把所有的值缩放到【0,255】范围内,具体的操作方式可参考https://blog.csdn.net/lanmeng_smile/article/details/49903865

相关文章:

  • 如何在eplan里面画一个伺服驱动器_EPLAN电气图实例-控制回路(电机回路2)
  • cmd php 不是内部命令_cmd不是内部命令解决方法
  • mysql test 映射到实体_10分钟教你Python+MySQL数据库操作
  • restful批量上传文件_RESTful文件上传与下载
  • db2存储过程怎么调试_多租户模式下存储方案的考量
  • wpf 点击按钮弹出新对话框_wpf-打开文件对话框MVVM
  • DCL记忆上次输入值lisp_如何快速记忆Word中Ctr+字母、数字快捷键
  • go定时器 每天重复_腾讯 Go 性能优化实战
  • 注入js文件_你需要知道的依赖注入
  • 世界机器人冠军王宇航_带队两夺机器人世界杯冠军 金牌教练是如何养成的
  • tanh函数matlab_MATLAB常用数学函数
  • arma模型平稳性和可逆性的条件_时间序列 | 第四章 模型识别
  • matlab中cvx例子_机器学习中的相似性度量总结
  • 8266连接mqtt发送消息_未读消息(小红点),前端 与 RabbitMQ 实时消息推送实践,贼简单~...
  • 容器删除元素后迭代器失效_Java容器类源码分析之Iterator与ListIterator迭代器(基于JDK8)...
  • 【Linux系统编程】快速查找errno错误码信息
  • 【译】理解JavaScript:new 关键字
  • CSS相对定位
  • Java知识点总结(JDBC-连接步骤及CRUD)
  • Just for fun——迅速写完快速排序
  • Mac转Windows的拯救指南
  • Node + FFmpeg 实现Canvas动画导出视频
  • 高度不固定时垂直居中
  • 基于HAProxy的高性能缓存服务器nuster
  • 入口文件开始,分析Vue源码实现
  • 通过几道题目学习二叉搜索树
  • 走向全栈之MongoDB的使用
  • MPAndroidChart 教程:Y轴 YAxis
  • ### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTr
  • #HarmonyOS:基础语法
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • (+3)1.3敏捷宣言与敏捷过程的特点
  • (1)常见O(n^2)排序算法解析
  • (5)STL算法之复制
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (SpringBoot)第二章:Spring创建和使用
  • (六)软件测试分工
  • (算法)前K大的和
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .\OBJ\test1.axf: Error: L6230W: Ignoring --entry command. Cannot find argumen 'Reset_Handler'
  • .Net Web窗口页属性
  • .NET国产化改造探索(一)、VMware安装银河麒麟
  • .NET下的多线程编程—1-线程机制概述
  • .sys文件乱码_python vscode输出乱码
  • @FeignClient注解,fallback和fallbackFactory
  • @RestController注解的使用
  • [ vulhub漏洞复现篇 ] Hadoop-yarn-RPC 未授权访问漏洞复现
  • [ACL2022] Text Smoothing: 一种在文本分类任务上的数据增强方法
  • [bzoj 3124][sdoi 2013 省选] 直径
  • [C++从入门到精通] 14.虚函数、纯虚函数和虚析构(virtual)
  • [CLR via C#]11. 事件
  • [Docker]四.Docker部署nodejs项目,部署Mysql,部署Redis,部署Mongodb
  • [hdu 4405] Aeroplane chess [概率DP 期望]
  • [HNOI2008]水平可见直线
  • [HUBUCTF 2022 新生赛]