mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-18 12:40:14 +08:00
53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
__author__ = 'Olivier Debeir 2021'
|
|
|
|
import logging
|
|
import time
|
|
|
|
def init_logger(logfilename = 'myapp.log'):
|
|
"""add logger capabilities
|
|
"""
|
|
FORMAT = '%(asctime)-15s %(processName)s %(process)d %(message)s'
|
|
logging.basicConfig(filename=logfilename,format=FORMAT,filemode='wt')
|
|
logger = logging.getLogger()
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
# create console handler and set level to debug
|
|
ch = logging.StreamHandler()
|
|
ch.setLevel(logging.DEBUG)
|
|
|
|
# add ch to logger
|
|
logger.addHandler(ch)
|
|
logger.info('start logging in %s' % logfilename)
|
|
return logger
|
|
|
|
|
|
logger = logging.getLogger()
|
|
|
|
def log_timing(func):
|
|
|
|
def wrapper(*arg):
|
|
log_timing.level += 1
|
|
t1 = time.time()
|
|
res = func(*arg)
|
|
t2 = time.time()
|
|
ms = (t2-t1)*1000.0
|
|
logger.info('%s%s took %0.3f ms' % (log_timing.level*'-',func.func_name, ms))
|
|
log_timing.level -= 1
|
|
return (res,ms)
|
|
|
|
return wrapper
|
|
|
|
log_timing.level = 0
|
|
|
|
def tumbnail_it(data):
|
|
"""display image with its histogram
|
|
"""
|
|
h = np.histogram(data[:],100)
|
|
hn = 512*h[0]/np.max(h[0])
|
|
|
|
plt.subplot(1,2,1)
|
|
plt.imshow(ima8,interpolation='nearest',cmap=cm.gray)
|
|
plt.subplot(1,2,2)
|
|
plt.plot(hn)
|
|
plt.colorbar()
|