博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
5-8 彩色直方图均衡化
阅读量:5093 次
发布时间:2019-06-13

本文共 5512 字,大约阅读时间需要 18 分钟。

# 本质: 统计每个像素灰度 出现的概率 0-255 p# 累计概率# 1 0.2 0.2 第一个灰度等级它出现的概率是0.2# 2 0.3 0.5 第二个灰度等级它出现的概率是0.3# 3 0.1 0.6 第三个灰度等级它出现的概率是0.1# 256# 100 0.5 255*0.5 = new import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('image0.jpg',1)cv2.imshow('src',img)imgInfo = img.shapeheight = imgInfo[0]width = imgInfo[1]#gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#cv2.imshow('src',gray)count_b = np.zeros(256,np.float)count_g = np.zeros(256,np.float)count_r = np.zeros(256,np.float)for i in range(0,height):    for j in range(0,width):        #pixel = gray[i,j]        #index = int(pixel)        #count[index] = count[index]+1        (b,g,r) = img[i,j]        index_b = int(b)        index_g = int(g)        index_r = int(r)        count_b[index_b] = count_b[index_b]+1        count_g[index_g] = count_g[index_g]+1        count_r[index_r] = count_r[index_r]+1for i in range(0,255):    count_b[i] = count_b[i]/(height*width)    count_g[i] = count_g[i]/(height*width)    count_r[i] = count_r[i]/(height*width)# 计算累计概率sum_b = float(0)sum_g = float(0)sum_r = float(0)for i in range(0,256):    sum_b = sum_b+count_b[i]    sum_g = sum_g+count_g[i]    sum_r = sum_r+count_r[i]    count_b[i] = sum_b    count_g[i] = sum_g    count_r[i] = sum_r#print(count)# 计算映射表map_b = np.zeros(256,np.uint16)map_g = np.zeros(256,np.uint16)map_r = np.zeros(256,np.uint16)for i in range(0,256):    map_b[i] = np.uint16(count_b[i]*255)    map_g[i] = np.uint16(count_g[i]*255)    map_r[i] = np.uint16(count_r[i]*255)# 映射dst = np.zeros((height,width,3),np.uint8)for i in range(0,height):    for j in range(0,width):       #pixel = gray[i,j]# 获取当前的像素值       #gray[i,j] = map1[pixel]       (b,g,r) = img[i,j]       b = map_b[b]       g = map_g[g]       r = map_r[r]       dst[i,j] = (b,g,r)#cv2.imshow('dst',gray)cv2.imshow('dst',dst)cv2.waitKey(0)

# 本质: 统计每个像素灰度 出现的概率 0-255 p# 累计概率# 1 0.2 0.2 第一个灰度等级它出现的概率是0.2# 2 0.3 0.5 第二个灰度等级它出现的概率是0.3# 3 0.1 0.6 第三个灰度等级它出现的概率是0.1# 256# 100 0.5 255*0.5 = new import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('image0.jpg',1)cv2.imshow('src',img)imgInfo = img.shapeheight = imgInfo[0]width = imgInfo[1]#gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#cv2.imshow('src',gray)count_b = np.zeros(256,np.float)count_g = np.zeros(256,np.float)count_r = np.zeros(256,np.float)for i in range(0,height):    for j in range(0,width):        #pixel = gray[i,j]        #index = int(pixel)        #count[index] = count[index]+1        (b,g,r) = img[i,j]        index_b = int(b)        index_g = int(g)        index_r = int(r)        count_b[index_b] = count_b[index_b]+1        count_g[index_g] = count_g[index_g]+1        count_r[index_r] = count_r[index_r]+1for i in range(0,256):    count_b[i] = count_b[i]/(height*width)    count_g[i] = count_g[i]/(height*width)    count_r[i] = count_r[i]/(height*width)# 计算累计概率sum_b = float(0)sum_g = float(0)sum_r = float(0)for i in range(0,256):    sum_b = sum_b+count_b[i]    sum_g = sum_g+count_g[i]    sum_r = sum_r+count_r[i]    count_b[i] = sum_b    count_g[i] = sum_g    count_r[i] = sum_r#print(count)# 计算映射表map_b = np.zeros(256,np.uint16)map_g = np.zeros(256,np.uint16)map_r = np.zeros(256,np.uint16)for i in range(0,256):    map_b[i] = np.uint16(count_b[i]*255)    map_g[i] = np.uint16(count_g[i]*255)    map_r[i] = np.uint16(count_r[i]*255)# 映射dst = np.zeros((height,width,3),np.uint8)for i in range(0,height):    for j in range(0,width):       #pixel = gray[i,j]# 获取当前的像素值       #gray[i,j] = map1[pixel]       (b,g,r) = img[i,j]       b = map_b[b]       g = map_g[g]       r = map_r[r]       dst[i,j] = (b,g,r)#cv2.imshow('dst',gray)cv2.imshow('dst',dst)cv2.waitKey(0)

