beacon_aug/screenshot.py
def screenshot_library(BA_operator, image_data, save_fig_path=None, individual_fig=False, **kwargs):
    '''    Visualize the augmentation result comparision to all available libraries
    e.g.
    ----
    import beacon_aug as BA
    from  beacon_aug import screenshot
    fig, __ = BA.screenshot.screenshot_library(BA.Brightness(), image_data=image)
    fig.show()
    '''
    avail_libraries = BA_operator(**kwargs).avail_libraries

    numOfLibraries = len(avail_libraries)
    fig, axs = plt.subplots(2, 1 + numOfLibraries,
                            figsize=(4*numOfLibraries, 4),
                            constrained_layout=True)
    fig.suptitle("beacon_aug."+BA_operator.__name__ + " with " +
                 str(kwargs))  # or plt.suptitle('Main title')

    axs[0][0].imshow(image_data)
    axs[0][0].set_title("Raw")
    axs[1][0].text(0.3, 0.5, "Difference to\n" + "raw")
    axs[1][0].axis("off")

    attributes_result = {"runtime": {}, "differentiable": {}}
    # axs[1][0].text(0.3, 0.5, "Sanity Check:\n p=0  ->", dict(size=10))
    for i, library in enumerate(avail_libraries):
        t_before = time.time()
        op = BA_operator(always_apply=False, p=1, library=library, **kwargs)
        image_auged = op(image=image_data)["image"]

        t_after = time.time()

        runtime = t_after - t_before

        image_auged_vis = image_auged

        attributes_result["runtime"][library] = runtime

        attributes_result["differentiable"][library] = properties.isOpDifferentiable(op)

        axs[0][1+i].set_title(library + ":" + '{0:.1f}'.format(runtime*1000) + " (ms)")
        axs[0][1+i].imshow(image_auged)

        # display the difference of original to augmented images
        if image_auged.shape == image_data.shape:
            axs[1][1+i].imshow(image_auged - image_data)

        if save_fig_path and individual_fig == True:
            img_name = os.path.join(save_fig_path, BA_operator.__name__+"-" + library+".jpeg")
            if os.path.isfile(img_name):
                print("\n...screenshot individual figure already existed as : ", img_name)
            else:
                if image_auged.min() < 0:   # normalzied case, need to
                    image_auged = image_auged - image_auged.min()
                    image_auged = image_auged/image_auged.max()
                    print("@@@@@@@", image_auged.min())

                plt.imsave(img_name, image_auged)
                print("\n...screenshot individual figure save as : ", img_name)

    fig.subplots_adjust(wspace=0)
    if save_fig_path and individual_fig == False:
        fig_name = os.path.join(save_fig_path, BA_operator.__name__+"aug_library-screenshot.png")
        print("\n...screenshot figure save as : ", fig_name)
        plt.savefig(fig_name)
    return fig, attributes_result
    Visualize the augmentation result comparision to all available libraries
    e.g.
    ----
    import beacon_aug as BA
    from  beacon_aug import screenshot
    fig, __ = BA.screenshot.screenshot_library(BA.Brightness(), image_data=image)
    fig.show()
    
Visualize the augmentation result comparision to all available libraries
e.g.


Visualize the augmentation result comparision to all available libraries e . g .
def screenshot_library(BA_operator, image_data, save_fig_path=None, individual_fig=False, **kwargs):
    avail_libraries = BA_operator(**kwargs).avail_libraries
    numOfLibraries = len(avail_libraries)
    fig, axs = plt.subplots(2, 1 + numOfLibraries,
                            figsize=(4*numOfLibraries, 4),
                            constrained_layout=True)
    fig.suptitle("beacon_aug."+BA_operator.__name__ + " with " +
                 str(kwargs))  
    axs[0][0].imshow(image_data)
    axs[0][0].set_title("Raw")
    axs[1][0].text(0.3, 0.5, "Difference to\n" + "raw")
    axs[1][0].axis("off")
    attributes_result = {"runtime": {}, "differentiable": {}}
    for i, library in enumerate(avail_libraries):
        t_before = time.time()
        op = BA_operator(always_apply=False, p=1, library=library, **kwargs)
        image_auged = op(image=image_data)["image"]
        t_after = time.time()
        runtime = t_after - t_before
        image_auged_vis = image_auged
        attributes_result["runtime"][library] = runtime
        attributes_result["differentiable"][library] = properties.isOpDifferentiable(op)
        axs[0][1+i].set_title(library + ":" + '{0:.1f}'.format(runtime*1000) + " (ms)")
        axs[0][1+i].imshow(image_auged)
        if image_auged.shape == image_data.shape:
            axs[1][1+i].imshow(image_auged - image_data)
        if save_fig_path and individual_fig == True:
            img_name = os.path.join(save_fig_path, BA_operator.__name__+"-" + library+".jpeg")
            if os.path.isfile(img_name):
                print("\n...screenshot individual figure already existed as : ", img_name)
            else:
                if image_auged.min() < 0:   
                    image_auged = image_auged - image_auged.min()
                    image_auged = image_auged/image_auged.max()
                    print("@@@@@@@", image_auged.min())
                plt.imsave(img_name, image_auged)
                print("\n...screenshot individual figure save as : ", img_name)
    fig.subplots_adjust(wspace=0)
    if save_fig_path and individual_fig == False:
        fig_name = os.path.join(save_fig_path, BA_operator.__name__+"aug_library-screenshot.png")
        print("\n...screenshot figure save as : ", fig_name)
        plt.savefig(fig_name)
    return fig, attributes_result
