This repository contains a series of Python scripts that work after one another to process images of spheroidal tissue models, perform segmentation using a YOLO model, post-process the segmentation masks, and analyze image darkness scores. The scripts are numbered in the order in which they should be executed.
This pipeline is designed to process high-bit TIFF images of spheroids, convert them to PNG format, perform YOLO-based segmentation inference, generate composite images using segmentation masks, and finally analyze the darkness score (i.e., average pixel intensity) of non-masked areas.
The workflow is as follows:
-
PNG Export (00PNGExport.py):
Inspects and processes a TIFF image from theAcquisitionfolder, converting its final layer to an 8-bit grayscale PNG. The result is saved in theoutputfolder. -
Segmentation Inference (01Segmentation_Inference.py):
Loads a YOLO segmentation model (Segment.pt) from the working directory and runs inference on PNG images from theoutputfolder. The segmentation outputs (binary masks and object statistics CSV) are saved in theseg_outputfolder. -
Mask Post-Processing (02Masks.py):
Combines the raw PNG image (from theoutputfolder) with the corresponding binary segmentation mask (fromseg_output/inferenceSeg/mask_crops/1). The composite images—where background areas are replaced with green—are saved in a new folderRawMaskswithin the mask folder. -
Darkness Score Analysis (03DarknessScore.py):
Processes the composite images fromseg_output/inferenceSeg/RawMasksto calculate darkness scores (average pixel intensity) for non-green areas. It also generates intermediate images (green mask, inverted mask, grayscale object image, histogram) and saves the analysis results as a CSV file.
- Purpose:
- Inspects a TIFF image and prints its properties (format, mode, size, number of frames, pixel range).
- Processes the TIFF by converting its final layer from 16-bit to an 8-bit grayscale image.
- Exports the processed image as a PNG to the
outputfolder.
- Input:
- A TIFF image (e.g.,
Spheroid.tiff) located in theAcquisitionfolder.
- A TIFF image (e.g.,
- Output:
- Processed PNG image saved in the
outputfolder.
- Processed PNG image saved in the
- Purpose:
- Loads the YOLO segmentation model (
Segment.pt) from the current working directory. - Runs segmentation inference on images located in the
outputfolder. - Saves segmentation outputs including binary masks and a CSV (
seg_circularity.csv) with area, perimeter, and circularity data.
- Loads the YOLO segmentation model (
- Input:
- PNG images from the
outputfolder. - Model file
Segment.pt(located in the working directory).
- PNG images from the
- Output:
- Segmentation outputs saved in the
seg_outputfolder, including binary mask crops inseg_output/inferenceSeg/mask_crops.
- Segmentation outputs saved in the
- Purpose:
- Combines the raw PNG image from the
outputfolder with its corresponding binary segmentation mask fromseg_output/inferenceSeg/mask_crops/1. - Creates composite images where pixels corresponding to the mask remain as in the raw image, and the rest are replaced with a green background.
- Saves the composite images in a new folder named
RawMaskswithinseg_output/inferenceSeg/mask_crops/1.
- Combines the raw PNG image from the
- Input:
- Raw PNG images from the
outputfolder. - Binary mask images from
seg_output/inferenceSeg/mask_crops/1.
- Raw PNG images from the
- Output:
- Composite images saved in
seg_output/inferenceSeg/mask_crops/1/RawMasks.
- Composite images saved in
- Purpose:
- Processes the composite images (from
seg_output/inferenceSeg/RawMasks) to compute a darkness score (average grayscale intensity) for the non-green areas. - Generates intermediate output images: the green mask, inverted mask, a grayscale image of the object, and a histogram of pixel intensities.
- Saves the analysis results to a CSV file (
average_intensities.csv).
- Processes the composite images (from
- Input:
- Composite images (PNG) from
seg_output/inferenceSeg/RawMasks.
- Composite images (PNG) from
- Output:
- Intermediate processing images and a CSV file with darkness scores, all saved in a new subfolder (
output) under the processed folder.
- Intermediate processing images and a CSV file with darkness scores, all saved in a new subfolder (
Note: You may need to adjust the folder path in
03DarknessScore.pyto ensure it points to the correct location relative to your working directory.
-
Clone the Repository:
git clone <repository_url> cd <repository_folder>