Python与图像处理(2):灰度变换,直方图均衡化
2016-06-27 19:54
1051 查看
本实验主要实现:对图像进行反相处理,将图像像素值变换到100…200区间,对图像像素值求平方后得到图像,对图像进行直方图均衡化处理
实验结果
参考《Python计算机视觉》
import tkFileDialog from PIL import Image from numpy import * from pylab import * import imtools filename = tkFileDialog.askopenfilename(initialdir='E:\experimentcode\Python\stripenoise') #读入图片 im = Image.open(filename) #读取图像到数组中 imA = array(im.convert('L')) imB = 255-imA #对图像进行反相处理 imC = (100.0/255)*imA+100 #将图像像素值变换到100...200区间 imD = 255.0*(imA/255.0)**2#对图像像素值求平方后得到的图像 figure() subplot(2,2,1) imshow(imA) subplot(2,2,2) imshow(imB) subplot(2,2,3) imshow(imC) subplot(2,2,4) imshow(imD) #直方图均衡化 im1,cdf = imtools.histeq(imA) figure() subplot(121) imshow(im1) subplot(122) plot(cdf) show() imtools.py from PIL import Image def histeq(im,nbr_bins=256): """对一幅灰度图像进行直方图均衡化""" #计算图像的直方图 imhist,bins = histogram(im.flatten(),nbr_bins,normed=True) cdf = imhist.cumsum()#计算分布函数 cdf = 255*cdf/[-1]#归一化 #使用累计分布函数的线性插值,计算新的像素值 im2 = interp(im.flatten(),bins[:-1],cdf) return im2.reshape(im.shape),cdf
实验结果
参考《Python计算机视觉》
相关文章推荐
- Python 数据转换
- Python学习笔记(一):列表和元组
- Python中若干概念和语法糖的廓清:参数、generator与decorator
- Python中的字符串替换操作示例
- Python实战1_2:爬取商品信息
- Python中为什么推荐使用isinstance来进行类型判断?而不是type
- Longest Palindromic Substring Leetcode Python Java
- Python的string模块中的Template类字符串模板用法
- 一个python程序
- python list常用操作
- Python3之configparser模块
- Python的GIL是什么鬼,多线程性能究竟如何
- 【python】关于python lxml 安装总是出错的问题
- 『Python数据分析与挖掘实战』第五章:挖掘建模
- python ValueError: ndmin bigger than allowable number of dimensions NPY_MAXDIMS (=32)
- Longest Substring Without Repeating Characters Leetcode Python Java
- python 字符串
- Python 中 strptime 的简单使用
- spark机器学习笔记:(二)用Spark Python进行数据处理和特征提取
- python的一个搜索文件的小程序