def screenshot_library ( BA_operator , image_data , save_fig_path = None , individual_fig = False , ** kwargs ) : avail_libraries = BA_operator ( ** kwargs ) . avail_libraries numOfLibraries = len ( avail_libraries ) fig , axs = plt . subplots ( 2 , 1 + numOfLibraries , figsize = ( 4 * numOfLibraries , 4 ) , constrained_layout = True ) fig . suptitle ( "beacon_aug." + BA_operator . __name__ + " with " + str ( kwargs ) ) axs [ 0 ] [ 0 ] . imshow ( image_data ) axs [ 0 ] [ 0 ] . set_title ( "Raw" ) axs [ 1 ] [ 0 ] . text ( 0.3 , 0.5 , "Difference to\n" + "raw" ) axs [ 1 ] [ 0 ] . axis ( "off" ) attributes_result = { "runtime" : { } , "differentiable" : { } } for i , library in enumerate ( avail_libraries ) : t_before = time . time ( ) op = BA_operator ( always_apply = False , p = 1 , library = library , ** kwargs ) image_auged = op ( image = image_data ) [ "image" ] t_after = time . time ( ) runtime = t_after - t_before image_auged_vis = image_auged attributes_result [ "runtime" ] [ library ] = runtime attributes_result [ "differentiable" ] [ library ] = properties . isOpDifferentiable ( op ) axs [ 0 ] [ 1 + i ] . set_title ( library + ":" + '{0:.1f}' . format ( runtime * 1000 ) + " (ms)" ) axs [ 0 ] [ 1 + i ] . imshow ( image_auged ) if image_auged . shape == image_data . shape : axs [ 1 ] [ 1 + i ] . imshow ( image_auged - image_data ) if save_fig_path and individual_fig == True : img_name = os . path . join ( save_fig_path , BA_operator . __name__ + "-" + library + ".jpeg" ) if os . path . isfile ( img_name ) : print ( "\n...screenshot individual figure already existed as : " , img_name ) else : if image_auged . min ( ) < 0 : image_auged = image_auged - image_auged . min ( ) image_auged = image_auged / image_auged . max ( ) print ( "@@@@@@@" , image_auged . min ( ) ) plt . imsave ( img_name , image_auged ) print ( "\n...screenshot individual figure save as : " , img_name ) fig . subplots_adjust ( wspace = 0 ) if save_fig_path and individual_fig == False : fig_name = os . path . join ( save_fig_path , BA_operator . __name__ + "aug_library-screenshot.png" ) print ( "\n...screenshot figure save as : " , fig_name ) plt . savefig ( fig_name ) return fig , attributes_result
Visualize the augmentation result comparision to all available libraries
e.g.
Visualize the augmentation result comparision to all available libraries e . g .
'''    Visualize the augmentation result comparision to all available libraries
    e.g.
    ----
    import beacon_aug as BA
    from  beacon_aug import screenshot
    fig, __ = BA.screenshot.screenshot_library(BA.Brightness(), image_data=image)
    fig.show()
    ''' # or plt.suptitle('Main title') # axs[1][0].text(0.3, 0.5, "Sanity Check:\n p=0  ->", dict(size=10)) # display the difference of original to augmented images # normalzied case, need to
BA_operator
image_data
save_fig_path
individual_fig