imsegm.utilities.read_zvi module

https://searchcode.com/codesearch/view/40141634/

read ZVI (Zeiss) image file

  • incomplete support

  • open uncompressed image from multi item image (Count>0)

  • require OleFileIO_PL - a Python module to read MS OLE2 files http: //www.decalage.info/en/python/olefileio#attachments


>>> import os, sys
>>> sys.path += [os.path.abspath(os.path.join('..', '..'))]
>>> import imsegm.utilities.data_io as tl_io
>>> path_file = os.path.join('data-images', 'others', 'sample.zvi')
>>> path_file = tl_io.update_path(path_file)
>>> n = get_layer_count(path_file)
>>> get_dir(path_file) 
[...]
>>> for p in range(n):
...     zvi = zvi_read(path_file, p)
...     arr = zvi.Image.Array
...     arr.shape
(488, 648)
(488, 648)
(488, 648)
(488, 648)
>>> img = load_image(path_file)
>>> img.shape
(4, 488, 648)
class imsegm.utilities.read_zvi.ImageTuple(Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array)[source]

Bases: tuple

Create new instance of ImageTuple(Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array)

_asdict()[source]

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)[source]

Make a new ImageTuple object from a sequence or iterable

_replace(**kwds)[source]

Return a new ImageTuple object replacing specified fields with new values

property Array[source]

Alias for field number 7

property Depth[source]

Alias for field number 3

property Height[source]

Alias for field number 2

property PIXEL_FORMAT[source]

Alias for field number 5

property PixelWidth[source]

Alias for field number 4

property ValidBitsPerPixel[source]

Alias for field number 6

property Version[source]

Alias for field number 0

property Width[source]

Alias for field number 1

_fields = ('Version', 'Width', 'Height', 'Depth', 'PixelWidth', 'PIXEL_FORMAT', 'ValidBitsPerPixel', 'Array')[source]
_source = "from builtins import property as _property, tuple as _tuple\nfrom operator import itemgetter as _itemgetter\nfrom collections import OrderedDict\n\nclass ImageTuple(tuple):\n    'ImageTuple(Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array)'\n\n    __slots__ = ()\n\n    _fields = ('Version', 'Width', 'Height', 'Depth', 'PixelWidth', 'PIXEL_FORMAT', 'ValidBitsPerPixel', 'Array')\n\n    def __new__(_cls, Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array):\n        'Create new instance of ImageTuple(Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array)'\n        return _tuple.__new__(_cls, (Version, Width, Height, Depth, PixelWidth, PIXEL_FORMAT, ValidBitsPerPixel, Array))\n\n    @classmethod\n    def _make(cls, iterable, new=tuple.__new__, len=len):\n        'Make a new ImageTuple object from a sequence or iterable'\n        result = new(cls, iterable)\n        if len(result) != 8:\n            raise TypeError('Expected 8 arguments, got %d' % len(result))\n        return result\n\n    def _replace(_self, **kwds):\n        'Return a new ImageTuple object replacing specified fields with new values'\n        result = _self._make(map(kwds.pop, ('Version', 'Width', 'Height', 'Depth', 'PixelWidth', 'PIXEL_FORMAT', 'ValidBitsPerPixel', 'Array'), _self))\n        if kwds:\n            raise ValueError('Got unexpected field names: %r' % list(kwds))\n        return result\n\n    def __repr__(self):\n        'Return a nicely formatted representation string'\n        return self.__class__.__name__ + '(Version=%r, Width=%r, Height=%r, Depth=%r, PixelWidth=%r, PIXEL_FORMAT=%r, ValidBitsPerPixel=%r, Array=%r)' % self\n\n    def _asdict(self):\n        'Return a new OrderedDict which maps field names to their values.'\n        return OrderedDict(zip(self._fields, self))\n\n    def __getnewargs__(self):\n        'Return self as a plain tuple.  Used by copy and pickle.'\n        return tuple(self)\n\n    Version = _property(_itemgetter(0), doc='Alias for field number 0')\n\n    Width = _property(_itemgetter(1), doc='Alias for field number 1')\n\n    Height = _property(_itemgetter(2), doc='Alias for field number 2')\n\n    Depth = _property(_itemgetter(3), doc='Alias for field number 3')\n\n    PixelWidth = _property(_itemgetter(4), doc='Alias for field number 4')\n\n    PIXEL_FORMAT = _property(_itemgetter(5), doc='Alias for field number 5')\n\n    ValidBitsPerPixel = _property(_itemgetter(6), doc='Alias for field number 6')\n\n    Array = _property(_itemgetter(7), doc='Alias for field number 7')\n\n"[source]
class imsegm.utilities.read_zvi.ZviImageTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling)[source]

Bases: tuple

Create new instance of ZviImageTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling)

_asdict()[source]

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)[source]

Make a new ZviImageTuple object from a sequence or iterable

_replace(**kwds)[source]

Return a new ZviImageTuple object replacing specified fields with new values

property Count[source]

Alias for field number 6

property Depth[source]

Alias for field number 4

property FileName[source]

Alias for field number 1

property Height[source]

Alias for field number 3

property Layers[source]

Alias for field number 10

property Others[source]

Alias for field number 9

property PIXEL_FORMAT[source]

Alias for field number 5

property Scaling[source]

Alias for field number 11

property ValidBitsPerPixel[source]

Alias for field number 7

property Version[source]

Alias for field number 0

property Width[source]

Alias for field number 2

_fields = ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'm_PluginCLSID', 'Others', 'Layers', 'Scaling')[source]
_source = "from builtins import property as _property, tuple as _tuple\nfrom operator import itemgetter as _itemgetter\nfrom collections import OrderedDict\n\nclass ZviImageTuple(tuple):\n    'ZviImageTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling)'\n\n    __slots__ = ()\n\n    _fields = ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'm_PluginCLSID', 'Others', 'Layers', 'Scaling')\n\n    def __new__(_cls, Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling):\n        'Create new instance of ZviImageTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling)'\n        return _tuple.__new__(_cls, (Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, m_PluginCLSID, Others, Layers, Scaling))\n\n    @classmethod\n    def _make(cls, iterable, new=tuple.__new__, len=len):\n        'Make a new ZviImageTuple object from a sequence or iterable'\n        result = new(cls, iterable)\n        if len(result) != 12:\n            raise TypeError('Expected 12 arguments, got %d' % len(result))\n        return result\n\n    def _replace(_self, **kwds):\n        'Return a new ZviImageTuple object replacing specified fields with new values'\n        result = _self._make(map(kwds.pop, ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'm_PluginCLSID', 'Others', 'Layers', 'Scaling'), _self))\n        if kwds:\n            raise ValueError('Got unexpected field names: %r' % list(kwds))\n        return result\n\n    def __repr__(self):\n        'Return a nicely formatted representation string'\n        return self.__class__.__name__ + '(Version=%r, FileName=%r, Width=%r, Height=%r, Depth=%r, PIXEL_FORMAT=%r, Count=%r, ValidBitsPerPixel=%r, m_PluginCLSID=%r, Others=%r, Layers=%r, Scaling=%r)' % self\n\n    def _asdict(self):\n        'Return a new OrderedDict which maps field names to their values.'\n        return OrderedDict(zip(self._fields, self))\n\n    def __getnewargs__(self):\n        'Return self as a plain tuple.  Used by copy and pickle.'\n        return tuple(self)\n\n    Version = _property(_itemgetter(0), doc='Alias for field number 0')\n\n    FileName = _property(_itemgetter(1), doc='Alias for field number 1')\n\n    Width = _property(_itemgetter(2), doc='Alias for field number 2')\n\n    Height = _property(_itemgetter(3), doc='Alias for field number 3')\n\n    Depth = _property(_itemgetter(4), doc='Alias for field number 4')\n\n    PIXEL_FORMAT = _property(_itemgetter(5), doc='Alias for field number 5')\n\n    Count = _property(_itemgetter(6), doc='Alias for field number 6')\n\n    ValidBitsPerPixel = _property(_itemgetter(7), doc='Alias for field number 7')\n\n    m_PluginCLSID = _property(_itemgetter(8), doc='Alias for field number 8')\n\n    Others = _property(_itemgetter(9), doc='Alias for field number 9')\n\n    Layers = _property(_itemgetter(10), doc='Alias for field number 10')\n\n    Scaling = _property(_itemgetter(11), doc='Alias for field number 11')\n\n"[source]
property m_PluginCLSID[source]

Alias for field number 8

class imsegm.utilities.read_zvi.ZviItemTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image)[source]

Bases: tuple

Create new instance of ZviItemTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image)

_asdict()[source]

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable, new=<built-in method __new__ of type object>, len=<built-in function len>)[source]

Make a new ZviItemTuple object from a sequence or iterable

_replace(**kwds)[source]

Return a new ZviItemTuple object replacing specified fields with new values

property Count[source]

Alias for field number 6

property Depth[source]

Alias for field number 4

property FileName[source]

Alias for field number 1

property Height[source]

Alias for field number 3

property Image[source]

Alias for field number 11

property Layers[source]

