Encoded API¶
This feature is only possible since PyTango 7.1.4
-
class
PyTango.
EncodedAttribute
¶ -
decode_gray16
(da, extract_as=PyTango._PyTango.ExtractAs.Numpy)¶ Decode a 16 bits grayscale image (GRAY16) and returns a 16 bits gray scale image.
param da: DeviceAttribute
that contains the imagetype da: DeviceAttribute
param extract_as: defaults to ExtractAs.Numpy type extract_as: ExtractAs return: the decoded data - In case String string is choosen as extract method, a tuple is returned:
width<int>, height<int>, buffer<str>
In case Numpy is choosen as extract method, a
numpy.ndarray
is returned with ndim=2, shape=(height, width) and dtype=numpy.uint16.In case Tuple or List are choosen, a tuple<tuple<int>> or list<list<int>> is returned.
Warning
The PyTango calls that return a
DeviceAttribute
(likeDeviceProxy.read_attribute()
orDeviceProxy.command_inout()
) automatically extract the contents by default. This method requires that the givenDeviceAttribute
is obtained from a call which DOESN’T extract the contents. Example:dev = PyTango.DeviceProxy("a/b/c") da = dev.read_attribute("my_attr", extract_as=PyTango.ExtractAs.Nothing) enc = PyTango.EncodedAttribute() data = enc.decode_gray16(da)
-
decode_gray8
(da, extract_as=PyTango._PyTango.ExtractAs.Numpy)¶ Decode a 8 bits grayscale image (JPEG_GRAY8 or GRAY8) and returns a 8 bits gray scale image.
param da: DeviceAttribute
that contains the imagetype da: DeviceAttribute
param extract_as: defaults to ExtractAs.Numpy type extract_as: ExtractAs return: the decoded data - In case String string is choosen as extract method, a tuple is returned:
width<int>, height<int>, buffer<str>
In case Numpy is choosen as extract method, a
numpy.ndarray
is returned with ndim=2, shape=(height, width) and dtype=numpy.uint8.In case Tuple or List are choosen, a tuple<tuple<int>> or list<list<int>> is returned.
Warning
The PyTango calls that return a
DeviceAttribute
(likeDeviceProxy.read_attribute()
orDeviceProxy.command_inout()
) automatically extract the contents by default. This method requires that the givenDeviceAttribute
is obtained from a call which DOESN’T extract the contents. Example:dev = PyTango.DeviceProxy("a/b/c") da = dev.read_attribute("my_attr", extract_as=PyTango.ExtractAs.Nothing) enc = PyTango.EncodedAttribute() data = enc.decode_gray8(da)
-
decode_rgb32
(da, extract_as=PyTango._PyTango.ExtractAs.Numpy)¶ Decode a color image (JPEG_RGB or RGB24) and returns a 32 bits RGB image.
param da: DeviceAttribute
that contains the imagetype da: DeviceAttribute
param extract_as: defaults to ExtractAs.Numpy type extract_as: ExtractAs return: the decoded data - In case String string is choosen as extract method, a tuple is returned:
width<int>, height<int>, buffer<str>
In case Numpy is choosen as extract method, a
numpy.ndarray
is returned with ndim=2, shape=(height, width) and dtype=numpy.uint32.In case Tuple or List are choosen, a tuple<tuple<int>> or list<list<int>> is returned.
Warning
The PyTango calls that return a
DeviceAttribute
(likeDeviceProxy.read_attribute()
orDeviceProxy.command_inout()
) automatically extract the contents by default. This method requires that the givenDeviceAttribute
is obtained from a call which DOESN’T extract the contents. Example:dev = PyTango.DeviceProxy("a/b/c") da = dev.read_attribute("my_attr", extract_as=PyTango.ExtractAs.Nothing) enc = PyTango.EncodedAttribute() data = enc.decode_rgb32(da)
-
encode_gray16
(gray16, width=0, height=0)¶ Encode a 16 bit grayscale image (no compression)
param gray16: an object containning image information type gray16: str
orbuffer
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if gray16 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if gray16 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type height: int
Note
When
numpy.ndarray
is given:- gray16 MUST be CONTIGUOUS, ALIGNED
- if gray16.ndims != 2, width and height MUST be given and gray16.nbytes/2 MUST match width*height
- if gray16.ndims == 2, gray16.itemsize MUST be 2 (typically, gray16.dtype is one of numpy.dtype.int16, numpy.dtype.uint16, numpy.dtype.short or numpy.dtype.ushort)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() data = numpy.arange(100, dtype=numpy.int16) data = numpy.array((data,data,data)) enc.encode_gray16(data) attr.set_value(enc)
-
encode_gray8
(gray8, width=0, height=0)¶ Encode a 8 bit grayscale image (no compression)
param gray8: an object containning image information type gray8: str
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if gray8 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if gray8 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type height: int
Note
When
numpy.ndarray
is given:- gray8 MUST be CONTIGUOUS, ALIGNED
- if gray8.ndims != 2, width and height MUST be given and gray8.nbytes MUST match width*height
- if gray8.ndims == 2, gray8.itemsize MUST be 1 (typically, gray8.dtype is one of numpy.dtype.byte, numpy.dtype.ubyte, numpy.dtype.int8 or numpy.dtype.uint8)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() data = numpy.arange(100, dtype=numpy.byte) data = numpy.array((data,data,data)) enc.encode_gray8(data) attr.set_value(enc)
-
encode_jpeg_gray8
(gray8, width=0, height=0, quality=100.0)¶ Encode a 8 bit grayscale image as JPEG format
param gray8: an object containning image information type gray8: str
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if gray8 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if gray8 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type height: int
param quality: Quality of JPEG (0=poor quality 100=max quality) (default is 100.0) type quality: float
Note
When
numpy.ndarray
is given:- gray8 MUST be CONTIGUOUS, ALIGNED
- if gray8.ndims != 2, width and height MUST be given and gray8.nbytes MUST match width*height
- if gray8.ndims == 2, gray8.itemsize MUST be 1 (typically, gray8.dtype is one of numpy.dtype.byte, numpy.dtype.ubyte, numpy.dtype.int8 or numpy.dtype.uint8)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() data = numpy.arange(100, dtype=numpy.byte) data = numpy.array((data,data,data)) enc.encode_jpeg_gray8(data) attr.set_value(enc)
-
encode_jpeg_rgb24
(rgb24, width=0, height=0, quality=100.0)¶ Encode a 24 bit rgb color image as JPEG format.
param rgb24: an object containning image information type rgb24: str
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if rgb24 is a string or if it is a numpy.ndarray
with ndims != 3. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if rgb24 is a string or if it is a numpy.ndarray
with ndims != 3. Otherwise it is calculated internally.type height: int
param quality: Quality of JPEG (0=poor quality 100=max quality) (default is 100.0) type quality: float
Note
When
numpy.ndarray
is given:- rgb24 MUST be CONTIGUOUS, ALIGNED
- if rgb24.ndims != 3, width and height MUST be given and rgb24.nbytes/3 MUST match width*height
- if rgb24.ndims == 3, rgb24.itemsize MUST be 1 (typically, rgb24.dtype is one of numpy.dtype.byte, numpy.dtype.ubyte, numpy.dtype.int8 or numpy.dtype.uint8) and shape MUST be (height, width, 3)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() # create an 'image' where each pixel is R=0x01, G=0x01, B=0x01 arr = numpy.ones((10,10,3), dtype=numpy.uint8) enc.encode_jpeg_rgb24(data) attr.set_value(enc)
-
encode_jpeg_rgb32
(rgb32, width=0, height=0, quality=100.0)¶ Encode a 32 bit rgb color image as JPEG format.
param rgb32: an object containning image information type rgb32: str
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if rgb32 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if rgb32 is a string or if it is a numpy.ndarray
with ndims != 2. Otherwise it is calculated internally.type height: int
Note
When
numpy.ndarray
is given:- rgb32 MUST be CONTIGUOUS, ALIGNED
- if rgb32.ndims != 2, width and height MUST be given and rgb32.nbytes/4 MUST match width*height
- if rgb32.ndims == 2, rgb32.itemsize MUST be 4 (typically, rgb32.dtype is one of numpy.dtype.int32, numpy.dtype.uint32)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() data = numpy.arange(100, dtype=numpy.int32) data = numpy.array((data,data,data)) enc.encode_jpeg_rgb32(data) attr.set_value(enc)
-
encode_rgb24
(rgb24, width=0, height=0)¶ Encode a 24 bit color image (no compression)
param rgb24: an object containning image information type rgb24: str
ornumpy.ndarray
or seq< seq<element> >param width: image width. MUST be given if rgb24 is a string or if it is a numpy.ndarray
with ndims != 3. Otherwise it is calculated internally.type width: int
param height: image height. MUST be given if rgb24 is a string or if it is a numpy.ndarray
with ndims != 3. Otherwise it is calculated internally.type height: int
Note
When
numpy.ndarray
is given:- rgb24 MUST be CONTIGUOUS, ALIGNED
- if rgb24.ndims != 3, width and height MUST be given and rgb24.nbytes/3 MUST match width*height
- if rgb24.ndims == 3, rgb24.itemsize MUST be 1 (typically, rgb24.dtype is one of numpy.dtype.byte, numpy.dtype.ubyte, numpy.dtype.int8 or numpy.dtype.uint8) and shape MUST be (height, width, 3)
Example: :
def read_myattr(self, attr): enc = PyTango.EncodedAttribute() # create an 'image' where each pixel is R=0x01, G=0x01, B=0x01 arr = numpy.ones((10,10,3), dtype=numpy.uint8) enc.encode_rgb24(data) attr.set_value(enc)
-