Example #1
0
def transform_image(image, params=[], tags=[]):
    image = apply_tags(image, tags)
    image = extract_roi(image, params)
    for k, v in params:
        if k == 'saturation':
            saturation = float(v)
            image = scale_saturation(image, saturation)
        elif k == 'gamma':
            gamma = float(v)
            image = np.power(img_as_float(image), gamma)
        elif k == 'brightness':
            b = float(v)
            image = (img_as_float(image) * b).clip(0., 1.)
        elif k == 'width':
            scale = float(v) / image.shape[1]
            image = rescale(image, scale)
        elif k == 'maxwidth':
            w = float(v)
            if image.shape[1] > w:
                scale = w / image.shape[1]
                image = rescale(image, scale)
        elif k == 'height':
            scale = float(v) / image.shape[0]
            image = rescale(image, scale)
        elif k == 'maxheight':
            h = float(v)
            if image.shape[0] > h:
                scale = h / image.shape[0]
                image = rescale(image, scale)
    return image
def transform_image(image, params=[], tags=[]):
    image = apply_tags(image, tags)
    image = extract_roi(image, params)
    for k,v in params:
        if k=='saturation':
            saturation = float(v)
            image = scale_saturation(image, saturation)
        elif k=='gamma':
            gamma = float(v)
            image = np.power(img_as_float(image), gamma)
        elif k=='brightness':
            b = float(v)
            image = (img_as_float(image) * b).clip(0.,1.)
        elif k=='width':
            scale = float(v) / image.shape[1]
            image = rescale(image, scale)
        elif k=='maxwidth':
            w = float(v)
            if image.shape[1] > w:
                scale = w / image.shape[1]
                image = rescale(image, scale)
        elif k=='height':
            scale = float(v) / image.shape[0]
            image = rescale(image, scale)
        elif k=='maxheight':
            h = float(v)
            if image.shape[0] > h:
                scale = h / image.shape[0]
                image = rescale(image, scale)
    return image
Example #3
0
def show_image(image,max_width=None,order=1):
    f = tmp_img()
    if image.dtype == np.bool:
        image = image.astype(np.int) * 255
    if max_width is not None:
        (h,w) = image.shape[:2]
        scale = max_width / float(w)
        image = rescale(image,scale,order=order)
    imsave(f,image)
    d = display.Image(filename=f)
    os.remove(f)
    return d