Home  >  Article  >  Backend Development  >  How to cut pictures in python language

How to cut pictures in python language

尚
Original
2019-07-08 09:34:294507browse

How to cut pictures in python language

Python语言的图片处理使我们常常使用的方面,那么我们该如何实现图片的剪切呢,下面给出具体的方法。

打开Python语言的idle,也就是它的shell界面。

How to cut pictures in python language

载入Python语言的skimage工具包和相关的工具,代码如下:

How to cut pictures in python language

读取图片,文中读取的是Python的skimage包中自带的图片,具体代码如下:

img=data.clock()

我们也可以读取其他的图片的,具体代码如下:

img_name="D:\\WinPython-64bit-3.5.3.0Qt5\\notebooks\\hashiqi.jpg"
img=io.imread(img_name,as_grey=False)

How to cut pictures in python language

用下面的指令来实现剪切图片的方法,下面小编,剪切图片的四分之一:

import numpy as np

cows,cols=img.shape

new=img[0:rows//2,0:cols//2]

How to cut pictures in python language

查看剪切后的结果如下图。

前一个是剪切后的效果,后一个是剪前的效果。

How to cut pictures in python language

How to cut pictures in python language

更多Python相关技术文章,请访问Python教程栏目进行学习!

The above is the detailed content of How to cut pictures in python language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn