# Path: imgProcessor/imgIO.py
# def imread(img, color=None, dtype=None):
#     '''
#     dtype = 'noUint', uint8, float, 'float', ...
#     '''
#     COLOR2CV = {'gray': cv2.IMREAD_GRAYSCALE,
#                 'all': cv2.IMREAD_COLOR,
#                 None: cv2.IMREAD_ANYCOLOR
#                 }
#     c = COLOR2CV[color]
#     if callable(img):
#         img = img()
#     elif isinstance(img, string_types):
#         #         from_file = True
#         #         try:
#         #             ftype = img[img.find('.'):]
#         #             img = READERS[ftype](img)[0]
#         #         except KeyError:
#         # open with openCV
#         # grey - 8 bit
#         if dtype in (None, "noUint") or np.dtype(dtype) != np.uint8:
#             c |= cv2.IMREAD_ANYDEPTH
#         img2 = cv2.imread(img, c)
#         if img2 is None:
#             raise IOError("image '%s' is not existing" % img)
#         img = img2
# 
#     elif color == 'gray' and img.ndim == 3:  # multi channel img like rgb
#         # cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #cannot handle float64
#         img = toGray(img)
#     # transform array to uint8 array due to openCV restriction
#     if dtype is not None:
#         if isinstance(img, np.ndarray):
#             img = _changeArrayDType(img, dtype, cutHigh=False)
# 
#     return img


from imgProcessor.imgIO import imread
from scipy.ndimage.filters import median_filter
from scipy.optimize import curve_fit
    from fancytools.os.PathStr import PathStr
import numpy as np
    import sys
    import imgProcessor
    import pylab as plt

    if imgs2 is None:
        imgs2 = [None] * len(imgs1)
    else:
        assert len(imgs1) == len(imgs2)

    y_vals = np.empty((len(imgs1), nbins))
    w_vals = np.zeros((len(imgs1), nbins))

    if mn_mx is None:
        print('estimating min and max image value')
        mn = 1e6
        mx = -1e6
        # get min and max image value checking all first images:
        for n, i1 in enumerate(imgs1):
            print('%s/%s' % (n + 1, len(imgs1)))
            i1 = imread(i1)
            mmn, mmx = _getMinMax(i1)
            mn = min(mn, mmn)
            mx = mx = max(mx, mmx)
        print('--> min(%s), max(%s)' % (mn, mx))
    else:
        mn, mx = mn_mx

    x = None
    print('get noise level function')
    for n, (i1, i2) in enumerate(zip(imgs1, imgs2)):
        print('%s/%s' % (n + 1, len(imgs1)))

        i1 = imread(i1)
        if i2 is not None:

# Path: imgProcessor/imgIO.py
# def imread(img, color=None, dtype=None):
#     '''
#     dtype = 'noUint', uint8, float, 'float', ...
#     '''
#     COLOR2CV = {'gray': cv2.IMREAD_GRAYSCALE,
#                 'all': cv2.IMREAD_COLOR,
#                 None: cv2.IMREAD_ANYCOLOR
#                 }
#     c = COLOR2CV[color]
#     if callable(img):
#         img = img()
#     elif isinstance(img, string_types):
#         #         from_file = True
#         #         try:
#         #             ftype = img[img.find('.'):]
#         #             img = READERS[ftype](img)[0]
#         #         except KeyError:
#         # open with openCV
#         # grey - 8 bit
#         if dtype in (None, "noUint") or np.dtype(dtype) != np.uint8:
#             c |= cv2.IMREAD_ANYDEPTH
#         img2 = cv2.imread(img, c)
#         if img2 is None:
#             raise IOError("image '%s' is not existing" % img)
#         img = img2
# 
#     elif color == 'gray' and img.ndim == 3:  # multi channel img like rgb
#         # cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #cannot handle float64
#         img = toGray(img)
#     # transform array to uint8 array due to openCV restriction
#     if dtype is not None:
#         if isinstance(img, np.ndarray):
#             img = _changeArrayDType(img, dtype, cutHigh=False)
# 
#     return img


# Path: imgProcessor/camera/NoiseLevelFunction.py
from imgProcessor.imgIO import imread
from scipy.ndimage.filters import median_filter
from scipy.optimize import curve_fit
    from fancytools.os.PathStr import PathStr
import numpy as np
    import sys
    import imgProcessor
    import pylab as plt

    if imgs2 is None:
        imgs2 = [None] * len(imgs1)
    else:
        assert len(imgs1) == len(imgs2)

    y_vals = np.empty((len(imgs1), nbins))
    w_vals = np.zeros((len(imgs1), nbins))

    if mn_mx is None:
        print('estimating min and max image value')
        mn = 1e6
        mx = -1e6
        # get min and max image value checking all first images:
        for n, i1 in enumerate(imgs1):
            print('%s/%s' % (n + 1, len(imgs1)))
            i1 = imread(i1)
            mmn, mmx = _getMinMax(i1)
            mn = min(mn, mmn)
            mx = mx = max(mx, mmx)
        print('--> min(%s), max(%s)' % (mn, mx))
    else:
        mn, mx = mn_mx

    x = None
    print('get noise level function')
    for n, (i1, i2) in enumerate(zip(imgs1, imgs2)):
        print('%s/%s' % (n + 1, len(imgs1)))

        i1 = imread(i1)
        if i2 is not None:

            i2 = imread(i2)
