直方图均衡化

一、直方图

1、原理

图像的直方图描述图像的灰度级和对应灰度级在图像中出现的次数(频率)的关系,通过直方图可以进行图像分割、检索、分类等操作

2、绘制直方图

1.1.1代码实现

# encoding:utf-8

from PIL import Image
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei']


im = array(Image.open('D:\PhotoTest\1.jpg').convert('L'))

figure()
subplot(121)
gray()
contour(im, origin='image')
axis('equal')
axis('off')
title(u'灰度图像')

subplot(122)
hist(im.flatten(), 128)#一维数组
title(u'图像直方图')
plt.xlim([0, 260])
plt.ylim([0, 11000])

show()

1.1.2实验结果与分析

在这里插入图片描述

二、直方图均衡化

1、原理

直方图均衡化是将一幅图像的灰度直方图扁平化,使得经过变换后的图像中的每个灰度值的分布概率相同,这样分散扩大化灰度值使得图像的对比度得以增强

2.1.1代码实现

# encoding:utf-8
from PIL import Image
from matplotlib.pyplot import figure, subplot, axis, gray, title, imshow
from numpy import array
from pylab import *
from PCV.tools import imtools
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)

im = array(Image.open('D:\PhotoTest\1.jpg').convert('L'))
im2, cdf = imtools.histeq(im)

figure()
subplot(2, 2, 1)
axis('off')
gray()
title(u'原始图像',fontproperties=font)
imshow(im)

2.1.2实验结果与分析

在这里插入图片描述

可以发现经过均衡化处理后原图像的灰度值由原本的集中分布变为扩散均匀分布,视觉上的效果表示为明亮对比度增强了

三、高斯滤波

1、原理

高斯滤波主要用于对图像的降噪,处理过程中图像每一个像素点的值,都由其本身和邻域内的其他像素值经过加权平均后得到。高斯滤波的具体操作是:用一个模板(或称卷积、掩模)扫描图像中的每一个像素,用模板确定的邻域内像素的加权平均灰度值去替代模板中心像素点的值。

2.2.1代码实现

# -- coding: utf-8 --
from PIL import Image
from pylab import *
from numpy import *
from numpy import random
from scipy.ndimage import filters
from scipy.misc import imsave
from PCV.tools import rof

from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"c:\windows\fonts\SimSun.ttc", size=14)

im = array(Image.open('D:\PhotoTest\1.jpg').convert('L'))

U,T = rof.denoise(im,im)
G = filters.gaussian_filter(im,10) # save the result
#imsave(‘synth_original.pdf’,im)
#imsave(‘synth_rof.pdf’,U)
#imsave(‘synth_gaussian.pdf’,G) # plot
figure()
gray()

subplot(1,3,1)
imshow(im)
#axis(‘equal’)
axis('off')
title(u'原噪声图像', fontproperties=font)

subplot(1,3,2)
imshow(G)
#axis(‘equal’)
axis('off')
title(u'高斯模糊后的图像', fontproperties=font)

subplot(1,3,3)
imshow(U)
#axis(‘equal’)
axis('off')
title(u'ROF降噪后的图像', fontproperties=font)

show()

2.2.2实验结果与分析

在这里插入图片描述
由于中间数组以与输出相同的数据类型存储,所以,对于精度有限的输出类型,结果可能不精确,因为中间结果可能存储的精度不足。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值