裁剪图像中感兴趣区域python

题外话:比较全面的缩略图及相应源码 http://matplotlib.org/gallery.html
http://www.cnblogs.com/wei-li/archive/2012/05/23/2506940.html

题外外话:
http://stackoverflow.com/questions/8213522/matplotlib-clearing-a-plot-when-to-use-cla-clf-or-close

mark:
http://matplotlib.org/users/path_tutorial.html
http://stackoverflow.com/questions/21566610/crop-out-partial-image-using-numpy-or-scipy
http://stackoverflow.com/questions/25688573/matplotlib-set-clip-path-requires-patch-to-be-plotted
http://matplotlib.org/examples/images_contours_and_fields/image_demo_clip_path.html
http://blog.csdn.net/aguisy/article/details/5787221
http://matplotlib.org/users/path_tutorial.html
http://matplotlib.org/examples/shapes_and_collections/path_patch_demo.html

然而最有用的链接是介个:
http://www.scipy-lectures.org/advanced/image_processing/

目的是接上篇生成的高斯分布,3*delta范围内包含99+%的信息,那么3*delta外的区域置零,只保留半径为3*delta的区域。

import numpy as np
import matplotlib.pyplot as plt
#import cv2
from scipy import misc

#imgpath = './image.jpg'
#img = cv2.imread(imgpath)
img = misc.face(gray=True)
lx, ly = img.shape#[0:2]
X, Y = np.mgrid[0:lx, 0:ly]
# Mask
mask = (X-lx/2)**2 + (Y-ly/2)**2 > lx*ly/4
img[mask] = 0
# Display
plt.figure(figsize=(3, 3))
plt.axes([0, 0, 1, 1])
plt.imshow(img) # cmap=plt.cm.gray
plt.axis('off')

plt.show()

你可能感兴趣的:(python学习路)