COSIE.image_preprocessing

Functions

combine_mask

Modify a grayscale image by applying a binary mask.

create_model

Create and load a pre-trained Vision Transformer (ViT-L/16) model from a HuggingFace-compatible checkpoint.

extract_features

Extracts both global and local visual features from an input image batch using a pretrained model.

generate_homograph

Generate a geometric transformation matrix from source to destination keypoints, using either rigid or affine transformation.

generate_pxl_location_from_mask

Extract pixel and spatial coordinates of 16×16 superpixels whose top-left pixels fall within the white (255) region of a binary mask.

get_white_superpixel_centers

Identify the center coordinates of superpixels that are entirely white (255) in a binary image.

image_feature_extraction

Extract image features at cell locations using a pretrained Vision Transformer (ViT) model and save the output to disk as a pickle file.

load_image

Efficiently load an image file and convert it to a NumPy array.

load_pickle

Load a Python object from a .pkl file.

mkdir

Create the parent directory for a given file or directory path if it does not already exist.

rescale_image

Rescale an image by a given scale factor using skimage.transform.rescale.

save_jpg

Convert a NumPy array into a JPEG image and save it to disk.

save_pickle

Save a Python object to a .pkl file using the pickle module.

transform_coordinates

Apply a geometric transformation matrix (e.g., from generate_homograph) to 2D coordinates.

Classes

PatchDataset

A PyTorch-compatible dataset for extracting 224×224 image patches centered at specified cell coordinates from a high-resolution RGB image.