图像处理库python skimage

图像处理库python skimage


skimage是和scipy、numpy可以完美结合的,PIL和numpy等结合不好。

from skimage import data
import matplotlib.pyplot as plt
 
camera = data.camera()
# 将图像前面 10 行的值赋为 0
camera[: 10 ] = 0
# 寻找图像中像素值小于 87 的像素点
mask = camera < 87
# 将找到的点赋值为 255
camera[mask] = 255
# 建立索引
inds_x = np.arange(len(camera))
inds_y = ( 4 * inds_x) % len(camera)
# 对应索引的像素赋值为 0
camera[inds_x, inds_y] = 0
 
# 获取图像的行数(高),列数(宽)
l_x, l_y = camera.shape[ 0 ], camera.shape[ 1 ]
# 建立网格坐标索引
X, Y = np.ogrid[:l_x, :l_y]
# 生成圆形的网格坐标
outer_disk_mask = (X - l_x / 2 )** 2 + (Y - l_y / 2 )** 2 > (l_x / 2 )** 2
# 对网格坐标赋 0
camera[outer_disk_mask] = 0
 
# 建立figure的尺寸比例
plt.figure(figsize=( 4 , 4 ))
# 显示图像
plt.imshow(camera, cmap= 'gray' , interpolation= 'nearest' )
# 关掉图像的坐标
plt.axis( 'off' )
plt.show()</code>

你可能感兴趣的:(python,图像处理)