Medical imaging often suffers from low contrast, making it difficult for radiologists and automated systems to detect abnormalities such as pneumonia in chest X-rays. Enhancing these images can reveal hidden details, improve visibility of anatomical structures, and support more accurate diagnosis.
This project focuses on improving the visibility of bone and lung structures in low-contrast X-ray images using point processing transformations and histogram-based techniques.
Source: Kaggle – Chest X-Ray Pneumonia Dataset
- The dataset is organized into 3 folders:
train,test, andval, each containing subfolders for categories Pneumonia and Normal. - Contains 5,863 anterior-posterior (AP) chest X-Ray images (JPEG).
- Patient group: pediatric patients aged 1–5 years, collected at Guangzhou Women and Children’s Medical Center.
- Quality control: Low-quality/unreadable scans were removed. Diagnoses were graded by two expert physicians, with an additional third review on the evaluation set for consistency.
Before running the project, install the following dependencies:
pip install opencv-python matplotlib numpyIf running on Google Colab, you only need to upload your notebook and dataset.
-
Justification: Enhances visibility in darker regions while compressing bright areas. Useful for lung field details.
-
Function:
$$ s = c \cdot r^\gamma $$ where
cis a scaling constant andγcontrols brightness/contrast.
- Justification: Spreads out pixel intensities, improving global contrast.
- Function: Redistributes histogram values so intensities are more evenly spread across 0–255.
-
Justification: Expands a narrow range of intensity values to cover the full spectrum, improving image clarity.
-
Function:
$$ s = \frac{(r - r_{min})}{(r_{max} - r_{min})} \times (L-1) $$
- Justification: Gamma first enhances darker lung regions, while histogram equalization redistributes contrast globally. This gives the most balanced and clinically useful result.
- Gamma Transformation: Improved darker details but limited global contrast.
- Histogram Equalization: Strong global contrast improvement, but sometimes introduced noise in bright regions.
- Contrast Stretching: Helped when intensity range was narrow but less effective in varied datasets.
- Combination (Gamma + Histogram Equalization): Provided the best overall enhancement, balancing detail visibility with global contrast.
- Gamma (<1): Histogram shifts right (brighter image).
- Gamma (>1): Histogram shifts left (darker image).
- Histogram Equalization: Histogram flattens and spreads across full range.
- Contrast Stretching: Histogram expands from compressed/narrow range to full 0–255.
- Combination: Histogram shows both spread and adjusted distribution for balanced enhancement.
- The combination of Gamma Transformation + Histogram Equalization gave the most diagnostically useful results.
- This combination enhanced subtle lung details while also redistributing global contrast effectively.
- Recommendation: For medical image enhancement tasks, particularly chest X-rays, apply Gamma → Histogram Equalization for optimal clarity.
- Run the Jupyter Notebook / Colab Notebook.
- Upload a chest X-ray image (
.jpg,.jpeg,.png). - Select a transformation (Gamma, Histogram Equalization, Contrast Stretching, or Combination).
- View original vs enhanced image side by side with their histograms.
- Optionally save the enhanced image to your local machine.
The full well-commented code is available in the project notebook:
- Check the attached
.ipynbfile in this repository.
👨💻 Author: Rafay Adeel
📧 Contact: Rafay Adeel