# 本质: 统计每个像素灰度 出现的概率 0-255 p# 累计概率# 1 0.2 0.2 第一个灰度等级它出现的概率是0.2# 2 0.3 0.5 第二个灰度等级它出现的概率是0.3# 3 0.1 0.6 第三个灰度等级它出现的概率是0.1# 256# 100 0.5 255*0.5 = new import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('image2.jpg',1)cv2.imshow('src',img)imgInfo = img.shapeheight = imgInfo[0]width = imgInfo[1]#gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)#cv2.imshow('src',gray)count_b = np.zeros(256,np.float)count_g = np.zeros(256,np.float)count_r = np.zeros(256,np.float)for i in range(0,height):    for j in range(0,width):        #pixel = gray[i,j]        #index = int(pixel)        #count[index] = count[index]+1        (b,g,r) = img[i,j]        index_b = int(b)        index_g = int(g)        index_r = int(r)        count_b[index_b] = count_b[index_b]+1        count_g[index_g] = count_g[index_g]+1        count_r[index_r] = count_r[index_r]+1for i in range(0,256):    count_b[i] = count_b[i]/(height*width)    count_g[i] = count_g[i]/(height*width)    count_r[i] = count_r[i]/(height*width)# 计算累计概率sum_b = float(0)sum_g = float(0)sum_r = float(0)for i in range(0,256):    sum_b = sum_b+count_b[i]    sum_g = sum_g+count_g[i]    sum_r = sum_r+count_r[i]    count_b[i] = sum_b    count_g[i] = sum_g    count_r[i] = sum_r#print(count)# 计算映射表map_b = np.zeros(256,np.uint16)map_g = np.zeros(256,np.uint16)map_r = np.zeros(256,np.uint16)for i in range(0,256):    map_b[i] = np.uint16(count_b[i]*255)    map_g[i] = np.uint16(count_g[i]*255)    map_r[i] = np.uint16(count_r[i]*255)# 映射dst = np.zeros((height,width,3),np.uint8)for i in range(0,height):    for j in range(0,width):       #pixel = gray[i,j]# 获取当前的像素值       #gray[i,j] = map1[pixel]       (b,g,r) = img[i,j]       b = map_b[b]       g = map_g[g]       r = map_r[r]       dst[i,j] = (b,g,r)#cv2.imshow('dst',gray)cv2.imshow('dst',dst)cv2.waitKey(0)

 

转载于:https://www.cnblogs.com/ZHONGZHENHUA/p/9745322.html

你可能感兴趣的文章
JavaEE笔记(十)
查看>>
python scipy stats学习笔记
查看>>
mysql的一些查询优化,count优化,limit优化
查看>>
[Nuxt] Add CSS Libraries to Nuxt
查看>>
[Immutable.js] Converting Immutable.js Structures to Javascript and other Immutable Types
查看>>
PuTTY 'modmul()' 函数缓冲区下溢漏洞(CVE-2013-4206)
查看>>
makefile
查看>>
像进度条的网页加载Loading JS代码
查看>>
C#有哪几种定时器
查看>>
javascript高级程序设计笔记-第八章(BOM)
查看>>
结构体和共用体字节对齐
查看>>
在一个环境中使用不同版本的rails
查看>>
openfire的搭建与运行(转)
查看>>
mybatis使用oracle自动生成主键
查看>>
实践中 XunSearch(讯搜)更新索引方案对比
查看>>
C#程序关闭时怎么关闭子线程
查看>>
Plants vs. Zombies(二分好题+思维)
查看>>
依赖包拼合方法
查看>>
professional email address collections
查看>>
jquery兼容IE和火狐下focus()事件
查看>>