python图像处理——图像形变与缩放
来源:互联网 发布:股票入门软件下载 编辑:程序博客网 时间:2024/06/04 18:12
图像的形变与缩放,使用的是skimage的transform模块,函数比较多,功能齐全。
1、改变图片尺寸
函数格式为:
skimage.transform.resize(image,output_shape)
image:需要改变尺寸的图片
output_shape:新的图片尺寸
from skimage import transform,dataimport matplotlib.pyplot as pltimg = data.camera()dst=transform.resize(img, (80, 60))plt.figure('resize')plt.subplot(121)plt.title('before resize')plt.imshow(img,plt.cm.gray)plt.subplot(122)plt.title('before resize')plt.imshow(dst,plt.cm.gray)plt.show()
可以看到简爱嗯图片由原来512×512,变成来80×60。
2 按比例缩放
函数格式为:
skimage.transform.resize(image,scale[…..])
scale参数可以是单个floate数,表示缩放的倍数,也可是floate型tuple,如[0.2,0.5]表示将行列分开进行缩放。
from skimage import transform,dataimg = data.camera()print(img.shape) #图片原始大小 print(transform.rescale(img, 0.1).shape) #缩小为原来图片大小的0.1倍print(transform.rescale(img, [0.5,0.25]).shape) #缩小为原来图片行数一半,列数四分之一print(transform.rescale(img, 2).shape) #放大为原来图片大小的2倍
3、旋转rotate
skimage.transform.rotate(image,angle[,…],resize=False)
angle参数是一个float类型,表示旋转度数
resize用于控制在旋转时,是否改变大小,默认为False
from skimage import transform,dataimport matplotlib.pyplot as pltimg = data.camera()print(img.shape) #图片原始大小img1=transform.rotate(img, 60) #旋转90度,不改变大小 print(img1.shape)img2=transform.rotate(img, 30,resize=True) #旋转30度,同时改变大小print(img2.shape) plt.figure('resize')plt.subplot(121)plt.title('rotate 60')plt.imshow(img1,plt.cm.gray)plt.subplot(122)plt.title('rotate 30')plt.imshow(img2,plt.cm.gray)plt.show()
4、图像金字塔
以多分辨率来解释图像的一种有效但概念简单的结构就是图像金字塔。图像金字塔最初用于机器视觉和图像压缩,一幅图像的金字塔是一系列以金字塔形状排列的分辨率逐步降低的图像集合。金字塔的底部是待处理图像的高分辨率表示,而顶部是低分辨率的近似。当向金字塔的上层移动时,尺寸和分辨率就降低。
在此,我们举一个高斯金字塔的应用实例,函数原型为:skimage.transform.pyramid_gaussian(image, downscale=2)
import numpy as npimport matplotlib.pyplot as pltfrom skimage import data,transformimage = data.astronaut() #载入宇航员图片rows, cols, dim = image.shape #获取图片的行数,列数和通道数pyramid = tuple(transform.pyramid_gaussian(image, downscale=2)) #产生高斯金字塔图像#共生成了log(512)=9幅金字塔图像,加上原始图像共10幅,pyramid[0]-pyramid[1]composite_image = np.ones((rows, cols + cols / 2, 3), dtype=np.double) #生成背景composite_image[:rows, :cols, :] = pyramid[0] #融合原始图像i_row = 0for p in pyramid[1:]: n_rows, n_cols = p.shape[:2] composite_image[i_row:i_row + n_rows, cols:cols + n_cols] = p #循环融合9幅金字塔图像 i_row += n_rowsplt.imshow(composite_image)plt.show()
阅读全文
0 0
- python图像处理——图像形变与缩放
- python数字图像处理(7):图像的形变与缩放
- python数字图像处理(7):图像的形变与缩放
- python数字图像处理(7):图像的形变与缩放
- python 图像的形变, 旋转与缩放 (transform) (1)
- Python学习07_图像的形变与缩放
- 【python图像处理】图像的缩放、旋转与翻转
- python中Image类处理图像 缩放、旋转与翻转
- 图形图像处理 —— 图像缩放算法
- python图像处理——图像绘制
- Delphi图像处理 -- 图像缩放
- python——图像处理
- 图像缩放处理
- 图像金字塔与图像缩放
- Python与图像处理5
- Python与图像处理6
- Python与图像处理1
- Python与图像处理2
- 3
- Android 操作SQLite基本用法
- VMware虚拟机中使用usb设备
- Python--matplotlib绘图可视化知识点整理
- 【基于url权限管理 shiro(一)】--基础
- python图像处理——图像形变与缩放
- Python编程中对于头部注释的要求
- assert断言
- bootstrap学习24---媒体对象
- 结构体在内存中的对齐规则
- MySQL SQL语句优化技巧
- [Swift 开发] 深拷贝一个UILabel
- java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
- dedecms-sql调用