Using OpenCV to calculate the edges of the tissue on a slide

This tutorial applies to Python 2.7.

As shown elsewhere on this site, we can fetch snapshots of any size from PMA.core.lite. Once we have a snapshot we can further process it with OpenCV for example to calculate the boundaries of the tissue.
In order to run this example the following libraries need to be installed along with Python 2.7:

  • numpy
  • matplotlib
  • opencv

Windows users can download these binaries as .whl files from here:

Once the correct whl files have been downloaded they can be installed using pip.

The steps to calculate the contours for the tissue in a whole slide image, presented in this example are:

  1. Fetch an image snaposhot from PMA.core.lite (as illustrated in the snapshot example above)
  2. Convert the image’s color space from RGB to HSV
  3. Perform a gaussian blur
  4. Calculate a threshold value to convert the image to black & white using Otsu’s method
  5. Find the contours using OpenCV
  6. Plot the contours on top of the image

Example output

Digital slide image analysis

Digital slide image analysis

Here you can download the source code in Python for the image analysis examples.

To run the examples modify the code accordingly to point to a directory in your system that contains whole slide images and issue: