5 from skimage.morphology 
import binary_closing
 
    9     where = np.argwhere(mask)
 
   10     (y_start, x_start), (y_stop, x_stop) = where.min(0), where.max(0) + 1
 
   11     return img[y_start:y_stop, x_start:x_stop]
 
   16     for i 
in range(n_times):
 
   17         selem = np.ones((S[0] * (n_times - i), S[1] * (n_times - i)))
 
   18         mask = binary_closing(mask, selem=selem)