原创 python实现灰度图像直方图统计与均衡化.docVIP

  • 11
  • 0
  • 约4.56千字
  • 约 6页
  • 2018-10-11 发布于重庆
  • 举报

原创 python实现灰度图像直方图统计与均衡化.doc

原创 python实现灰度图像直方图统计与均衡化

原创 python实现:灰度图像直方图统计与均衡化 代码如下,重构过两次,使用面向对象设计,最后是效果图。(原参考的代码是过程化的,并且命名比较难懂,我改进了一把) # coding=utf-8 import cv2.cv as cv class Image: ??? ??? def __init__(self,imagePath=None,imageData=None): ??????? if imagePath is not None: ??????????? self.image = self._readImage(imagePath) ??????????? return ??????? if imageData is not None: ??????????? self.image = imageData ??????????? return ??????? ??? def _readImage(self,imagePath): ??????? return cv.LoadImage(imagePath,0) ??????? ??? def show(self,windowName): ??????? cv.ShowImage(windowName, self.image) ??? class Histogram: ??? ??? def __init__(self,image): ??????? self.image = image ??????? ??? def _getIntensiveCount(self): ??????? analyst = Analyst() ??????? return analyst.getIntensiveCount(self.image) ??? ??? def _draw(self,lineColor): ??????? intensiveCount = self._getIntensiveCount() ??????? painter = Painter() ??????? return painter.drawPictureFromData(intensiveCount,lineColor)?? ???? ??? def show(self,windowName,lineColor): ??????? histogram = self._draw(lineColor) ??????? cv.ShowImage(windowName, histogram) class Accumulate: ??? ??? def __init__(self,image): ??????? self.image = image ??????? ??? def _getIntensiveAccumulate(self): ??????? analyst = Analyst() ??????? return analyst.getIntensiveAccumulate(self.image) ??? ??? def _draw(self,lineColor): ??????? intensiveAccumulate = self._getIntensiveAccumulate() ??????? painter = Painter() ??????? return painter.drawPictureFromData(intensiveAccumulate,lineColor) ??? ??? def show(self,windowName,lineColor): ??????? accumulate = self._draw(lineColor) ??????? cv.ShowImage(windowName, accumulate) ??? class Equalizer: ??? ??? INTENSIVE_COUNT = 256 ??? INTENSIVE_RANK = 255 ??? ??? def __init__(self,image): ??????? self.image = image ??? ??? def equalize(self): ??????? size = (self.image.width,self.image.height) ??????? depth = self.image.depth ??????? channels = 1 ??????? pixelCount = self.image.width * self.image.height ??????? equalizedImg = cv.CreateIma

文档评论(0)

1亿VIP精品文档

相关文档