Summary description here.

progress_bar[source]

progress_bar(i, n)

resize_file[source]

resize_file(fn, scale=1)

in_ipython[source]

in_ipython()

Check if the code is running in the ipython environment (jupyter including)

in_colab[source]

in_colab()

Check if the code is running in Google Colaboratory

in_notebook[source]

in_notebook()

Check if the code is running in a jupyter notebook

gpu_memory[source]

gpu_memory()

Print memory total, free and used

Images and Color Maps

  • Functions for displaying images and consistant color maps across
           0-255 int8 scaler data with appliet cmap  
    
    : 0-1 float32 RGB with label code annotations 0 to 255
    : images to look the same in matplotlib and in system image viewer

np_open_image[source]

np_open_image(fn:str)

open an image and return as numpy

cv_open_image[source]

cv_open_image(fn:str)

open an image and return as numpy

old_colormap_segmentation_labels[source]

old_colormap_segmentation_labels(N=256)

create a colour map for segmentation labels

generate_colormap_rgb[source]

generate_colormap_rgb(cmap:str='hot', num_colors:int=256)

generate a color map from a matplotlib base

  • cmap: colormap ( use matplotlib cmaps )
  • num_colors: less than 256, for label images set num_colors to the number of colors in the cmap colormap

generate_colormap_rgba[source]

generate_colormap_rgba(cmap:str='hot', num_colors:int=256)

generate a color map from a matplotlib base

  • cmap: colormap ( use matplotlib cmaps )
  • num_colors: less than 256, for label images set num_colors to the number of colors in the cmap colormap

LABEL_COLORMAP_RGB & LABEL_COLORMAP_RGBA

show_img[source]

show_img(im, figsize=None, ax=None, alpha=None, label=None, mode=None, axis_on=False, title=None, cmap=None, vmin=0, vmax=None)

plot_images[source]

plot_images(img_dict, figsize=None)

plot numpy images side by side

plot_images({'RGB':np_open_image(TEST_JPG), 'PNG':np_open_image(TEST_PNG)}, figsize=(12, 5))

cmap_show[source]

cmap_show(num=50)

Showing the first 50 colors, which repeat in stepes of 20, with the first black

cmap_show() 

Loading and saving greyscale uint8 images with LABEL_COLORMAP_RGB

save_png_p[source]

save_png_p(img:ndarray, fn)

Save an image as an 8 bit png file with an embedded LABEL_COLORMAP_RGB

  • img:
  • fn: filename to save
  • cmap: colormap ( use matplotlib cmaps )
  • num_colors: less than 256, for label images set num_colors to the number of colors in the cmap colormap
print("Save test image")
grd = np.linspace(0, 50, 50); 
grd = np.vstack((grd, grd, grd, grd)).astype(np.uint8)
show_img(grd, mode='P', axis_on=True)
plt.tight_layout()
# save_png_p(np.resize(grd,(200,200)), 'images/save_png_p_test.png', cmap='hot')
save_png_p(grd, 'images/save_png_p_test.png')
Save test image
print("Load test image to compare color maps")
img = np_open_image('images/save_png_p_test.png')
show_img(img, mode='P', axis_on=True)
plt.tight_layout()
Load test image to compare color maps

A sample of available colour maps

show_directory_stats[source]

show_directory_stats(path)