美文网首页
2019-06-23(day011——python中正则化时要将

2019-06-23(day011——python中正则化时要将

作者: 雨住多一横 | 来源:发表于2019-06-23 22:37 被阅读0次

python

import cv2 as cv
import numpy as np
import sys
sys.path.append("../")
import my_module as m
def function():
    img = m.read("test.jpg")
    cv.imshow("input", img)
    gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
    
    gray = np.float32(gray)
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 0, beta = 1.0, norm_type = cv.NORM_MINMAX)
    print(dst)
    cv.imshow("min_max", np.uint8(dst * 255))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_INF)
    print(dst)
    cv.imshow("INF", np.uint8(dst * 255))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_L1)
    print(dst)
    cv.imshow("L1", np.uint8(dst * 10000000))
    
    dst = np.zeros(gray.shape, dtype = np.float32)
    cv.normalize(gray, dst = dst, alpha = 1.0, beta = 0, norm_type = cv.NORM_L2)
    print(dst)
    cv.imshow("L2", np.uint8(dst * 10000))
function()
cv.waitKey(0)
cv.destroyAllWindows()

python中的新知识

  • np.float32()
  • np.uint8
  • cv.NORM_MINMAX
  • cv.NORM_INF
  • cv.NORM_L1
  • cv.NORM_L2
  • cv.normalize()
    从上面程序看出,python中正则化时要将numpy中的数据转化为np.float32,处理完之后,显示之前需要再转化为np.uint8

c++

#include "all.h"
using namespace std;
using namespace cv;

void MyClass::day011() {
    Mat img = read(PATH + "images\\test.jpg");
    Mat gray;
    if (img.empty()) {
        printf("can't open image\n");
        return;
    }
    cvtColor(img, gray, COLOR_BGR2GRAY);
    gray.convertTo(gray, CV_32F);

    Mat dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_MINMAX);
    dst = dst * 255;
    dst.convertTo(dst, CV_8UC1);
    imshow("minMax", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_INF);
    dst = dst * 255;
    dst.convertTo(dst, CV_8UC1);
    imshow("INF", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_L1);
    dst = dst * 10000000;
    dst.convertTo(dst, CV_8UC1);
    imshow("L1", dst);

    dst = Mat::zeros(gray.size(), CV_32FC1);
    normalize(gray, dst, 1.0, 0, NORM_L2);
    dst = dst * 10000;
    dst.convertTo(dst, CV_8UC1);
    imshow("L2", dst);
    waitKey(0);
}

c++中的新知识

  • 新数据类型:CV_32FC1
  • NORM_MINMAC
  • NORM_INF
  • NORM_L1
  • NORM_L2
  • normalize()
  • Mat::convertTo()
    从上面程序看出,c++中正则化时要将Mat中的数据转化为CV_32F,处理完之后,显示之前需要再转化为CV_8U

相关文章

  • 2019-06-23(day011——python中正则化时要将

    python python中的新知识 np.float32() np.uint8 cv.NORM_MINMAX c...

  • Python中的re模块

    Python中的re模块 Python中提供perl风格的正则表达式模式,re模块使Python拥有全部的正则表达...

  • 正则表达式

    Python正则表达式初识(一) Python正则表达式初识(二) Python正则表达式初识(三) Python...

  • Python--正则匹配

    正则表达式匹配规则 Python 的 re 模块 在 Python 中,我们可以使用内置的 re 模块来使用正则表...

  • Python 脚本之统计基因组文件中染色体长度及N碱基数目

    模块介绍 re模块 re模块是Python中的正则表达式调用模块,在python中,通过将正则表达式内嵌集成re模...

  • 正则表达式

    Python:正则表达式Python:正则表达式

  • Python正则表达式指南

    Python正则表达式指南 本文介绍了Python对于正则表达式的支持,包括正则表达式基础以及Python正则表达...

  • 1.正则表达式

    Python通过标准库中的re模块来支持正则表达式。 1. 正则表达式的基本符号 2. python实现正则表达式...

  • python爬虫之正则表达

    python爬虫之正则表达 概述 这部分主要讲的是python中的re模块。 最简单的正则表达就是普通字符串的匹配...

  • day19-总结

    python中的正则表达式 正则表达式:用来做字符串查找,匹配,切割用的一种工具python对正则表达式的支持:提...

网友评论

      本文标题:2019-06-23(day011——python中正则化时要将

      本文链接:https://www.haomeiwen.com/subject/tvxgqctx.html