---
title: "OpenCV for medical image analysis: Open Source pattern recognition"
description: "The OpenCV library originating at Intel in 1999, OpenCV 1.0 of 2006 and 1.1 in development in 2008. Pre-processing, feature extraction, Viola-Jones face detection, and typical uses in mammography, retinal imaging, microscopy and dermatology."
url: "https://www.noze.it/en/insights/opencv-medical-image-analysis/"
lang: "en"
alternate: "https://www.noze.it/insights/opencv-imaging-analisi-medica/"
published: "2008-10-28"
author: "noze S.r.l."
keywords: "Digital Health, R&D, Open Source, OpenCV, Computer Vision, Image Analysis, Pattern Recognition, Mammography, Retinal Imaging, Microscopy"
---

# OpenCV for medical image analysis: Open Source pattern recognition

The OpenCV library originating at Intel in 1999, OpenCV 1.0 of 2006 and 1.1 in development in 2008. Pre-processing, feature extraction, Viola-Jones face detection, and typical uses in mammography, retinal imaging, microscopy and dermatology.

28 October 2008

## From industry to medical imaging

**OpenCV** — _Open Source Computer Vision Library_ — is one of the most widespread Open Source computer vision libraries in the world. Born in **1999-2000** within **Intel Research** under **Gary Bradski’s** initiative, it went through public alpha/beta releases between 2000 and 2006, and the first **stable 1.0 release** was published in **October 2006**. **Version 1.1** is currently in preparation, with public release expected over 2008.

In **2008** the project’s support is taken up by **Willow Garage**, an industrial robotics spin-off founded in Menlo Park, funding the partial rewrite in C++ of key components and preparation of the 2.0 expected in 2009. The model is the shift from a _corporate-funded_ project to a community project, keeping the original **BSD** licence and openness to external contributions.

The book **“Learning OpenCV” by Gary Bradski and Adrian Kaehler**, published by O’Reilly in September 2008, is the library’s reference manual — complete and didactically effective, contributing to further diffusion in academic and research environments.

## The application domain

OpenCV is **generalist**: its original target is industrial vision, human-computer interaction, video surveillance, robotics, automation. It is not a library specifically for medical imaging — for that, the reference is ITK, discussed separately. But many of its base operations apply directly to biomedical images, and a growing number of clinical publications use OpenCV as implementation tool.

Its strength is its orientation to **2D on photographic-quality images** — exactly the type of input of many non-volumetric diagnostic modalities: mammography, retinal/fundus imaging, dermatology, endoscopy, light microscopy, digital pathology. For 3D CT/MR volumes the natural choice remains ITK; for “natural” 2D medical images, OpenCV has much to offer.

## Capabilities as of 2008

OpenCV 1.x includes:

### Manipulation and pre-processing

- Reading/writing common image formats (not DICOM natively, but with external adapters)
- Colour conversions (RGB, HSV, LAB, grayscale), histograms, equalisation
- Filters: Gaussian, median, bilateral, Sobel, Laplacian, Canny (edge detection)
- Morphological operations: erosion, dilation, opening, closing, top-hat, watershed
- Transforms: Hough (lines and circles), Fourier, distance transform

### Segmentation and analysis

- Thresholding (global, adaptive, Otsu)
- Contour detection and approximation
- Connected components
- GrabCut (foreground/background segmentation)
- Flood fill

### Feature detection and description

- Corner detection: Harris, Shi-Tomasi (_goodFeaturesToTrack_), FAST
- Blob detection: MSER, SimpleBlobDetector
- **SIFT** and **SURF** — patent-covered (SIFT: University of British Columbia) so usable only in non-commercial contexts

### Classification

- Support Vector Machines (wrapper over libsvm)
- K-nearest neighbours
- Boosted classifiers (AdaBoost)
- Random Trees
- Normal Bayes Classifier
- Neural networks (shallow multilayer perceptrons)
- Expectation-Maximization

### Face detection

The implementation of **Viola-Jones** (2001), with cascades of Haar-like feature classifiers, is available out-of-the-box. Trained on human faces, it has been used as a starting point in many medical applications — training of custom cascades on lesions, microcalcifications, cells, via the provided training pipeline.

## Applications in medicine

Biomedical literature from 2007-2008 starts citing OpenCV as implementation tool in several scenarios:

### Mammography

- Pre-processing to enhance microcalcification contrast
- Detection of suspicious ROIs with custom Haar cascades
- Fibroglandular tissue segmentation
- Breast density analysis

### Ophthalmic imaging

- Retinal vessel segmentation (Hough, reimplemented Frangi filters)
- Optic disc and fovea detection
- Diabetic retinopathy classification from geometric and chromatic features
- OCT (optical coherence tomography) analysis

### Dermatology

- Pigmented lesion segmentation over skin background
- Feature extraction for ABCD criteria (Asymmetry, Border, Colour, Diameter)
- Nevus/melanoma classification with SVM/ensemble classifiers

### Microscopy and digital pathology

- Automated cell counting (tissue microarray, smears)
- Nuclear segmentation
- Morphometric area and distribution measurement
- Reconstruction of _whole slide images_ from tiles

### Endoscopy

- Contrast and sharpness enhancement
- Polyp segmentation
- Artefact detection (bubbles, speculum)

### Movement analysis and physiotherapy

- Gait analysis with video marker tracking
- Postural analysis
- Rehabilitative movement study

## The typical flow

A clinical research project using OpenCV typically follows the pattern:

1. **Acquisition** — image in its original format (DICOM, TIFF, PNG, JPEG) loaded via specific library (e.g. DCMTK for DICOM) and converted into `IplImage` (C) or `cv::Mat` (C++ new API)
2. **Pre-processing** — enhancement, filtering, normalisation via OpenCV functions
3. **Feature extraction** — extraction of numerical descriptors (moments, texture, shape, colour)
4. **Classification or clustering** — with OpenCV algorithms or export to **WEKA** / **R** for more sophisticated analyses
5. **Validation** — cross-validation, ROC curves, comparison with clinician ground truth

Integration with existing research flows (MATLAB, R, Python) is supported by official **bindings**: Python (pycv), C# (emgucv), Java (javacv in development). The combination **OpenCV + Python + NumPy** is starting to spread as a MATLAB alternative in academic biomedical research.

## Limits for medical applications

OpenCV has specific limits when applied to medicine:

- **Non-volumetric** — 3D operations on CT/MR volumes are outside the natural scope; for those scenarios **ITK** is the appropriate tool
- **DICOM not native** — lacks an integrated DICOM parser; has to be used alongside DCMTK, GDCM, pixelmed
- **Numerical precision** — traditional focus is performance, not precision; some critical operations (sub-pixel registration, high-quality interpolation) require additional care
- **Regulatory certification** — the BSD licence permits use in commercial products but certification as a medical device component requires extensive qualification (IEC 62304 software lifecycle, risk management); must be planned from day one
- **Medical data variability** — absence of standardised acquisitions (protocols, different scanners, lighting conditions in endoscopy/dermatology) creates generalisation issues that go beyond the library

## The 2008 context

As of 2008 OpenCV is mid-transition:

- **Ownership change** from Intel to Willow Garage
- **C++ rewrite** under way, with a more idiomatic new API
- **Arrival of the C++ API** with `cv::Mat` as central structure (available in 2.0)
- **Binding growth** — the Python community is producing maintained wrappers
- **Integration with robotic platforms** like ROS (Robot Operating System), also in development at Willow Garage

For medical imaging, this means an evolving but stable library with a clear improvement trajectory. For those starting a research project in the coming months, the choice to stay on 1.x or migrate to 2.0 (when released) is a trade-off between immediate stability and future capabilities.

## Outlook

For medicine, OpenCV positions itself as a cross-cutting tool for pre-processing and classical feature extraction, complementary to specialised tools (ITK for 3D volumetric, dcm4che for DICOM, WEKA for tabular classification). The choice for a clinical project depends on image nature and the overall pipeline — not universal, but for the many non-volumetric 2D applications in medicine it is today the most mature and documented Open Source tool available.

Update — 2024

Development at Willow Garage leads to **OpenCV 2.0** (2009) with a modern C++ API based on `cv::Mat`. The arrival of deep learning frameworks from 2012 (AlexNet) changes how features are extracted from images, but OpenCV remains relevant for pre-processing, post-processing and lightweight deployment. The **Python binding** becomes the dominant way to use the library, with the **OpenCV + NumPy + scikit-learn** axis as the reference analytical stack in biomedical research.

---

_References: OpenCV (opencv.org), OpenCV 1.0 (October 2006), 1.1 in preparation 2008. Gary Bradski, Adrian Kaehler, _Learning OpenCV_ (O’Reilly, September 2008). BSD licence. Willow Garage as development sponsor from 2008. Viola-Jones face detection (2001)._
