Coretex
coretex.coretex.annotation.image.coretex_format.CoretexImageAnnotation Class Reference
Inheritance diagram for coretex.coretex.annotation.image.coretex_format.CoretexImageAnnotation:
coretex.codable.codable.Codable

Public Member Functions

Self create (cls, str name, float width, float height, List[CoretexSegmentationInstance] instances)
 
np.ndarray extractSegmentationMask (self, ImageDatasetClasses classes)
 
- Public Member Functions inherited from coretex.codable.codable.Codable
Dict[str, Any] encode (self)
 
None onDecode (self)
 
Self decode (cls, Dict[str, Any] encodedObject)
 

Detailed Description

    Image Annotation class

    Properties
    ----------
    name : str
        name of annotation class
    width : float
        width of annotation
    height : float
        height of annotation
    instances : List[CoretexSegmentationInstance]
        list of SegmentationInstance objects

Definition at line 232 of file coretex_format.py.

Member Function Documentation

◆ create()

Self coretex.coretex.annotation.image.coretex_format.CoretexImageAnnotation.create (   cls,
str  name,
float  width,
float  height,
List[CoretexSegmentationInstance]   instances 
)
    Creates CoretexImageAnnotation object with provided parameters

    Parameters
    ----------
    name : str
name of annotation class
    width : float
width of annotation
    height : float
height of annotation
    instances : List[CoretexSegmentationInstance]
list of SegmentationInstance objects

    Returns
    -------
    The created CoretexImageAnnotation object

Definition at line 262 of file coretex_format.py.

262  def create(
263  cls,
264  name: str,
265  width: float,
266  height: float,
267  instances: List[CoretexSegmentationInstance]
268  ) -> Self:
269  """
270  Creates CoretexImageAnnotation object with provided parameters
271 
272  Parameters
273  ----------
274  name : str
275  name of annotation class
276  width : float
277  width of annotation
278  height : float
279  height of annotation
280  instances : List[CoretexSegmentationInstance]
281  list of SegmentationInstance objects
282 
283  Returns
284  -------
285  The created CoretexImageAnnotation object
286  """
287 
288  obj = cls()
289 
290  obj.name = name
291  obj.width = width
292  obj.height = height
293  obj.instances = instances
294 
295  return obj
296 

◆ extractSegmentationMask()

np.ndarray coretex.coretex.annotation.image.coretex_format.CoretexImageAnnotation.extractSegmentationMask (   self,
ImageDatasetClasses  classes 
)
    Generates segmentation mask of provided ImageDatasetClasses object

    Parameters
    ----------
    classes : ImageDatasetClasses
list of dataset classes

    Returns
    -------
    np.ndarray -> segmentation mask represented as np.ndarray

Definition at line 297 of file coretex_format.py.

297  def extractSegmentationMask(self, classes: ImageDatasetClasses) -> np.ndarray:
298  """
299  Generates segmentation mask of provided ImageDatasetClasses object
300 
301  Parameters
302  ----------
303  classes : ImageDatasetClasses
304  list of dataset classes
305 
306  Returns
307  -------
308  np.ndarray -> segmentation mask represented as np.ndarray
309  """
310 
311  image = Image.new("L", (self.width, self.height))
312 
313  for instance in self.instances:
314  labelId = classes.labelIdForClassId(instance.classId)
315  if labelId is None:
316  continue
317 
318  for segmentation in instance.segmentations:
319  if len(segmentation) == 0:
320  raise ValueError(f">> [Coretex] Empty segmentation")
321 
322  draw = ImageDraw.Draw(image)
323  draw.polygon(toPoly(segmentation), fill = labelId + 1)
324 
325  return np.asarray(image)

The documentation for this class was generated from the following file: