使用SciPy进行常用的图像操作
2017-08-19 16:47
405 查看
SciPy provides some basic functions to work with images. For example, it has functions to read images from disk into numpy arrays, to write numpy arrays to disk as images, and to resize images. Here is a simple example that showcases these functions:
# coding:utf-8 import numpy as np from scipy.misc import imread, imsave, imresize # Read an JPEG image into a numpy array img = imread('cat.jpg') print(img.dtype, img.shape) # Prints "uint8 (400, 248, 3)" print(type(np.array(img))) # Prints "<class 'numpy.ndarray'>" # We can tint the image by scaling each of the color channels # by a different scalar constant. The image has shape (400, 248, 3); # we multiply it by the array [1, 0.95, 0.9] of shape (3,); # numpy broadcasting means that this leaves the red channel unchanged, # and multiplies the green and blue channels by 0.95 and 0.9 # respectively. img_tinted = img * [1, 0.95, 0.9] # Resize the tinted image to be 300 by 300 pixels. img_tinted = imresize(img_tinted, (300, 300)) # Write the tinted image back to disk imsave('cat_tinted.jpg', img_tinted)
相关文章推荐
- iOS 使用手势UIGestureRecognizer对图像进行缩放、移动、旋转等操作
- iOS 使用手势UIGestureRecognizer对图像进行缩放、移动、旋转操作
- opencv2中使用Mat对图像像素进行操作
- iOS 使用手势UIGestureRecognizer对图像进行缩放、移动、旋转操作
- Python使用scipy和numpy操作处理图像
- iOS开发:使用手势UIGestureRecognizer对图像进行缩放、移动、旋转操作
- C# 中使用Word文档对图像进行操作
- 使用Java进行图像处理的一些基础操作
- Python学习之使用Pillow(PIL)进行图像操作方法详解
- BGRABitmap图像操作10:使用Affine 变换进行纹理映射
- 使用blur函数进行基于均值滤波的图像模糊操作
- C++builder 使用cximage对图像文件进行操作
- 使用TensorFlow进行常用的图像处理-图像转为矩阵以及图像大小调整
- iOS 使用手势UIGestureRecognizer对图像进行缩放、移动、旋转等操作
- 使用OpenCV读、操作、写图像并与bash合作对某个目录下所有图像进行类似处理
- 使用OpenCv获取摄像头图像并进行旋转操作
- 使用OpenCV读、操作、写图像并与bash合作对某个目录下所有图像进行类似处理
- eclipse下使用java api 进行hbase的常用的操作所需的jar包,以及如何查看java build path下的jar是否使用
- Android 中 Handler 引起的内存泄露 在Android常用编程中,Handler在进行异步操作并处理返回结果时经常被使用。其实这可能导致内存泄露,代码中哪里可能导致内存泄露,又是如何
- C# 中使用Word文档对图像进行操作