Beispiel #1
0
        # print("Image type %r recognized." % img.mode)
    elif img.mode in 'LP':
        print("Errored on", name)
        print(("Image type %r recognized, but this program is not written" +
               "for an 8-bit image.") % img.mode)
        print("Unsure how to proceed; exiting.")
        exit(1)
    else:
        print("Errored on", name)
        print("Image type %r recognized, but not a 0-255 grayscale image." %
              img.mode)
        print("Unsure how to proceed; exiting.")
        exit(4)

    if args.limits is None:
        inputs.append(list(image_iter(img)))
    else:
        inputs.append([im.crop(args.limits) for im in image_iter(img)])


def renorm_bin(arr, thresh, upper):
    float_arr = np.asarray(arr, dtype=np.float)
    normed = float_arr / upper_thresh
    np.clip(normed, 0, 1, out=normed)
    binned = arr > thresh
    return normed, binned


def arr_to_img(arr):
    return Image.fromarray(np.uint8(arr * 255))
Beispiel #2
0
try:
    img = Image.open(str(args.input))
except FileNotFoundError as e:
    print(e)
    exit(2)
except OSError as e:
    print(e)
    exit(3)
if img.mode not in 'LP':
    print("Image type %s recognized, but not a 0-255 grayscale image." %
          img.mode)
    print("Unsure how to proceed; exiting.")
    exit(1)

img_list = (list(image_iter(img)) if args.limits is None else
            [im.crop(args.limits) for im in image_iter(img)])
cyans_unnormalized = img_list[::2]
yellows_unnormalized = img_list[1::2]

hists = cyan_hist, yellow_hist = [
    np.sum([im.histogram() for im in img_list], axis=0)
    for img_list in (cyans_unnormalized, yellows_unnormalized)
]


def to_arr_lists(img_list, thresh, upper_thresh):
    thresh, upper_thresh, lst, bin_lst = renormalize_all(
        img_list, thresh, upper_thresh)
    arrs = np.asarray([np.asarray(im) for im in lst], dtype=float) / MAX_PIXEL
    bins = np.asarray([np.asarray(im) > 0 for im in bin_lst], dtype=bool)
        MAX_PIXEL = (1 << 16) - 1
        # print("Image type %r recognized." % img.mode)
    elif img.mode in 'LP':
        print("Errored on", name)
        print(("Image type %r recognized, but this program is not written" +
         "for an 8-bit image.") % img.mode)
        print("Unsure how to proceed; exiting.")
        exit(1)
    else:
        print("Errored on", name)
        print("Image type %r recognized, but not a 0-255 grayscale image." % img.mode)
        print("Unsure how to proceed; exiting.")
        exit(4)
    
    if args.limits is None:
        inputs.append(list(image_iter(img)))
    else:
        inputs.append([im.crop(args.limits) for im in image_iter(img)])


def renorm_bin(arr, thresh, upper):
    float_arr = np.asarray(arr, dtype=np.float)
    normed = float_arr / upper_thresh
    np.clip(normed, 0, 1, out=normed)
    binned = arr > thresh
    return normed, binned


def arr_to_img(arr):
    return Image.fromarray(np.uint8(arr * 255))
try:
    img = Image.open(str(args.input))
except FileNotFoundError as e:
    print(e)
    exit(2)
except OSError as e:
    print(e)
    exit(3)
if img.mode not in 'LP':
    print("Image type %s recognized, but not a 0-255 grayscale image." % img.mode)
    print("Unsure how to proceed; exiting.")
    exit(1)

img_list = (
    list(image_iter(img))
    if args.limits is None else
    [im.crop(args.limits) for im in image_iter(img)])
cyans_unnormalized = img_list[::2]
yellows_unnormalized = img_list[1::2]

hists = cyan_hist, yellow_hist = [
    np.sum([im.histogram() for im in img_list], axis=0)
    for img_list in (cyans_unnormalized, yellows_unnormalized)
]


def to_arr_lists(img_list, thresh, upper_thresh):
    thresh, upper_thresh, lst, bin_lst = renormalize_all(
        img_list, thresh, upper_thresh)
    arrs = np.asarray([np.asarray(im) for im in lst], dtype=float) / MAX_PIXEL