def flatten(itr):
    if (type(itr) in (str, bytes, sitk.Image)):
        (yield itr)
    else:
        for x in itr:
            try:
                (yield from flatten(x))
            except TypeError:
                (yield x)
def flatten(itr):
    if (type(itr) in (str, bytes, sitk.Image)):
        (yield itr)
    else:
        for x in itr:
            try:
                (yield from flatten(x))
            except TypeError:
                (yield x)