mrftools.ImageLoader module¶
Utility class for loading images into grid MRF structures for image segmentation
-
class
mrftools.ImageLoader.ImageLoader(max_width=0, max_height=0)[source]¶ Bases:
objectImage loading class that reads images from disk and creates grid-structured CRFs for image segmentation
-
static
calculate_tree_probabilities_snake_shape(width, height)[source]¶ Calculate spanning-tree edge appearance probabilities by considering two “snakes” that cover the graph going north-to-south and east-to-west.
Parameters: - width (int) – width of grid MRF
- height (int) – height of grid MRF
Returns: dictionary of edge appearance probabilities under the two-snake spanning tree distribution
Return type: dict
-
static
compute_features(img)[source]¶ Generate pixel and edge features based on Fourier expansion. Method ported from https://arxiv.org/abs/1301.3193 by Justin Domke.
Parameters: img (image) – image to compute features of Returns: tuple of two dictionaries: (1) a dictionary of pixel features, (2) a dictionary of edge features Return type: tuple
-
static
create_model(img, num_states)[source]¶ Create a log-linear model for the image
Parameters: - img (image) – PIL image object
- num_states (int) – number of labels possible for each image
Returns: LogLinearModel representing the image with variables for each pixel
Return type:
-
draw_image_and_label(name)[source]¶ Draw an image and its ground truth label.
Parameters: name (string) – path to image file Returns: None
-
static
get_all_edges(img)[source]¶ Create a list of all edges in a grid structured graph of the same width and height as the image. :param img: image object with a width and height :type img: image :return: list of edges :rtype: list
-
load_all_images_and_labels(directory, num_states, num_images=inf)[source]¶ Load all jpg or png images from a directory.
Parameters: - directory (string) – path to directory
- num_states (int) – number of possible classes for segmentation
- num_images (int) – maximum number of images to load
Returns: tuple containing the images, LogLinearModels, the labels, and the names of the images
Return type: tuple
-
load_image(path)[source]¶ Load image at path and resize according to our maximum size parameters :param path: location of image in file system :type path: string :return: PIL image object
-
load_label_dict(image_name)[source]¶ Create a dictionary of label values for an image and label file.
Parameters: image_name (string) – full path to the image file (this method will remove the extension and append ‘_label.txt’ Returns: dictionary with pixel names as keys (pixel_width, pixel_height) and integer class as values Return type: dict
-
load_label_img(image_name)[source]¶ Load the semantic segmentation labels, assuming they are stored in a space-delimited text table of the same size as the image. This method will resize the label image according to this object’s maximum size parameters. The labels should be integer values starting from 0.
The label file must have the same name as the associated image, except instead of the image type extension, it has ‘_label.txt’ as its suffix. For example the image ‘./picture1.jpg’ should have label file ‘./picture1_label.txt’
Parameters: image_name (string) – full path to the image file (this method will remove the extension and append ‘_label.txt’ Returns: PIL image object with the labels as the greyscale intensity value. Return type:
-
static