histogram module

A module providing facilities for generating and analyzing histograms based on greyscale images.

This module provides methods that take a greyscale image and create a histogram of pixel values. The resulting histograms can be analyzed to determine the cloudiness of each image. Histograms can be plotted and saved. Categorization of histograms can also be done through this module.

histogram.categorize(histogram, categories)[source]

Categorize a histogram based on the given categories.

Parameters:
  • histogram (array_like) – List of histogram bin values.
  • categories (dict) – A dictionary mapping category names to the histograms that define them.
Returns:

The category that the histogram belongs to.

Return type:

object or None

Notes

This method uses the histogram intersection algorithm. The algorithm is defined originally by Swain and Ballard in a paper entitled Color Indexing [1].

In essence the method decides what category the histogram belongs to by finding the category whose histogram”s shape most closely matches that of the input histogram.

References

[1]Swain, M.J. & Ballard, D.H. Int J Comput Vision (1991) 7: 11. https://doi.org/10.1007/BF00130487
histogram.cloudiness(hist)[source]

Calculate the cloudiness of a histogram.

Parameters:hist (array_like) – List of histogram bin values.
Returns:Cloudiness value of a given histogram.
Return type:float

Notes

The cloudiness fraction for a histogram is calculated by taking the number of greyscale pixel values above 160 and dividing it by the total number of greyscale pixel values that appear in the histogram.

histogram.generate_histogram(img, masking=None)[source]

Generate a histogram of pixel values.

Parameters:
Returns:

hist – The histogram values.

Return type:

list

histogram.init_categories()[source]

Initialize histogram categories.

Returns:A dictionary mapping category names to the histograms that define them.
Return type:dict

Notes

Images used for initializing each category are stored in Images/category/. These images can be downloaded from the GitHub repository.

histogram.plot_histogram(img, hist, masking=None, save=True)[source]

Plot and save an image and histogram.

Parameters:
  • img (image.AllSkyImage) – The image.
  • hist (array_like) – Histogram of image pixel values.
  • masking (numpy.ndarray, optional) – A masking array of pixels to ignore. Defaults to None.
  • save (bool, optional) – If the plot should be saved. Defaults to True.

Notes

This method will save the histogram into Images/histogram/img.date/ img.name.