Visualization Utility¶
Visualization Utility
-
kalmus.utils.visualization_utils.
extract_region_with_index
(image, region_index, labeled_image)[source]¶ Helper function that masked the labeled image on the input image, and extract the region with corresponding region index in the labeled image from the input image
- Parameters
image (numpy.ndarray) -- input image shape=(row(height), col(width))
region_index (int) -- the extracted region index in the labeled image
labeled_image (numpy.ndarray) -- the labeled image of the corresponding input image shape=image.shape
- Returns
Image with only region with corresponding index on labeled_image.
- Return type
numpy.ndarray
-
kalmus.utils.visualization_utils.
show_color
(color, figure_size=(9, 6), title='', axis_off=False, save_image=False, file_name='test.png', return_color=False)[source]¶ Plot the rgb color.
- Parameters
color (numpy.ndarray) -- 1D array contains the R, G, and B channel values
figure_size (tuple) -- Size of the plotted figure
title (str) -- The title of the plotted color
axis_off (bool) -- True to set the axis of the plot figure off. False to have the axis on the side of figure.
save_image (bool) -- True to save the plot figure into the path that user provide. False not to save the plot figure
file_name (str) -- The filename of the saved figure. The default path to the saved image is test.png
return_color (bool) -- Return the numpy array (shape==30 x 30 x 3) of color block if True. Directly plot the color if False
- Returns
Return the numpy array of color block if return_color is True.
- Return type
numpy.ndarray
-
kalmus.utils.visualization_utils.
show_colors_in_cube
(colors, figure_size=(8, 8), tight_plot=True, grid_off=True, background_off=True, return_figure=False, sampling=- 1, return_sampled_colors=False)[source]¶ Show a sequence of RGB colors in cubic RGB space (e.g. R axis (x axis), G axis (y axis), and B axis (z axis)) see https://matplotlib.org/3.1.1/gallery/mplot3d/scatter3d.html for more references ipympl is required for this function to work in the jupyter notebook
- Parameters
colors (numpy.ndarray) -- A sequence of colors to display in cubic space
figure_size (tuple) -- the size of the figure
tight_plot (bool) -- Remove the white margin around the plot if true Keep the original white margin if false
grid_off (bool) -- Remove the grid of plot if true Keep the original grid if false
background_off (bool) -- Use the transparent background if true Keep the original background if false
return_figure (bool) -- Return the plotted figure and axes, if true Directly plot the cube, if false
sampling (int) -- Number of data points plot in the 3D cube. -1 to include all data in the plot
return_sampled_colors (bool) -- Return the sampled out colors if True. Directly plot the colors in RGB cube if False
- Returns
return the figure and axes with plotted figure if return_figure is True or, return the sampled out colors if return_sampled_colors is True
- Return type
numpy.ndarray
-
kalmus.utils.visualization_utils.
show_colors_in_hue_light_3d_bar_plot
(colors, figure_size=(6, 6), hue_resolution=10, bri_resolution=0.02, return_figure=False, grid_off=True, background_off=True, shaded=False, tight_plot=True, axes=None, saturation_threshold=0.15)[source]¶ Show a sequence of RGB colors in a Hue vs. Light vs. Counts 3D bar Plot (Hue on x-axis, Light on y-axis, and counts/frequency of color on z-axis). Colors are assumed to be in the RGB colorspace and will be converted to the HSV color space within this function.
- Parameters
colors (numpy.ndarray) -- A sequence of colors to display in cubic space
figure_size (tuple) -- the size of the figure
hue_resolution (float) -- Resolution of the bar plot on the hue axis (hue 0 - 360)
bri_resolution (float) -- Resolution of the bar plot on the light axis (light 0 - 1)
return_figure (bool) -- Return the plotted figure and axes, if true Directly plot the cube, if false
grid_off (bool) -- Remove the grid of plot if true Keep the original grid if false
background_off (bool) -- Use the transparent background if true Keep the original background if false
shaded (bool) -- Shaded the 3D bar object if true Unshaded if false
tight_plot (bool) -- Remove the white margin around the plot if true Keep the original white margin if false
axes (matplotlib.pyplot.Axes) -- The matplotlib Axes object. If given function will plot the bar plot in the given Axes
saturation_threshold (float) -- The color of which the saturation value is under the threshold will be excluded from the plots
- Returns
return the figure and axes with plotted figure if return_figure is True
- Return type
tuple (matplotlib.pyplot.Figure, matplotlib.pyplot.Axes)
-
kalmus.utils.visualization_utils.
show_colors_in_hue_light_scatter_plot
(colors, figure_size=(10, 5), return_figure=False, remove_border=False, saturation_threshold=0.15)[source]¶ Show a sequence of RGB colors in a Hue vs. Light Scatter Plot (Hue on x-axis and Light on y-axis). Colors are assumed to be in the RGB colorspace and will be converted to the HSV color space within this function.
- Parameters
colors (numpy.ndarray) -- A sequence of colors to display in cubic space
figure_size (tuple) -- the size of the figure
return_figure (bool) -- Return the plotted figure and axes, if true Directly plot the cube, if false
remove_border (bool) -- Remove the frame border of the plot if true Keep the original frame border if false
saturation_threshold (float) -- The color of which the saturation value is under the threshold will be excluded from the plots
- Returns
return the figure and axes with plotted figure if return_figure is True
- Return type
tuple (matplotlib.pyplot.Figure, matplotlib.pyplot.Axes)
-
kalmus.utils.visualization_utils.
show_colors_in_sequence
(colors, figure_size=(9, 6), title='', axis_off=False, save_image=False, file_name='test.png', horizontal=True, return_color_sequence=False)[source]¶ Plot a sequence of RGB colors either horizontally or vertically in line
- Parameters
colors (numpy.ndarray) -- 2D array of RGB colors. Expected sequence shape==Number of colors x channels (3)
figure_size (tuple) -- the size of the plot figure
title (str) -- the title of the plot
axis_off (bool) -- True to set the axis of the figure off. False to have the axis with the figure
save_image (bool) -- True to save the plot figure. False do not save figure
file_name (str) -- the path of the saved figure
horizontal (bool) -- True to plot the sequence of colors horizontally, False to plot the sequence of colors vertically
return_color_sequence (bool) -- Return the numpy array (shape==30 x (30 * num_colors) x 3) of color sequence if True Directly plot the color sequence if False
- Returns
Return the numpy array of the color sequence image if return_color_sequence is True.
- Return type
numpy.ndarray
-
kalmus.utils.visualization_utils.
show_high_contrast_region
(image, minimum_segment_size=0.0004, figsize=(6, 4), return_region_image=False)[source]¶ Plot the high contrast region (brightness contrast) of the image. image is segmented using the gradient based watershed segmentation
- Parameters
image (numpy.ndarray) -- input color image shape=(row (height), col (width), channel(3))
minimum_segment_size (float) -- The minimum size (in relative ratio [0, 1]) for the segments in the segmented image
figsize (tuple) -- the size of the plot figure
return_region_image (bool) -- Return the image with only high contrast region if True. Directly plot the image if False
- Returns
If return_region_image is True, return the the image with only high contrast region. region_image.shape == image.shape
- Return type
numpy.ndarray
-
kalmus.utils.visualization_utils.
show_low_contrast_region
(image, minimum_segment_size=0.0004, figsize=(6, 4), return_region_image=False)[source]¶ Plot the low contrast region (brightness contrast) of the image. image is segmented using the gradient based watershed segmentation
- Parameters
image (numpy.ndarray) -- input color image shape=(row (height), col (width), channel(3))
minimum_segment_size (float) -- The minimum size (in relative ratio [0, 1]) for the segments in the segmented image
figsize (tuple) -- the size of the plot figure
return_region_image (bool) -- Return the image with only low contrast region if True. Directly plot the image if False
- Returns
If return_region_image is True, return the the image with only low contrast region. region_image.shape == image.shape
- Return type
numpy.ndarray