|
Self | create (cls, UUID classId, BBox bbox, List[SegmentationType] segmentations) |
|
np.ndarray | extractSegmentationMask (self, int width, int height) |
|
np.ndarray | extractBinaryMask (self, int width, int height) |
|
Tuple[float, float] | centroid (self) |
|
None | centerSegmentations (self, Tuple[float, float] newCentroid) |
|
None | rotateSegmentations (self, int degrees) |
|
Dict[str, Any] | encode (self) |
|
None | onDecode (self) |
|
Self | decode (cls, Dict[str, Any] encodedObject) |
|
Segmentation Instance class
Properties
----------
classID : UUID
uuid of class
bbox : BBox
Bounding Box as a python class
segmentations : List[SegmentationType]
list of segmentations that define the precise boundaries of object
Definition at line 44 of file coretex_format.py.
◆ centerSegmentations()
None coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.centerSegmentations |
( |
|
self, |
|
|
Tuple[float, float] |
newCentroid |
|
) |
| |
Centers segmentations to the specified center point
Parameters
----------
newCentroid : Tuple[float, float]
x, y coordinates of centroid
Definition at line 167 of file coretex_format.py.
167 def centerSegmentations(self, newCentroid: Tuple[float, float]) ->
None:
169 Centers segmentations to the specified center point
173 newCentroid : Tuple[float, float]
174 x, y coordinates of centroid
177 newCenterX, newCenterY = newCentroid
178 oldCenterX, oldCenterY = self.centroid()
180 modifiedSegmentations: List[List[float]] = []
182 for segmentation
in self.segmentations:
183 modifiedSegmentation: List[float] = []
185 for i
in range(0, len(segmentation), 2):
186 x = segmentation[i] + (newCenterX - oldCenterX)
187 y = segmentation[i+1] + (newCenterY - oldCenterY)
189 modifiedSegmentation.append(x)
190 modifiedSegmentation.append(y)
192 modifiedSegmentations.append(modifiedSegmentation)
194 self.segmentations = modifiedSegmentations
◆ centroid()
Tuple[float, float] coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.centroid |
( |
|
self | ) |
|
Calculates centroid of segmentations
Returns
-------
Tuple[float, float] -> x, y coordinates of centroid
Definition at line 148 of file coretex_format.py.
148 def centroid(self) -> Tuple[float, float]:
150 Calculates centroid of segmentations
154 Tuple[float, float] -> x, y coordinates of centroid
157 flattenedSegmentations = [element
for sublist
in self.segmentations
for element
in sublist]
159 listCX = [value
for index, value
in enumerate(flattenedSegmentations)
if index % 2 == 0]
160 centerX = fsum(listCX) / len(listCX)
162 listCY = [value
for index, value
in enumerate(flattenedSegmentations)
if index % 2 != 0]
163 centerY = fsum(listCY) / len(listCY)
165 return centerX, centerY
◆ create()
Self coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.create |
( |
|
cls, |
|
|
UUID |
classId, |
|
|
BBox |
bbox, |
|
|
List[SegmentationType] |
segmentations |
|
) |
| |
Creates CoretexSegmentationInstance object with provided parameters
Parameters
----------
classID : UUID
uuid of class
bbox : BBox
Bounding Box as a python class
segmentations : List[SegmentationType]
list of segmentations that define the precise boundaries of object
Returns
-------
The created CoretexSegmentationInstance object
Definition at line 74 of file coretex_format.py.
74 def create(cls, classId: UUID, bbox: BBox, segmentations: List[SegmentationType]) -> Self:
76 Creates CoretexSegmentationInstance object with provided parameters
83 Bounding Box as a python class
84 segmentations : List[SegmentationType]
85 list of segmentations that define the precise boundaries of object
89 The created CoretexSegmentationInstance object
96 obj.segmentations = segmentations
◆ extractBinaryMask()
np.ndarray coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.extractBinaryMask |
( |
|
self, |
|
|
int |
width, |
|
|
int |
height |
|
) |
| |
Works the same way as extractSegmentationMask function
Values that are > 0 are capped to 1
Parameters
----------
width : int
width of image in pixels
height : int
height of image in pixels
Returns
-------
np.ndarray -> binary segmentation mask represented as np.ndarray
Definition at line 126 of file coretex_format.py.
126 def extractBinaryMask(self, width: int, height: int) -> np.ndarray:
128 Works the same way as extractSegmentationMask function
129 Values that are > 0 are capped to 1
134 width of image in pixels
136 height of image in pixels
140 np.ndarray -> binary segmentation mask represented as np.ndarray
143 binaryMask = self.extractSegmentationMask(width, height)
144 binaryMask[binaryMask > 0] = 1
◆ extractSegmentationMask()
np.ndarray coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.extractSegmentationMask |
( |
|
self, |
|
|
int |
width, |
|
|
int |
height |
|
) |
| |
Generates segmentation mask based on provided
width and height of image\n
Pixel values are equal to class IDs
Parameters
----------
width : int
width of image in pixels
height : int
height of image in pixels
Returns
-------
np.ndarray -> segmentation mask represented as np.ndarray
Definition at line 100 of file coretex_format.py.
100 def extractSegmentationMask(self, width: int, height: int) -> np.ndarray:
102 Generates segmentation mask based on provided
103 width and height of image\n
104 Pixel values are equal to class IDs
109 width of image in pixels
111 height of image in pixels
115 np.ndarray -> segmentation mask represented as np.ndarray
118 image = Image.new(
"L", (width, height))
120 for segmentation
in self.segmentations:
121 draw = ImageDraw.Draw(image)
122 draw.polygon(toPoly(segmentation), fill = 1)
124 return np.asarray(image)
◆ rotateSegmentations()
None coretex.coretex.annotation.image.coretex_format.CoretexSegmentationInstance.rotateSegmentations |
( |
|
self, |
|
|
int |
degrees |
|
) |
| |
Rotates segmentations of CoretexSegmentationInstance object
Parameters
----------
degrees : int
degree of rotation
Definition at line 196 of file coretex_format.py.
196 def rotateSegmentations(self, degrees: int) ->
None:
198 Rotates segmentations of CoretexSegmentationInstance object
206 rotatedSegmentations: List[List[float]] = []
207 centerX, centerY = self.centroid()
211 theta = radians(-degrees)
212 cosang, sinang = cos(theta), sin(theta)
214 for segmentation
in self.segmentations:
215 rotatedSegmentation: List[float] = []
217 for i
in range(0, len(segmentation), 2):
218 x = segmentation[i] - centerX
219 y = segmentation[i + 1] - centerY
221 newX = (x * cosang - y * sinang) + centerX
222 newY = (x * sinang + y * cosang) + centerY
224 rotatedSegmentation.append(newX)
225 rotatedSegmentation.append(newY)
227 rotatedSegmentations.append(rotatedSegmentation)
229 self.segmentations = rotatedSegmentations
The documentation for this class was generated from the following file: