Start of the transition from jupyter to plain python. Still WIP ! For now, only give the cropped image.
69 lines
1.6 KiB
Python
69 lines
1.6 KiB
Python
import numpy as np
|
|
import utils
|
|
import sys
|
|
|
|
data = utils.load( sys.argv[1] )
|
|
|
|
"""
|
|
find fill points
|
|
"""
|
|
points = []
|
|
|
|
points += utils.find_point( data[ : , 0 ] , 0 ) # x_min
|
|
points += utils.find_point(
|
|
data[ : , data.shape[1] - 1 ],
|
|
data.shape[1] - 1 ,
|
|
) # x_max
|
|
|
|
index_min = 0
|
|
while data.shape[0] - 1 > index_min:
|
|
index_min += 1
|
|
if len( utils.find_point( data[ index_min , : ] , index_min , 'y' ) ) == 3:
|
|
break
|
|
|
|
points.append(
|
|
utils.find_point( data[ index_min , : ] , index_min , 'y' )[1]
|
|
) # y_min
|
|
|
|
index_max = data.shape[0] - 1
|
|
while index_min < index_max:
|
|
index_max -= 1
|
|
if len( utils.find_point( data[ index_max , : ] , index_max , 'y' ) ) == 3:
|
|
break
|
|
|
|
|
|
points.append(
|
|
utils.find_point( data[ index_max , : ] , index_max , 'y' )[1]
|
|
) # y_max
|
|
|
|
small_data = utils.compress( data , 5 )
|
|
|
|
points = utils.big_to_small( points , 5 )
|
|
|
|
points[ 1 ][ 1 ] -= 1
|
|
points[ 3 ][ 0 ] -= 1
|
|
|
|
extremum = []
|
|
for point in points:
|
|
taken_points = utils.small_to_big( utils.fill( small_data , point , 1000 ) , 5 )
|
|
extremum.append( [
|
|
np.min( taken_points[ : , 1 ] ),
|
|
np.max( taken_points[ : , 1 ] ),
|
|
np.min( taken_points[ : , 0 ] ),
|
|
np.max( taken_points[ : , 0 ] ),
|
|
] )
|
|
|
|
border = {
|
|
'x': {
|
|
'min': extremum[0][1] + 1,
|
|
'max': extremum[1][0] ,
|
|
},
|
|
'y': {
|
|
'min': extremum[2][3] + 1,
|
|
'max': extremum[3][2] ,
|
|
},
|
|
}
|
|
|
|
import matplotlib.pyplot as plt
|
|
plt.imshow( data[ border[ 'y' ][ 'min' ] : border[ 'y' ][ 'max' ] , border[ 'x' ][ 'min' ] : border[ 'x' ][ 'max' ] ] )
|
|
plt.savefig( 'test.png' )
|