def image_filter(img):
img2 = img.copy();
img2[img2 < 30] = 100;
img2 = exp.smooth_image(img2, sigma = 1.0);
#plt.figure(6); plt.clf();
#plt.imshow(img2);
# threshold image and take zero smaller components..
th = img2 < 92;
th2 = morph.binary_closing(th, morph.diamond(1))
label = meas.label(th2, background=0)
#plt.imshow(mask)
bs = meas.regionprops(label+1);
area = np.array([prop.area for prop in bs]);
if len(area) > 0:
mask = np.logical_and(label > -1, label != np.argsort(area)[-1]);
img2[mask] = 100;
img2[:2,:] = 100; img2[-2:,:] = 100;
img2[:,:2] = 100; img2[:,-2:] = 100;
#plt.figure(6); plt.clf();
#plt.subplot(1,2,1);
#plt.imshow(img2, vmin = 84, vmax = 92, cmap = plt.cm.gray)
#plt.subplot(1,2,2);
#plt.imshow(img2);
return img2;
评论列表
文章目录