Package bar :: Module parsers :: Class barBitmapParser
[hide private]
[frames] | no frames]

Class barBitmapParser


Generic bitmap parser for processing color encoded bitmaps and volumetric datasets. This generic class requires implementing several functions in order to make it fully functional parser:

  1. Generating source bitmap of the slide: _getSourceImage
  2. Creating black and white image mask: _createMask
  3. Getting 'z' coordinate for given slide: _getZCoord
  4. Getting spatial transformation martix for given slide: _getSpatialTransfMatrix
  5. Generating consecutive paths IDs: _getNewPathID
Instance Methods [hide private]
 
__init__(self, **kwargs)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
barTracedSlideRenderer
parse(self, slideNumber, generateLabels=True, useIndexer=True, writeSlide=True)
Returns: Traced slide with given slideNumber.
barTracedSlideRenderer
_getSlide(self, slideNumber)
Returns: Traced slide with given number.
SVG XML DOM object
_processStructure(self, sourceImage, imageColour)
Returns: DOM object holding SVG document created by tracing masked image generated by _parseTracerOutput.
[(int,int,int), ... ]
_getUniqeColours(self, sourceImage)
Returns: List of uniqe colours that were found in given image.
PIL image
_getSourceImage(self, slideNumber)
Returns: raw bitmap with slide slideNumber
PIL image
_createMask(self, image, colorValue)
Returns: Black and white image with structure mask.
float
_getZCoord(self, slideNumber)
Returns: Colonal ('z') coordinate of given slide.
(float a, float b, float c, float d)
_getSpatialTransfMatrix(self, slideNumber)
Returns: Creates set of parameters allowing to translate any image coordinate into spatial coordinate using the formula: x'=ax+b, y'=cy+d.
str
_getNewPathID(self, structName)
Returns: path id
 
_parseTracerOutput(self, tracerOutput, pathColour)
Change PoTrace SVG output in the way which will be usefull later:
barPath
_getPath(self, pathElem, structName, structFill)
Returns: Path object representing given structure.

Inherited from barGenericParser: RGBToHTMLColor, getProperty, parseAll, parseRange, reindex, setProperty, writeIndex

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

Class Variables [hide private]
list _requiredInternalData = ['outputDirectory', 'filenameTemplates...
Required instance attributtes.
Instance Variables [hide private]
dict imageToStructure
Dictionary holding image colour (key) to structure abbrevation (value) translation.
dict structureColours
Dictionary holding structure abbreviations (keys) and translating them into path colous in CAF traced file (values).

Inherited from barGenericParser: filenameTemplates, outputDirectory, renderingProperties, slideRange, tracingProperties

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, **kwargs)
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Overrides: object.__init__
(inherited documentation)

parse(self, slideNumber, generateLabels=True, useIndexer=True, writeSlide=True)

 
Parameters:
  • slideNumber - Number of slide to parse
Returns: barTracedSlideRenderer
Traced slide with given slideNumber.

Performs all operation related to creating CAF slide from souce data. Should be customized in each parser.

Overrides: barGenericParser.parse
(inherited documentation)

_getSlide(self, slideNumber)

 
Parameters:
  • slideNumber (int) - Number of slide to extract
Returns: barTracedSlideRenderer
Traced slide with given number.

_processStructure(self, sourceImage, imageColour)

 
Parameters:
  • sourceImage (PIL image) - raw image from file or volumetric dataset
  • imageColour ((int,int,int)) - colour tuple in r,g,b format. All pixels with that colour will be extracted and consideres as pixels representing given stucture.
Returns: SVG XML DOM object
DOM object holding SVG document created by tracing masked image generated by _parseTracerOutput.

_getUniqeColours(self, sourceImage)

 
Parameters:
  • sourceImage (PIL image) - Image in RGB
Returns: [(int,int,int), ... ]
List of uniqe colours that were found in given image.

To Do: Check if image is in RGB mode

_getSourceImage(self, slideNumber)

 
Parameters:
  • slideNumber (int) - number of slide to process.
Returns: PIL image
raw bitmap with slide slideNumber

Note: this is Virtual method and should be custimized in subclasess.

Generated raw bitmap slide for further processing.

_createMask(self, image, colorValue)

 
Parameters:
  • image (PIL image) - Image basing on which mask will be created.
  • colorValue (str) - Colour in '#%x%x%x' format
Returns: PIL image
Black and white image with structure mask.

Note: this is Virtual method and should be custimized in subclasess.

Creates black & white mask of given slide using provided colour. All pixels with given colour are changed to black while all other pixels are turned into white. Note that image mode is not binary but still indexed (holds 256 colours not 2).

_getZCoord(self, slideNumber)

 
Parameters:
  • slideNumber (int) - number of slide to process.
Returns: float
Colonal ('z') coordinate of given slide.

Note: this is Virtual method and should be custimized in subclasess.

_getSpatialTransfMatrix(self, slideNumber)

 
Parameters:
  • slideNumber (int) - number of slide to process.
Returns: (float a, float b, float c, float d)
Creates set of parameters allowing to translate any image coordinate into spatial coordinate using the formula: x'=ax+b, y'=cy+d.

Note: this is Virtual method and should be custimized in subclasess.

_getNewPathID(self, structName)

 
Parameters:
  • structName (string) - Name of the structure that will be represented by given path.
Returns: str
path id

Note: this is Virtual method and should be custimized in subclasess.

Builds id of new path representing provided structure using internal path indexing.

_parseTracerOutput(self, tracerOutput, pathColour)

 

Change PoTrace SVG output in the way which will be usefull later:

  1. Creates DOM structure from PoTrace SVG output
  2. Creates single path segments instead of long bezier paths
  3. Converts path coordinates to absolute
  4. Reduces transformation rules (using my own svgfix module :)
Parameters:
  • pathColour (str) - Colour in '#%x%x%x' format
  • tracerOutput (string) - PoTrace SVG output string
Returns:
SVG XML DOM stucture generated from PoTrace SVG output string.

_getPath(self, pathElem, structName, structFill)

 
Parameters:
  • pathElem (DOM object) - SVG path element to process
  • structName (str) - Name of the structure
  • structFill (str) - Colour in '#%x%x%x' format
Returns: barPath
Path object representing given structure.

Creates barPath element representing given stucture.


Class Variable Details [hide private]

_requiredInternalData

Required instance attributtes. Without prividing them parsing cannot be invoked. Meaning of each attribute is explained below.
Type:
list
Value:
['outputDirectory',
 'filenameTemplates',
 'slideRange',
 'tracingProperties',
 'renderingProperties',
 'imageToStructure',
 'structureColours',
 'backgroundColor']

Instance Variable Details [hide private]

imageToStructure

Dictionary holding image colour (key) to structure abbrevation (value) translation. Used for decoding source image colours to th structures names.
Type:
dict