Advertisement
smathot

Untitled

Mar 21st, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #-*- coding:utf-8 -*-
  3.  
  4. import sys
  5. import numpy as np
  6. from scipy.ndimage import imread, zoom
  7. from matplotlib import pyplot as plt
  8.  
  9. sys.path.insert(0, '/home/sebastiaan/Tmp/texture/scikit-image/')
  10.  
  11. from skimage.measure import block_reduce
  12.  
  13. im = imread('4.png', flatten=True)
  14. im = im != 255
  15.  
  16. for z in np.arange(1000,1,-1):
  17.  
  18.     print 'Downsample by %d' % z
  19.     im2 = block_reduce(im, (z,z), func=np.min)
  20.     if True not in im2:
  21.         continue
  22.     l = np.where(im2 == 1)
  23.     row = l[0][0]
  24.     col = l[1][0]
  25.  
  26.     minY = int(row*z)
  27.     maxY = int((row+1)*z)
  28.     minX = int(col*z)
  29.     maxX = int((col+1)*z)
  30.     surface = (maxX-minX)*(maxY-minY)
  31.  
  32.     print '(%d, %d) -> (%d, %d), surface = %d' % (minX, minY, maxX, maxY, \
  33.         surface)
  34.  
  35.     plt.subplot(211)
  36.     plt.imshow(im)
  37.     plt.axhline(minY, color='white')
  38.     plt.axhline(maxY, color='white')
  39.     plt.axvline(minX, color='white')
  40.     plt.axvline(maxX, color='white')
  41.     plt.subplot(212)
  42.     plt.imshow(im2)
  43.     plt.show()
  44.  
  45.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement