Python使用scipy和numpy操作处理图像
来源:互联网 发布:一地狗粮什么意思网络 编辑:程序博客网 时间:2024/05/01 06:18
之前使用Python处理数据的时候都是一些简单的plot。今天遇见了需要处理大量像素点,并且显示成图片的问题,无奈水浅,一筹莫展。遂Google之。
找到如下站点,真心不错。准备翻译之~~~
http://scipy-lectures.github.io/advanced/image_processing/index.html
2.6.1. Opening and writing to image files
Writing an array to a file:
from scipy import miscl = misc.lena()misc.imsave('lena.png', l) # uses the Image module (PIL)import matplotlib.pyplot as pltplt.imshow(l)plt.show()
Creating a numpy array from an image file:
>>> from scipy import misc>>> lena = misc.imread('lena.png')>>> type(lena)<type 'numpy.ndarray'>>>> lena.shape, lena.dtype((512, 512), dtype('uint8'))
dtype is uint8 for 8-bit images (0-255)
Opening raw files (camera, 3-D images)
>>> l.tofile('lena.raw') # Create raw file>>> lena_from_raw = np.fromfile('lena.raw', dtype=np.int64)>>> lena_from_raw.shape(262144,)>>> lena_from_raw.shape = (512, 512)>>> import os>>> os.remove('lena.raw')
Need to know the shape and dtype of the image (how to separate databytes).
For large data, use np.memmap for memory mapping:
>>> lena_memmap = np.memmap('lena.raw', dtype=np.int64, shape=(512, 512))
(data are read from the file, and not loaded into memory)
Working on a list of image files
>>> for i in range(10):... im = np.random.random_integers(0, 255, 10000).reshape((100, 100))... misc.imsave('random_%02d.png' % i, im)>>> from glob import glob>>> filelist = glob('random*.png')>>> filelist.sort()
2.6.2. Displaying images
Use matplotlib and imshow to display an image inside amatplotlibfigure:
>>> l = misc.lena()>>> import matplotlib.pyplot as plt>>> plt.imshow(l, cmap=plt.cm.gray)<matplotlib.image.AxesImage object at 0x3c7f710>
Increase contrast by setting min and max values:
>>> plt.imshow(l, cmap=plt.cm.gray, vmin=30, vmax=200)<matplotlib.image.AxesImage object at 0x33ef750>>>> # Remove axes and ticks>>> plt.axis('off')(-0.5, 511.5, 511.5, -0.5)
Draw contour lines:
>>> plt.contour(l, [60, 211])<matplotlib.contour.ContourSet instance at 0x33f8c20>
[Python source code]
0 0
- Python使用scipy和numpy操作处理图像
- 使用Numpy和Scipy处理图像
- 使用Numpy和Scipy处理图像
- 使用Numpy和Scipy处理图像
- 使用Numpy和Scipy处理图像
- 使用Numpy和Scipy处理图像
- python-scipy 图像处理
- SciPy和Numpy处理能力
- python安装numpy和scipy
- Python安装Numpy,SciPy和MatplotLib
- Python windows下安装scipy 和numpy
- 安装Python的Numpy和SciPy库
- Numpy,SciPy和MatplotLib 安装 -- python
- python安装 numpy、matplotlib 和scipy
- python numpy、scipy安装及numpy的初步使用
- 使用NumPy和SciPy进行数值分析
- 【Python】numpy, scipy
- python-numpy、scipy
- HDU 1443 Joseph
- Event、CreateProcess使用的一些总结
- 孤儿进程退出分析
- 程序员技术练级攻略(转)
- Android KEYCODE键值对应表
- Python使用scipy和numpy操作处理图像
- 好吧,我们这些不懂前端的后台,该如何写html5?
- iOS 关于ARC与MRC(非ARC) 之间互相兼容解答
- Android 查看 无wifi/usb设备的logcat方法
- 如何安全退出已调用多个Activity的Application?
- java程序员需要看的书
- eclipse中hadoop2.3.0环境部署及在eclipse中直接提交mapreduce任务
- 解决VMware虚拟机CentOS6.0无法连通网络的办法
- Java hashset hashmap用法机制详解