An automated computer image processing pipeline written in Python to quantify skin erythem following the application of Coated Microneedle arrays on in vivo porcine skin.
This pipeline overcomes local lighting variations, isolates the microneedle insertion footprint, normalizes biological colorimetric responses against untreated skin baseline.
As a secondary output, it also provides Footprint Area, Application Aspect Ratio, and Total Puncture Holes. The total puncture holes are not accurate and users should verfiy the output.
To eliminate the influence of system lighting variations, and natural background skin pigmentation, the pipeline utilizes a dual-zone concentric normalization model.
-
Microneedle Insertion Site (
$A_1$ ): The core region containing the actual device delivery footprint (visualized as the inner blue bounding box). -
Bezel Normalizing Area (
$A_2$ ): The surrounding untreated skin "halo" used as a localized baseline comparison zone (visualized as the outer magenta bounding box region, excluding the inner blue core).
The absolute tissue response is evaluated by subtracting the mean baseline skin index from the mean insertion site index:
Where the Mean Erythema Index (
-
$n_A$ represents the total number of valid pixels contained within region$A$ . -
$EI(x,y)$ represents the pixel-level spectroscopic erythema value at coordinate$(x,y)$ , derived from the raw RGB channels via the following logarithmic ratio:
In the underlying Python code execution framework:
mask_roi1corresponds to the Microneedle Insertion Site ($A_1$ ).mask_roi3corresponds to the Bezel Normalizing Area ($A_2$ ), generated by applying a logical bitwise-AND matrix subtraction gate (mask_roi2 & ~mask_roi1) to isolate the outer normalization ring cleanly away from the core parameters.
To capture different biological signatures of tissue trauma, the pipeline computes three distinct colorimetric delta metrics. All metrics use background subtraction, evaluating the mean intensity over the Microneedle Insertion Site (
Quantifies localized hemoglobin pooling and capillary blood flow. This index is highly sensitive to early-stage inflammatory flushes.
Where the pixel-level spectroscopic value
Quantifies pure tissue chromatic redness. Because it isolates the color data from the lightness channel, it acts as an objective measurement invariant to changing overhead room lighting or local skin shadows.
Where
Acts as an alternative subtractive color signature to track vascular changes and deeper mechanical tissue bruising.
Where the pixel-level subtractive Magenta component
(Note: ε = 10-7 is a small mathematical stabilizer to prevent division-by-zero errors in areas of pure white or absolute black pixels).
-
Dynamic Database Mapping: Automatically consumes a metadata mapping spreadsheet (
Image_analysis_info.csv) at runtime to dynamically mapLeftandRightregions of interest (ROIs) to their scientifically accuratecMNorbMNdesignations based on the filename. -
The "Whitewash" Guidance Subsystem: If the image contains numerous rectangular features (such as windows or tables), then a manual pre-processing can be done to apply a bulk white color across the image except the insertion site regions, and save it with prefix
whitewashed_. The script allows this manual pre-processing seamlessly. If an image features awhitewashed_prefix, the script derives the master bounding boxes and safe zones from the clean, noise-free whitewashed image, then mirrors those exact coordinates back onto the raw, unedited master image to extract completely unwarped, objective color statistics. -
Mechanical Shear Tracking: Computes the Application Aspect Ratio (
$W / H$ ) of the patch footprint to measure tissue stretching, skin elasticity, or user application slippage. However, care should be taken while interpretting these results. -
Micro-Hole Textural Topography: Uses fine-grained local adaptive thresholding to find individual microscopic needle punctures, then deploys local peak-maxima tracking to count the active holes and output a smooth density gradient heatmap overlayed in the
PINKcolormap. Care should be taken to verify these results.
To run the batch processing engine seamlessly, organize your project workspace directory exactly as follows:
├── Image_Analyzer.py # The execution analysis engine
├── Image_bMN_cMN_MAPPING.csv # The mandatory Left/Right patch assignment database
├── Week_1/ # Target directory specified in execution block
│ contains images to be analyzed. If image was 'whitewashed_', add the raw image without prefix 'whitewashed_' also here.
├── Week_N/ # Add more as needed
│ contains images to be analyzed.
The database must sit in the root execution directory and feature the following column syntax:
Image_Name,Left,Gender
name1.jpg,bMN,M
name2.jpg,cMN,F
and so on.
The script automatically deduces the right-side patch assignment as the inverse of the Left property.
📦 Project Dependencies
The libraries used in this script are divided into external packages that require installation and core modules that come pre-packaged with Python.
- External Packages (Installation Required)
These packages must be installed in your environment before running the pipeline:
opencv-python (provides cv2): Used for image loading, matrix transformations, color space manipulation, and morphological processing.
numpy (provides np): Used for high-performance array operations and numerical mask filtering.
scikit-image (provides skimage): Used for advanced color space transforms (color.rgb2lab) and textural spatial processing (peak_local_max).
Pillow (provides PIL): Used for core digital image handling and structural comparisons (ImageChops).
matplotlib (provides plt): Used for plotting diagnostic distributions, thresholds, and generating visual analytics charts.
pip install opencv-python numpy scikit-image Pillow matplotlib- Standard Libraries (Pre-Installed)
These modules are part of Python’s standard library and do not require any installation:
math: Handles geometric algorithms and numeric logarithmic operations.
os: Manages directory structures, file paths, and local file validation.
csv: Controls spreadsheet file read/write input and output pipelines.
Upon completion of a batch directory run, the pipeline will generate three new folders inside your target week directory alongside your summary CSV file:
-
final_experiment_results.csv: Detailed master spreadsheet containing side-by-side comparative metrics for both thecMNandbMNdelivery sites. -
[Folder_Name]/Week_1_results.csv/: Spreadsheet containing side-by-side comparative metrics for both thecMNandbMNdelivery sites for images in that particular folder. -
[Folder_Name]/bezelled_images/: Contains cropped image with a Blue rectangle around microneedle insertion site and Magenta around the baseline skin normalization halo. -
[Folder_Name]/processed_image/: Contains verification images displaying the locked master bounding frame for the hand-drawn rectangle (Yellow), a thin Magenta boundary padding the 20% Yellow box, the core patch proxy boundary (Blue), and the baseline skin normalization ring (thick Magenta). -
[Folder_Name]/debug_images/[Image_Name]/: Contains step-by-step diagnostic frames of the mask filters alongside the final pseudocolored needle density heatmap files.
