实现图像轮廓和图像直方图(Python)
2013-12-13 16:21
309 查看
Let's look at example of special plots: image contours and image histograms.Visualizing image ISO-contours of other 2D functions can be very useful.This needs gray scale images, because the contours need to be taken on a single value for every coordinate[x,y]. here's how to do it.
from PIL import Image
from pylab import *
im = array(Image.open('test.jpg').convert('L')) # read image to arry
figure() # create a new figure
gray() # don't use colors
#show contours with orgin upper left corner
contour(im,origin ='image')
axis('equal')
axis('off')
figure()
hist(im.flatten(),128)
show()[align=center]As before,the PIL method convert() does convection to gray-scale.An image histogram is a plot showing the distribution of pixel values.A number of bins is specified for the span of values and each bin gets a count of how many pixels have values in the bin's range.The visualization of the image histogram is done using the hist() function.The second argument specifies the number of bins to use.
Noe that the image needs to be flattened first,because hist() takes a 1-D array as input.The method flatten() converts any array to a 1-D array with values taken row-wise.figure shows the contour and histogram plot.
[/align]
[align=left]==========================================================================
转载请注明出处:http://blog.csdn.net/songzitea/article/details/17303547
==========================================================================[/align]
from PIL import Image
from pylab import *
im = array(Image.open('test.jpg').convert('L')) # read image to arry
figure() # create a new figure
gray() # don't use colors
#show contours with orgin upper left corner
contour(im,origin ='image')
axis('equal')
axis('off')
figure()
hist(im.flatten(),128)
show()[align=center]As before,the PIL method convert() does convection to gray-scale.An image histogram is a plot showing the distribution of pixel values.A number of bins is specified for the span of values and each bin gets a count of how many pixels have values in the bin's range.The visualization of the image histogram is done using the hist() function.The second argument specifies the number of bins to use.
Noe that the image needs to be flattened first,because hist() takes a 1-D array as input.The method flatten() converts any array to a 1-D array with values taken row-wise.figure shows the contour and histogram plot.
[/align]
[align=left]==========================================================================
转载请注明出处:http://blog.csdn.net/songzitea/article/details/17303547
==========================================================================[/align]
相关文章推荐
- Python-OpenCV 处理图像(四)(五):图像直方图和反向投影 图像中边界和轮廓检测
- python实现图像的直方图均衡
- Python OpenCV学习笔记之:图像直方图反向投影(backprojection)原理简单实现
- python + openCV 实现图像轮廓识别和面积计算
- 图像轮廓个直方图-(Python)
- Python与图像处理(1):绘制图像,点和线,图像轮廓,直方图
- 彩色图像直方图均衡化及颜色直方图显示 opencv实现 完整代码及详细注释
- Opencv_Python_9_图像直方图(histogram)
- Python语言opencv使用笔记(九)(图像直方图)
- 基于小波变换的多聚焦图像融合算法——Python实现
- matlab实现将彩色图像(R,G,B)色分量的直方图显示出
- 灰度图像直方图的规定化的原理及代码实现
- Python-OpenCV 处理图像(五):图像中边界和轮廓检测
- trackbar轮廓检测/图像颜色分布直方图
- 图像直方图实现
- 图像配准 - 三张灰度图合成彩色图 ECC算法 OpenCV C++/Python实现
- opencv实现灰度图像的直方图点计算以及灰度直方图显示
- openCV—Python(8)—— 图像直方图及其直方图均衡化
- Python实现图像卷积操作
- python实现图像识别功能