Image_processing module¶
-
class
Image_processing.Image(file_name=None, file_ext=None, color_type=None, image_array=None, dimensions=None, contrast_stretch_array=None, hist_eq_array=None, rev_video_array=None, image_as_string=None, log_comp_array=None, max_intensity_val=None, alpha_channel='no')¶ -
contrast_stretch()¶ Carries out contrast stretching on input image
Returns: self.contrast_stretch_array - numpy array containing image data of altered image :returns: run_time - the time it took to run this method in seconds
-
decode_string()¶ Takes in base64 string containing image data, determines the file type (either PNG or JPEG) based off this info, then saves the image to disc under the name ‘working_image’ with the same file extension as the input file
-
gather_data()¶ Gathers useful information about an input image and stores the data as object attributes. Functions by taking in a base64 string, decoding it then saving it as a numpy array
Returns: self.color_type a string stating ‘greyscale’ or ‘color’ Returns: self.dimensions an array in the form of (rows, columns) Returns: self.image_array: a numpy array containing the digital image data :returns: self.alpha_channel: a yes or no string indicating whether the image contains an alpha channel
-
get_file_ext()¶ Reads base64 image data and determines image file type ( PNG/JPEG)
Returns: self.file_ext - string reading either ‘.JPEG’ or ‘.PNG’
-
hist_eq()¶ Carries out histogram equalization on input image
Returns: self.hist_eq_array - numpy array containing image data of altered image :returns: run_time - the time it took to run this method in seconds
-
log_compression()¶ Carries out logarithmic compression on input image
Returns: self.log_comp_array - numpy array containing image data of altered image :returns: run_time - the time it took to run this method in seconds
-
output_histogram_data(hist_type)¶ Outputs image histogram data as arrays
Parameters: hist_type – the type of data for which the histogram is being produced (‘orignal’ - unaltered image, ‘hist_eq’ - image altered by histogram equalization, ‘rev_vid’ - image altered by reverse video, ‘contrast_stretch’ - image altered by contrast stretching, ‘log_comp’ - image altered by logarithmic compression :returns: red_hist - the red frequency values of the image’s histogram :returns: blue_hist-the blue frequency values of the image’s histogram :returns: green_hist - the green frequency values of the image’s histogram :returns: x_vals - the intensity values of the image (0-255)
-
remove_alpha_channel()¶ Removes alpha channel from image data array
Returns: self.image_array - image data array with alpha channel values removed
-
reverse_video()¶ Carries out reverse video on input image
Returns: self.rev_video_array - numpy array containing image data of altered image :return: run_time - the time it took to run this method in seconds
-
show_histogram()¶ Generates histogram of image in Python
-
-
Image_processing.contrast_stretching_complete(image_string)¶ Takes in base64 string, initializes an instance of Image class using this data, carries out contrast stretching, and generates plottable histogram data
Parameters: image_string – base64 string containing image data Returns: red_his - the red frequency values of the image’s histogram Returns: blue_hist - the blue frequency values of the image’s histogram Returns: green_hist - the green frequency values of the image’s histogram Returns: x_vals - the intensity values of the image (0-255) for histogram Returns: base64_string - string containing data for altered image Returns: run_time - the time it took to run the contrast stretching algorithm in seconds
-
Image_processing.encode_string(filename, file_ext)¶ Encodes image saved on disc into a base64 string
Parameters: - filename – filename of image on disc which is to be encoded
- file_ext – file extension of filename (.PNG/.JPEG)
Returns: string - base64 encoded image string
-
Image_processing.histogram_data(image_string)¶ Takes in base64 string, initializes an instance of Image class using this data, and generates plottable histogram data
Parameters: image_string – base64 string containing image data Returns: red_hist - the red frequency values of the image’s histogram Returns: blue_hist - the blue frequency values of the image’s histogram Returns: green_hist - the green frequency values of the image’s histogram Returns: x_vals - the intensity values of the image (0-255) for histogram
-
Image_processing.histogram_eq_complete(image_string)¶ Takes in base64 string, initializes an instance of Image class using this data, carries out histogram equalization, and generates plottable histogram data
Parameters: image_string – base64 string containing image data Returns: image - instance of Image class
-
Image_processing.initialize_image(image_string)¶ Creates instance of Image class called ‘image’ with the input base64 string as the image_as_string attribute
Parameters: image_string – base64 string containing image data Returns: image - instance of Image class
-
Image_processing.log_compression_complete(image_string)¶ Takes in base64 string, initializes an instance of Image class using this data, carries out logarithmic compression, and generates plottable histogram data
Parameters: image_string – base64 string containing image data Returns: red_hist - the red frequency values of the image’s histogram Returns: blue_hist - the blue frequency values of the image’s histogram Returns: green_hist - the green frequency values of the image’s histogram Returns: x_vals - the intensity values of the image (0-255) for histogram Returns: base64_string - string containing data for altered image Returns: run_time - the time it took to run the log compression algorithm algorithm in seconds
-
Image_processing.output_altered_histogram_data(hist_type, file_ext)¶ Outputs arrays containing histogram data of altered images
Parameters: - hist_type – the type of data for which the histogram is being produced (‘orignal’ - unaltered image, ‘hist_eq’ - image altered by histogram equalization, ‘rev_vid’ - image altered by reverse video, ‘contrast_stretch’ - image altered by contrast stretching, ‘log_comp’ - image altered by logarithmic compression
- file_ext – file extension of filename (.PNG/.JPEG)
Returns: red_hist - the red frequency values of the image’s histogram
Returns: blue_hist - the blue frequency values of the image’s histogram
Returns: green_hist - the green frequency values of the image’s histogram
Returns: x_vals - the intensity values of the image (0-255)
-
Image_processing.reverse_video_complete(image_string)¶ Takes in base64 string, initializes an instance of Image class using this data, carries out reverse video, and generates plottable histogram data
Parameters: image_string – base64 string containing image data Returns: red_hist - the red frequency values of the image’s histogram Returns: blue_hist - the blue frequency values of the image’s histogram Returns: green_hist - the green frequency values of the image’s histogram Returns: x_vals - the intensity values of the image (0-255) for histogram Returns: base64_string - string containing data for altered image Returns: run_time - the time it took to run the reverse video algorithm in seconds