Skip to content
Free whole slide image viewer – PMA.startFree whole slide image viewer – PMA.start
  • Home
  • Formats
  • Download
  • Plugins
  • Programming
    • Scripting
    • Image Analysis
    • API and SDKs
  • More stuff
    • Contact
    • Media
    • PMA.start wiki
    • RealData blog
    • Third party software credits

Fetching image snapshots from PMA.core.lite using Python

The following example uses Python 2.7 to connect to the locally installed instance of PMA.core.lite and downloads snapshots for all the images that exist in a directory of the system. Assuming that Python 2.7 is already installed in your system, the only other requirement to run the example is to install a SOAP client. Here we use suds which can be installed, if it’s not already, by issuing the following command at the command prompt:

pip install suds

PMA.core.lite runs at http://localhost:54001/. The WSDL definition of the SOAP API can be found at http://localhost:54001/api?WSDL

In order to fetch snapshots for all the images in a specific directory, we first have to get the list of images in that directory. Assuming that our slides reside in the directory C:Whole Slide Images, we can get the list by calling the GetFiles API method as follows:

from suds import WebFault
from suds.client import Client
import urllib
client = Client("http://localhost:54001/API?singleWsdl")
client.set_options(cache = None)
files = client.service.GetFiles(path = "C/Whole Slide Images") # notice how all back slashes have to be replaced by slashes and the colon (:) has to be removed from the path

Then, to fetch image information (such as width, height, resolution etc.) for any image, we have to call the GetImageInfo API method. Finally we can download a snapshot from the /region route, providing the required parameters. Here’s an example:

for i, filename in enumerate(files):
	info = client.service.GetImageInfo(filename)

	# Finally, to get the actual snapshot we have to decide the size of the output image. Suppose that we want to get a snapshot that is at most 1000 pixels wide or tall. We can do this like this:
	width = info.Width
	height = info.Height
	scale = 1.0

	# find the appropriate scale but also maintain aspect ratio
	if (width >= height):
		scale = 1000 / width
	else:
		scale = 1000 / height

	# build the url to get the image snapshot
	# parameters:
	# pathOrUid: the path of the image we want to retrieve
	# timeframe: the index of the timeframe we wish to load. Usually 0, unless we are dealing with images that contain time series.
	# layer: the index of the layer we wish to load. Usually 0, unless we are dealing with images that Z-stacks.
	# x: the top left pixel x coordinate of the image at which we want the snapshot to start at. This value is expressed in base level scale.
	# y: the top left pixel y coordinate of the image at which we want the snapshot to start at. This value is expressed in base level scale.
	# width: the width of the image we want to read. This value is expressed in base level scale.
	# height: the height of the image we want to read. This value is expressed in base level scale.
	# scale: the factor by which we want the width and height parameters to be scaled by. The resulting image will be width * scale pixels wide and height * scale pixels tall
	parameters = { 'pathOrUid' : filename, 'timeframe': 0, 'layer': 0 ,'x': 0,'y': 0, 'width': width, 'height': height, 'scale': scale }

	# we call the /region route with the appropriate parameters to fetch our image
	url = "http://localhost:54001/region?" + urllib.urlencode(parameters)

	# finally we can save it locally
	urllib.urlretrieve(url, "C:snapshots{0}.jpg".format(filename.split('/')[-1]))

Here you can download the source code in Python for making snapshots examples.

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

python SnapShooter.lite.py

FOLLOW

Digital pathology & microscopy solutions

CONTACT

Pathomation BV
Uitbreidingsstraat 66
2600 Berchem
Belgium
Email: info@pathomation.com
tel: +32 3 502 05 00
VAT no. BE 0500 694 204

 

Privacy Policy

By using our Software, you agree to the terms of our Privacy Policy.  
Copyright 2022 © Pathomation
  • Home
  • Formats
  • Download
  • Plugins
  • Programming
    • Scripting
    • Image Analysis
    • API and SDKs
  • More stuff
    • Contact
    • Media
    • PMA.start wiki
    • RealData blog
    • Third party software credits
  • WooCommerce not Found
  • Newsletter
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT