Example #1
0
def noise(src, p, p_chroma, level):
    if np.random.uniform() < p:
        with iproc.array_to_wand(src) as tmp:
            tmp = _noise(tmp, p_chroma, level)
            dst = iproc.wand_to_array(tmp)
        return dst
    else:
        return src
Example #2
0
def scale(src, filters, bmin, bmax, scale):
    h, w = src.shape[:2]
    blur = np.random.uniform(bmin, bmax)
    rand = random.randint(0, len(filters) - 1)
    with iproc.array_to_wand(src) as tmp:
        tmp.resize(w // 2, h // 2, filters[rand], blur)
        if scale:
            tmp.resize(w, h, 'box')
        dst = iproc.wand_to_array(tmp)
    return dst
Example #3
0
def noise_scale(src, filters, bmin, bmax, upscaling, p, p_chroma, level):
    h, w = src.shape[:2]
    blur = np.random.uniform(bmin, bmax)
    rand = random.randint(0, len(filters) - 1)
    with iproc.array_to_wand(src) as tmp:
        tmp.resize(w // 2, h // 2, filters[rand], blur)
        if np.random.uniform() < p:
            tmp = _noise(tmp, p_chroma, level)
        if upscaling:
            tmp.resize(w, h, 'box')
        dst = iproc.wand_to_array(tmp)
    return dst
Example #4
0
def scale(src, filters, bmin, bmax, upsampling):
    # 'box', 'triangle', 'hermite', 'hanning', 'hamming', 'blackman',
    # 'gaussian', 'quadratic', 'cubic', 'catrom', 'mitchell', 'lanczos',
    # 'lanczos2', 'sinc'
    h, w = src.shape[:2]
    blur = np.random.uniform(bmin, bmax)
    rand = random.randint(0, len(filters) - 1)
    with iproc.array_to_wand(src) as tmp:
        tmp.resize(w // 2, h // 2, filters[rand], blur)
        if upsampling:
            tmp.resize(w, h, 'box')
        dst = iproc.wand_to_array(tmp)
    return dst
Example #5
0
def benchmark(cfg, models, images, sampling_factor, quality):
    scores = []
    for src in images:
        dst = pairwise_transform.scale(np.array(src),
                                       [cfg.downsampling_filter], 1, 1, False)
        if quality != 100 or cfg.method != 'scale':
            with iproc.array_to_wand(dst) as tmp:
                tmp = iproc.jpeg(tmp, sampling_factor, quality)
                dst = iproc.wand_to_array(tmp)
        dst = Image.fromarray(dst)
        if 'noise_scale' in models:
            dst = upscale_image(cfg, dst, models['noise_scale'])
        else:
            if 'noise' in models:
                dst = denoise_image(cfg, dst, models['noise'])
            if 'scale' in models:
                dst = upscale_image(cfg, dst, models['scale'])
        score = iproc.clipped_psnr(np.array(dst), np.array(src), a_max=255)
        scores.append(score)
    return np.mean(scores), np.std(scores) / np.sqrt(len(scores))