Alias for field number 9

property Others[source]

Alias for field number 8

property PIXEL_FORMAT[source]

Alias for field number 5

property Scaling[source]

Alias for field number 10

property ValidBitsPerPixel[source]

Alias for field number 7

property Version[source]

Alias for field number 0

property Width[source]

Alias for field number 2

_fields = ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'Others', 'Layers', 'Scaling', 'Image')[source]
_source = "from builtins import property as _property, tuple as _tuple\nfrom operator import itemgetter as _itemgetter\nfrom collections import OrderedDict\n\nclass ZviItemTuple(tuple):\n    'ZviItemTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image)'\n\n    __slots__ = ()\n\n    _fields = ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'Others', 'Layers', 'Scaling', 'Image')\n\n    def __new__(_cls, Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image):\n        'Create new instance of ZviItemTuple(Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image)'\n        return _tuple.__new__(_cls, (Version, FileName, Width, Height, Depth, PIXEL_FORMAT, Count, ValidBitsPerPixel, Others, Layers, Scaling, Image))\n\n    @classmethod\n    def _make(cls, iterable, new=tuple.__new__, len=len):\n        'Make a new ZviItemTuple object from a sequence or iterable'\n        result = new(cls, iterable)\n        if len(result) != 12:\n            raise TypeError('Expected 12 arguments, got %d' % len(result))\n        return result\n\n    def _replace(_self, **kwds):\n        'Return a new ZviItemTuple object replacing specified fields with new values'\n        result = _self._make(map(kwds.pop, ('Version', 'FileName', 'Width', 'Height', 'Depth', 'PIXEL_FORMAT', 'Count', 'ValidBitsPerPixel', 'Others', 'Layers', 'Scaling', 'Image'), _self))\n        if kwds:\n            raise ValueError('Got unexpected field names: %r' % list(kwds))\n        return result\n\n    def __repr__(self):\n        'Return a nicely formatted representation string'\n        return self.__class__.__name__ + '(Version=%r, FileName=%r, Width=%r, Height=%r, Depth=%r, PIXEL_FORMAT=%r, Count=%r, ValidBitsPerPixel=%r, Others=%r, Layers=%r, Scaling=%r, Image=%r)' % self\n\n    def _asdict(self):\n        'Return a new OrderedDict which maps field names to their values.'\n        return OrderedDict(zip(self._fields, self))\n\n    def __getnewargs__(self):\n        'Return self as a plain tuple.  Used by copy and pickle.'\n        return tuple(self)\n\n    Version = _property(_itemgetter(0), doc='Alias for field number 0')\n\n    FileName = _property(_itemgetter(1), doc='Alias for field number 1')\n\n    Width = _property(_itemgetter(2), doc='Alias for field number 2')\n\n    Height = _property(_itemgetter(3), doc='Alias for field number 3')\n\n    Depth = _property(_itemgetter(4), doc='Alias for field number 4')\n\n    PIXEL_FORMAT = _property(_itemgetter(5), doc='Alias for field number 5')\n\n    Count = _property(_itemgetter(6), doc='Alias for field number 6')\n\n    ValidBitsPerPixel = _property(_itemgetter(7), doc='Alias for field number 7')\n\n    Others = _property(_itemgetter(8), doc='Alias for field number 8')\n\n    Layers = _property(_itemgetter(9), doc='Alias for field number 9')\n\n    Scaling = _property(_itemgetter(10), doc='Alias for field number 10')\n\n    Image = _property(_itemgetter(11), doc='Alias for field number 11')\n\n"[source]
imsegm.utilities.read_zvi.get_dir(file_name, ole=None)[source]

returns the content structure(streams) of the zvi file + length of each streams

imsegm.utilities.read_zvi.get_hex(data, n=16)[source]
imsegm.utilities.read_zvi.get_layer_count(file_name, ole=None)[source]

returns the number of image planes

imsegm.utilities.read_zvi.i32(data)[source]

return int32 from len4 string

imsegm.utilities.read_zvi.load_image(path_img)[source]
imsegm.utilities.read_zvi.parse_image(data)[source]

returns ImageTuple from raw image data(header+image)

imsegm.utilities.read_zvi.read_image_container_content(stream)[source]

returns a ZviImageTuple from a stream

imsegm.utilities.read_zvi.read_item_storage_content(stream)[source]

returns ZviItemTuple from the stream

imsegm.utilities.read_zvi.read_struct(data, t)[source]

read a t type from data(str)

imsegm.utilities.read_zvi.zvi_read(fname, plane, ole=None)[source]

returns ZviItemTuple of the plane from zvi file fname