Ejemplo n.º 1
0
def dehaze_from_fp(fp):
    with PIL.Image.open(fp) as img:
        img.load()
    img = np.array(img)/255
    # remove background, assuming retinal fundus image
    background = get_background(img)
    img[background] = 1
    return dehaze(img)
Ejemplo n.º 2
0
def illuminate_dehaze(img):
    """
    Perform illumination correction to remove shadows followed by dehazing.
    Correctly remove background
    Return a tuple of dicts.  The first dict is output of illumination
    correction.  Second dict is output from dehazing.
    """
    # compute a background mask to clean up noise from the guided filter
    background = get_background(img)
    img[background] = 1

    d = illumination_correction(img)
    # reset the background
    d['radiance'][background] = 1/255

    d2 = dehaze(d['radiance'])

    d['background'] = background
    return d, d2
Ejemplo n.º 3
0
            (I).astype('float32'),
            sh_blur_radius,
            sh_blur_guided_eps)
        #  kernel = np.outer(*([sp.stats.norm.pdf(np.linspace(-1, 1, sh_blur_radius), 0, .7)]*2))
        #  A2 = sp.signal.fftconvolve(I/t1, reshape_A(kernel))
        return (I - A2) / t + A2

    dset = IDRiD('./data/IDRiD_segmentation')
    img, labels = dset['IDRiD_25']
    #  he = labels['HE']
    #  ma = labels['MA']
    #  ex = labels['EX']
    #  se = labels['SE']
    #  od = labels['OD']
    # set background pure black.
    bg = util.get_background(img)
    img[bg] = 0

    best = illuminate_sharpen(img)
    illum = methods.illuminate_dcp(I, focus_region=~bg)
    plt.figure(1)
    plt.imshow(sh(illum))
    plt.figure(2)
    plt.imshow(sh(Jc2, .2))
    #  best = competing_methods.sharpen(Jc2, focus_region=~bg)
    import sys
    sys.exit()
    plt.figure()
    plt.imshow(img)
    plt.figure()
    plt.imshow(best)
Ejemplo n.º 4
0
    clip = 30
    enhanced_img = clahe(I, clipLimit=clip, tileGridSize=gridsize, colorspace=cv2.COLOR_RGB2LAB)
    axs[ax_idx].imshow(enhanced_img)
    axs[ax_idx].set_title(f"Grid Size: {clip}", fontsize=20)
    axs[ax_idx].axis('off')
f.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0.1)
f.savefig(save_fp, bbox_inches='tight')

s = time.time()
from ietk.methods.sharpen_img import sharpen
from ietk.util import get_background
from skimage.color import rgb2lab, lab2rgb

save_fp = f'{ns.save_fig_dir}/qualitative-{img_idx}-sharpen-nogf.png'
f, axs = plt.subplots(1, 5, num=3, figsize=(4*5, 4))
bg = get_background(I)
I[bg] = 0
#  for ax_idx, t in enumerate([.5, .3, .15, .1, .05]):
for ax_idx, t in enumerate([.1, .01, .005, .002, .001,]):
    print('sharpen l', t)
    labI = rgb2lab(I)
    assert labI.shape[-1] == 3
    labI[:,:,0] = sharpen(labI[:,:,0], t=t, blur_guided_eps=.1, use_guidedfilter=False)
    enhanced_img = lab2rgb(labI)
    axs[ax_idx].imshow(enhanced_img)
    axs[ax_idx].set_title(f"t: {t}", fontsize=20)
    axs[ax_idx].axis('off')
f.subplots_adjust(wspace=0.02, hspace=0.02, top=0.9, bottom=0.1)
f.savefig(save_fp, bbox_inches='tight')
print(time.time() - s)