OpenCV——归一化

normalize
void normalize( InputArray src, InputOutputArray dst, double alpha = 1, double beta = 0,
                             int norm_type = NORM_L2, int dtype = -1, InputArray mask = noArray());

norm_type有NORM_INF, NORM_MINMAX,NORM_L1和NORM_L2四种。
1、在 NORM_MINMAX 模式下,alpha表示归一化后的最小值,beta表示归一化后的最大值。
2、在NORM_L1、NORM_L2、NORM_INF 模式下,alpha表示执行相应归一化后矩阵的范数值,beta不使用。
3、稀疏矩阵归一化仅支持非零像素

在这里插入图片描述

NORM_MINMAX

NORM_L1

NORM_L2

用图像直方图做归一化  放大直方图数值100倍

示例代码

//
// Created by smallflyfly on 2021/6/10.
//

#include "opencv2/opencv.hpp"
#include "opencv2/highgui.hpp"

#include <iostream>

using namespace cv;
using namespace std;

int main() {

    Mat im = imread("test.jpg", IMREAD_GRAYSCALE);

    resize(im, im, Size(0, 0), 0.5, 0.5);

    Mat hist;
    const int channels[1] = {0};
    float inRanges[2] = {0, 255};
    const float *ranges[1] = {inRanges};
    const int bins[1] = {256};
    calcHist(&im, 1, channels, Mat(), hist, 1, bins, ranges);
    int histW = 512;
    int histH = 480;
    int width = 2;
    Mat histL1_im = Mat::zeros(histH, histW, CV_8UC3);
    Mat histInf_im = Mat::zeros(histH, histW, CV_8UC3);
    Mat histL1, histInf;
    normalize(hist, histL1, 1, 0, NORM_L1);
    for (int i = 1; i <= histL1.rows; ++i) {
        float va = histL1.at<float>(i-1);
        rectangle(histL1_im, Point(width * (i-1), histH-1),
                  Point(width * i - 1, histH - cvRound(histH * 100.0 * histL1.at<float>(i-1)) - 1),
                  Scalar(255, 255, 255), -1);
    }

    imshow("hist-L1", histL1_im);

    waitKey(0);

    destroyAllWindows();

    return 0;
}

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值