Package bar :: Module base :: Class barSlideRenderer
[hide private]
[frames] | no frames]

Class barSlideRenderer


Class holding all operation related to rasterizing SVG slides. It allows rasteizing whole slide, particular structures (by their names), or paths with given ID or belonging to particular structures.

Class has to be supplied with various parameters described better in class constructor. All rendered images are provided in form of PIL images.

Nested Classes [hide private]
Instance Methods [hide private]
 
__init__(self, vectorSlide, rendererConfiguration, tracingConfiguration, slideNumber=0)
Class requires providing following properties in order to work properly:
 
renderSlide(self, otype='pil')
An alias for self._renderSvgDrawing(self.getXMLelement(), otype=otype).
(float, float)
_toSVGCoordinates(self, ImageCoords)
Transform coordinates given in pixels (in image coordinate system) to coordinates in SVG drawing coordinate system (not spatial reference system).
(int, int)
_toImageCoordinates(self, svgCoords)
Convert coordinates from SVG image to coordinates in raster image system.
PIL.Image.Image or numpy.ndarray
_renderSvgDrawing(self, svgdoc, renderingSize=None, boundingBox=None, otype='pil', grayscale=True)
Renders provided SVG image with varioous options and returns rendered image.
 
values(self)
A stub of method.
(int, int)
__getSlideSize(self)
Getter for the self.size property.
 
__setSlideSize(self, newSize)
Setter for the self.size property.
(int, int)
__getBitmapSize(self)
Getter for the self.bitmapSize property
 
__setBitmapSize(self, newBitmapSize)
Setter for the self.bitmapSize property.

Inherited from barVectorSlide: Show, addLabel, affineTransform, alignToRefMatrix, deleteLabelByCaption, deleteLabelByID, getCommentLabels, getLabelByName, getRegularLabels, getSpotLabels, renameLabelByCaption, retypeLabelByCaption, srs2svg, svg2srs, updateMetadata

Inherited from barObject: __str__, getElementById, getXMLelement, writeXMLtoFile

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
Static Methods [hide private]

Inherited from barObject (private): _getAttributesDict

Instance Variables [hide private]

Inherited from barVectorSlide: slideNumber, slideTemplate

Inherited from barVectorSlide (private): _labels, _metadata

Properties [hide private]
(int, int) size
Get / set the CAF slide dimensions in pixels.
(int, int) bitmapSize
Get / set the size of the image that will be generated after invoking self.renderSlide.

Inherited from barVectorSlide: labelIndex, labels, metadata

Inherited from object: __class__

Method Details [hide private]

__init__(self, vectorSlide, rendererConfiguration, tracingConfiguration, slideNumber=0)
(Constructor)

 

Class requires providing following properties in order to work properly:

  • rendererConfiguration['ReferenceWidth']: (int) width of SVG drawing
  • rendererConfiguration['ReferenceHeight']: (int) height of SVG drawing
  • rendererConfiguration['imageSize'] : ((int, int)) size (width, height) of resulting bitmap image
Parameters:
  • rendererConfiguration ({str : ?, ...}) - renderer configuration (see module description for details)
  • tracingConfiguration ({str : ?, ...}) - tracing configuration (see module description for details)
  • slideNumber (int) - slide number
Overrides: object.__init__

_toSVGCoordinates(self, ImageCoords)

 

Transform coordinates given in pixels (in image coordinate system) to coordinates in SVG drawing coordinate system (not spatial reference system).

Parameters:
  • ImageCoords ((int, int)) - image coordinates to transform
Returns: (float, float)
coordinates transformed to SVG drawing coordinate system

_toImageCoordinates(self, svgCoords)

 

Convert coordinates from SVG image to coordinates in raster image system. By default, SVG drawings are rendered with 90 dpi resolution. In this resolution one point in SVG drawing is equivalent to one pixel of raster image. When SVG is rendered in larger resolution (we do not consider smaller resolutions in this software), coordinates has to be rescaled. Returned values are rounded to integers.

Parameters:
  • svgCoords ((int, int)) - coordinates in SVG drawing coordinates system
Returns: (int, int)
image coordinates corresponding to provided SVG coordinates

_renderSvgDrawing(self, svgdoc, renderingSize=None, boundingBox=None, otype='pil', grayscale=True)

 

Renders provided SVG image with varioous options and returns rendered image.

Workflow:

  1. Render image and convert it to NumPy array
  2. Manipulate channels and colours, convert to indexed mode
  3. Create and return PIL image

Availiable rendering protocols are:

  • 'pil' - returns PIL Image with rendered image,
  • 'npy' - returns NumPy array,
  • 'rec' - returns NumPy array rendered according to reconstruction module requirements
Parameters:
  • svgdoc (xml.dom.minidom.Document) - SVG document to render
  • renderingSize ((int, int)) - Dimensions (in pixels) of the rendered image, before an optional cropping.
  • boundingBox ((int, int, int, int)) - cropping coordinates (left, top, right, bottom); applies only to 'rec' protocol
  • otype (str) - requested rendering protocol - one of 'pil', 'npy', 'rec'
  • grayscale (bool) - determines if returned image would be in grayscale or RGB mode; applies only to 'pil' protocol
Returns: PIL.Image.Image or numpy.ndarray
rendered SVG image

To Do: Consider rewriting this method to staticmethod

values(self)

 

A stub of method. Raise NotImplementedError.

__getSlideSize(self)

 

Getter for the self.size property.

Returns: (int, int)
tuple with (width, height) of the slide.

__setSlideSize(self, newSize)

 

Setter for the self.size property.

Parameters:
  • newSize ((int, int)) - Dimensions of the SVG drawing in pixels

__getBitmapSize(self)

 

Getter for the self.bitmapSize property

Returns: (int, int)
Resolution of the rasterized slide in pixels

__setBitmapSize(self, newBitmapSize)

 

Setter for the self.bitmapSize property.

Parameters:
  • newBitmapSize ((int, int)) - resloution of the rasterized slide in pixels.

Property Details [hide private]

size

Get / set the CAF slide dimensions in pixels.

Get Method:
__getSlideSize(self) - Getter for the self.size property.
Set Method:
__setSlideSize(self, newSize) - Setter for the self.size property.
Type:
(int, int)

bitmapSize

Get / set the size of the image that will be generated after invoking self.renderSlide.

Get Method:
__getBitmapSize(self) - Getter for the self.bitmapSize property
Set Method:
__setBitmapSize(self, newBitmapSize) - Setter for the self.bitmapSize property.
Type:
(int, int)