Flamingo¶

Code to import .npdi files and their annotations (in .ndpa files). The annotations in these files are typically saved in nanometers which cannot be converted to pixels without the use of Openslide. Using Openslide, a low resolution image can be exported and the pixel-based annotations scaled accordingly.

Import¶

 Installed via pip¶

In [ ]:
import sys
from flamingo.Flamingo import HE

Direct download¶

In [2]:
import sys
from src.flamingo.Flamingo import HE

Example 1¶

Using file test3-FITC 2 (485).ndpi. Please download the file and place in the example/ folder where the test annotations .ndpa file is stored.

Providing a resolution on initiation will automatically generate a low resolution image with one dimension equal to resolution and the other proportionally smaller. Annotations will be scaled to this new low res image size.

In [22]:
# File path and name
fp1 = 'example/'
fn1 = 'test3-FITC 2 (485).ndpi'

# Load file and scale automatically to 2000 pixels
ex1 = HE(fp1,fn1,resolution=2000)
pointer: this annotation type is not yet supported.
pin: this annotation type is not yet supported.
linearmeasure: this annotation type is not yet supported.

Plot the annotations¶

Annotations are plotted as an image mask adjacent to the low-res image. Each annoation is uniquely coloured, and overlapping annotations are considered void.

In [30]:
ex1.annotationPlot(type='combined')
In [33]:
ex1.annotationPlot(type='anno')

Export¶

The annotations coordinates (pixel basis) and the low-res image can be exported. Additionally, the image mask can also be exported.

  • type='json' : annotation labels and coordinates
  • type='image': low resolution image
  • type='mask' : masked image of size matching low res thumbnail
  • type='all' : all of the above
In [25]:
ex1.export(type='json',path='example/results/')

Example 2¶

Using file test3-DAPI 2 (387) .ndpi. Please download the file and place in the example/ folder where the test annotations .ndpa file is stored.

resolution is not specified, with the various methods worked through in turn.

In [13]:
fp2 = 'example/'
fn2 = 'test3-DAPI 2 (387) .ndpi'
ex2 = HE(fp2,fn2)

# Determine image properties: offsets from centre and the microns per pixel
ex2.imageProperties()

# Import the .ndpa file and parse annotations
ex2.annotationImport()

# Openslide's get_thumbail method
ex2.imageLoRes(resolution=1750)

# Convert annotations into an image mask matching the low res image size
ex2.annotationMask()

Plot¶

In [32]:
ex2.annotationPlot(type='combined')
In [31]:
ex2.annotationPlot(type='anno')

Export¶

In [35]:
ex2.export(type='json',path='example/results/')