Python: 图像处理的基本运算
2016-10-16 19:41
337 查看
Python 作为一种面向对象、直译式的计算机程序语言,在很多领域得到广泛应用。
本文主要介绍 Python 在图像处理中的基本运算,借助 scikit-image 库,Python 在做图像处理的
时候非常方便,对于习惯用MATLAB的人来说,可以非常快速的习惯Python的语法。 熟悉了这些
基本的运算,就可以做进一步复杂的图像处理了。
本文主要介绍 Python 在图像处理中的基本运算,借助 scikit-image 库,Python 在做图像处理的
时候非常方便,对于习惯用MATLAB的人来说,可以非常快速的习惯Python的语法。 熟悉了这些
基本的运算,就可以做进一步复杂的图像处理了。
import numpy as np from skimage import data import matplotlib.pyplot as plt from skimage import io import time from skimage import img_as_float, img_as_ubyte # 读取图像 file_name='E:/Visual Effects/PS Algorithm/2.jpg'; img=io.imread(file_name) file_name2='E:/Visual Effects/PS Algorithm/3.jpg' img2=io.imread(file_name2) # 图像的融合, img3=img2*0.5+img*0.5; # 浮点值的图像归一化到 0-1 之间 img3=img3/255.0; # 图像数据类型的转换 img3=img_as_float(img3); img3=img_as_ubyte(img3); # 分离图像的 R, G, B 三个通道 r_img=img2[:,:,0]; g_img=img2[:,:,1]; b_img=img2[:,:,2]; # 保存图像 io.imsave('red.jpg', r_img); io.imsave ('out.jpg', img3); # 访问图像中的像素 # 单通道图像 aa=r_img[0:3, 0:4]; # 多通道图像 bb=img[0:3, 0:4, :]; print aa print bb[1] # 图像的显示 # 显示彩色图像 plt.figure(1) plt.imshow(img) # 显示灰度图像 plt.figure(2) plt.imshow(r_img, plt.cm.gray) plt.figure(3) plt.imshow(g_img, plt.cm.gray) plt.figure(4) plt.imshow(b_img, plt.cm.gray) plt.axis('off'); plt.show(); # 获取图像的维度,行数,列数以及通道数 row, col, channel=img.shape; print "red channel", r_img.dtype, r_img.shape print "green channel", g_img.dtype, g_img.shape print "blue channel", g_img.dtype, b_img.shape print r_img.shape, row, col, channel # 求图像的最大值,最小值,均值 print img3.min(), img3.max(), img3.mean()
相关文章推荐
- Python: 图像处理的基本运算
- python 视觉:基本的图像操作和处理
- Python-OpenCV 处理图像(二):滤镜和图像运算
- 图像处理书籍笔记1--基本图像处理运算1
- Python图像处理库:PIL中Image,ImageDraw等基本模块介绍
- Python-OpenCV 处理图像(二):滤镜和图像运算
- Python图像处理库(PIL)--Image,ImageDraw等基本模块介绍
- Python在图像处理方向的基本配置
- Python-Image基本的图像处理操作
- Python-OpenCV 处理图像(二)(三):滤镜和图像运算 图像像素点操作
- Python-Image 基本的图像处理操作
- 数字图像处理3---图像基本运算--续
- Python图像处理库PIL的基本模块介绍
- Python-Image 基本的图像处理操作
- Python-Image 基本的图像处理操作
- python 简单图像处理(14) 灰度图腐蚀和膨胀,开运算、闭运算
- 特征提取与图像处理:简单基本的图像处理运算
- Python图像处理库:PIL中Image,ImageDraw等基本模块介绍
- Python图像处理库PIL的基本概念介绍
- Python-Image基本的图像处理操作