Facebook
From Little Bird, 1 Week ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 29
  1. %matplotlib inline
  2. matplotlib.use('Agg')
  3. from __future__ import division
  4. from pylab import *
  5. import skimage
  6. from skimage import data, filters, exposure, feature, morphology
  7. from skimage.morphology import square
  8. from skimage.filters import rank
  9. from skimage.util.dtype import convert
  10. from skimage import img_as_float, img_as_ubyte
  11. #from skimage.io import Image
  12. from matplotlib.pyplot import imshow
  13. import skimage.io as io
  14. from skimage.color import rgb2hsv, hsv2rgb, rgb2gray
  15. from skimage.filters.edges import convolve
  16. from matplotlib import pylab as plt  
  17. import numpy as np
  18. from numpy import array
  19. from IPython.display import display
  20. from ipywidgets import interact, interactive, fixed
  21. from IPython.core.display import clear_output
  22.  
  23.  
  24. import warnings
  25. warnings.simplefilter("ignore")
  26.  
  27. def show_gray(img):
  28.      imshow(img, cmap='gray')
  29.      
  30.      import os
  31.  
  32. def fun(plane, coef_sobel, coef_bin, count_morph, coef_morph, coef_canny):
  33.     plane = rgb2gray(plane)
  34.     plane = filters.sobel(plane)#**coef_sobel
  35.     binary = plane > coef_bin
  36.    
  37.     dilated = binary
  38.     for i in range(count_morph):
  39.         dilated = morphology.dilation(dilated, square(coef_morph))
  40.  
  41.     eroded = dilated
  42.     for i in range(count_morph):
  43.         eroded = morphology.erosion(eroded, square(coef_morph))
  44.  
  45.     result = eroded
  46.     result = filters.rank.median(result, ones([3,3],dtype=uint8))
  47.     result = skimage.feature.canny(result, sigma=coef_canny)
  48.     return filters.sobel(result)
  49.  
  50. def load(coef_sobel, coef_bin, count_morph, coef_morph, coef_canny):
  51.     fig, axes = plt.subplots(nrows=21, figsize=(20,20*21))
  52.     for i, ax in enumerate(axes):
  53.         if(i < 10):
  54.             file =  os.getcwd() + '//planes/samolot0' + str(i) + '.jpg'
  55.         else:
  56.             file = os.getcwd() + '//planes/samolot' + str(i) + '.jpg'
  57.         plane = data.load(file)
  58.         result = fun(plane, coef_sobel, coef_bin, count_morph, coef_morph, coef_canny)
  59.         ax.imshow(result, cmap='gray')
  60.     fig.savefig('planes.pdf')
  61.  
  62. load(0.6, 0.1, 2, 3, 0)