This project implements a MATLAB-based pipeline for segmenting the liver and tumors from NIfTI medical images. It includes stages for data loading, extensive preprocessing, segmentation, evaluation, and visualization. All image processing and segmentation tasks are performed using classical image processing algorithms and techniques; no machine learning models are employed.
The pipeline processes 3D medical image volumes through several stages:
-
Data Loading:
- Loads NIfTI image and label files (e.g.,
*.nii.gz) using functions likedata_io.loadNiiVolumes. - Handles
.gzdecompression.
- Loads NIfTI image and label files (e.g.,
-
Preprocessing:
- ROI-based Normalization: Normalizes volume intensity based on a defined Region of Interest using
preprocessing.normalizeVolumeByRoi. - Histogram Analysis:
- Calculates volume histograms (
histogram_tools.calculateVolumeHistogram). - Groups histogram bins (
histogram_tools.groupHistogram). - Detects intensity bands within histograms (
histogram_tools.detectHistogramBand). - Removes histogram outliers (
histogram_tools.removeHistogramOutliers).
- Calculates volume histograms (
- Contrast Stretching: Adjusts volume contrast, for example, using
preprocessing.stretchVolumeContrast. - Artifact/Structure Removal: Removes high-intensity structures (e.g., bones) using functions like
preprocessing.removeHighIntensityArtifactsandpreprocessing.createStructureMask. - Histogram Matching: Matches volume histograms to a reference slice (
preprocessing.matchHistogramToReference). - Bilateral Filtering: Applies bilateral filters for noise reduction while preserving edges (e.g.,
preprocessing.applyBilateralFilter). - Mask Application: Applies masks to isolate regions of interest (
preprocessing.applyMask).
- ROI-based Normalization: Normalizes volume intensity based on a defined Region of Interest using
-
Segmentation:
- Liver Segmentation:
- Initial 2D segmentation based on intensity thresholds and morphological operations (e.g.,
segmentation.segmentLiverByThreshold2D). - 2D refinement using morphological operations (
segmentation.refineLiverMask2D). - 3D refinement, often by selecting the largest connected component (
segmentation.refineMask3DLargestComponent). - Post-processing for connectivity (
segmentation.postProcessLiverMaskConnectivity).
- Initial 2D segmentation based on intensity thresholds and morphological operations (e.g.,
- Tumor Segmentation: Segments tumors within the liver region, typically involving thresholding and morphological operations (e.g.,
segmentation.segmentTumors).
- Liver Segmentation:
-
Evaluation:
- Calculates segmentation performance metrics such as Dice score and Recall for both liver and tumor against ground truth labels (
evaluation.calculateSegmentationMetrics). - Displays these metrics in the command window (
evaluation.displayMetrics).
- Calculates segmentation performance metrics such as Dice score and Recall for both liver and tumor against ground truth labels (
-
Visualization:
- Displays 2D slices of volumes at various processing stages, often with overlays (
visualization.viewVolumeSlices). - Plots histograms and grouped histograms with detected bands (
visualization.plotHistogramComparison,visualization.plotGroupedHistogramWithBand). - Provides a GUI for comparing segmentation results with ground truth slice by slice (
visualization.displaySegmentationComparisonGUI). - Renders 3D surfaces of the segmented liver, tumors, and optionally bones (
visualization.render3DSegmentation).
- Displays 2D slices of volumes at various processing stages, often with overlays (
The project is organized using MATLAB packages:
+data_io/: Functions for data input/output.+evaluation/: Scripts for evaluating segmentation performance.+histogram_tools/: Utilities for histogram manipulation.+morph_ops/: Functions for morphological operations.+preprocessing/: Scripts for image preprocessing steps.+segmentation/: Algorithms for liver and tumor segmentation.+visualization/: Tools for displaying images, plots, and 3D renderings.data/: Intended for storing NIfTI image and label files (Note: this directory is ignored by Git as per.gitignore).old/: Contains older versions or auxiliary scripts.run_liver_analysis_pipeline.m: Main script to execute the entire pipeline.
- Ensure you have MATLAB installed with the Image Processing Toolbox. You will also need a NIfTI I/O library (the project uses
load_nii, which is common in the neuroimaging community). - Place your NIfTI image and label files (e.g.,
liver_XX.nii.gz) into adata/imagesTranddata/labelsTrsubdirectory respectively, or update the paths in the main configuration section of the script. - Open MATLAB and navigate to the project's root directory.
- Run the main pipeline script:
run_liver_analysis_pipeline.m.
The script run_liver_analysis_pipeline.m contains a config structure at the beginning where parameters like file paths, algorithm settings, and verbosity can be adjusted.
This project achieves liver and tumor segmentation using a sequence of classical image processing techniques. These include:
- Intensity-based thresholding
- Histogram analysis and manipulation (normalization, stretching, matching)
- Morphological operations (erosion, dilation, opening, closing, connected component analysis)
- Spatial filtering (e.g., bilateral filtering)
No machine learning or deep learning models are used in this pipeline. The segmentation is entirely driven by algorithmic processing of image intensities and spatial relationships. The performance of the pipeline is evaluated using standard metrics like Dice coefficient and Recall, which are reported at the end of the script execution. The specific results will vary depending on the input data and the fine-tuning of parameters within the config structure.
For reference, the algorithm with the current configuration was tested on the following dataset:
--- Segmentation Metrics ---
Dice Score Liver: 0.9496
Dice Score Tumor: 0.8680
Recall Liver: 0.9533
Recall Tumor: 0.8288
---------------------------
- MATLAB
- Image Processing Toolbox (for functions like
imhist,imfill,strel, morphological operations, etc.) - NIfTI file I/O tools (e.g., "Tools for NIfTI and ANALYZE image" by Jimmy Shen, which provides
load_nii).