Skip to content

Commit

Permalink
draw does not modify the input image (#28)
Browse files Browse the repository at this point in the history
* make all methods that draw do not modify the input image
* add xmljson in setup.py
  • Loading branch information
fabiofumarola authored and jsbroks committed Jan 22, 2020
1 parent ae0441d commit eb493ff
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
19 changes: 12 additions & 7 deletions imantics/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, image=None, category=None, bbox=None, mask=None, polygons=Non
@property
def mask(self):
"""
:class:`Mask` repsentation of the annotations
:class:`Mask` representation of the annotations
"""
if not self._c_mask:

Expand Down Expand Up @@ -466,7 +466,9 @@ def draw(self, image, color=None, thickness=2):
:type thinkness: int
"""
color = Color.create(color).rgb
cv2.rectangle(image, self.min_point, self.max_point, color, thickness)
image_copy = image.copy()
cv2.rectangle(image_copy, self.min_point, self.max_point, color, thickness)
return image_copy

@property
def min_point(self):
Expand Down Expand Up @@ -710,7 +712,9 @@ def draw(self, image, color=None, thickness=3):
:type thinkness: int
"""
color = Color.create(color).rgb
cv2.polylines(image, self.points, True, color, thickness)
image_copy = image.copy()
cv2.polylines(image_copy, self.points, True, color, thickness)
return image_copy

def __eq__(self, other):
if isinstance(other, self.INSTANCE_TYPES):
Expand Down Expand Up @@ -879,13 +883,14 @@ def draw(self, image, color=None, alpha=0.5):
:type alpha: float
"""
color = Color.create(color).rgb
image_copy = image.copy()
for c in range(3):
image[:, :, c] = np.where(
image_copy[:, :, c] = np.where(
self.array,
image[:, :, c] * (1 - alpha) + alpha * color[c],
image[:, :, c]
image_copy[:, :, c] * (1 - alpha) + alpha * color[c],
image_copy[:, :, c]
)
return image
return image_copy

def subtract(self, other):
"""
Expand Down
6 changes: 2 additions & 4 deletions imantics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,8 @@ def __init__(self, image_array=None, annotations=[], path="", id=0, metadata={},

# Create empty image if not provided
if image_array is None:
self.height, self.width = (height,width)

self.height, self.width = (height, width)
else:

self.height, self.width, _ = image_array.shape

self.size = (self.width, self.height)
Expand All @@ -118,7 +116,7 @@ def __init__(self, image_array=None, annotations=[], path="", id=0, metadata={},

def add(self, annotation, category=None):
"""
Adds a annotaiton, list of annotaitons, mask, polygon or bbox to current image.
Adds an annotation, list of annotation, mask, polygon or bbox to current image.
If annotation is not a Annotation a category is required
List of non-Annotaiton objects will have the same category
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy
opencv-python
sphinx_rtd_theme
lxml
lxml
xmljson
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

setup(
name='imantics',
version='0.1.11',
version='0.1.12',
description='Python package for managing image annotations',
url='https://github.com/jsbroks/imantics',
author='Justin Brooks',
author_email='[email protected]',
long_description=long_description,
long_description_content_type="text/markdown",
license='MIT',
install_requires=['numpy', 'opencv-python>=3', 'lxml'],
install_requires=['numpy', 'opencv-python>=3', 'lxml', 'xmljson'],
packages=['imantics'],
python_requires='>=2.7',
zip_safe=False,
Expand Down

0 comments on commit eb493ff

Please sign in to comment.