Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
drop skimage dependency (#57)
Browse files Browse the repository at this point in the history
* drop dependency

* bump patch version and remove virtualenv dependency
  • Loading branch information
johnnv1 authored May 1, 2022
1 parent 90d2c89 commit 119a1a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
10 changes: 5 additions & 5 deletions CCAgT_utils/converters/CCAgT.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def single_core_to_PS_COCO(
if df['image_width'].nunique() == df['image_height'].nunique() == 1:
w = int(df['image_width'].unique()[0])
h = int(df['image_height'].unique()[0])
output_template = np.zeros((h, w, 3), dtype=np.uint8)
output_template = Image.fromarray(np.zeros((h, w, 3), dtype=np.uint8))
else:
output_template = None

Expand All @@ -532,15 +532,15 @@ def single_core_to_PS_COCO(

segments_info = []

if isinstance(output_template, np.ndarray):
if isinstance(output_template, Image.Image):
out = output_template.copy()
else:
w = int(df_by_img['image_width'].unique()[0])
h = int(df_by_img['image_height'].unique()[0])
out = np.zeros((h, w, 3), dtype=np.uint8)
out = Image.fromarray(np.zeros((h, w, 3), dtype=np.uint8))

for ann in annotations_sorted:
out = draw_annotation(out, ann, ann.color.rgb, out.shape[:2])
out = draw_annotation(out, ann, ann.color.rgb)
segments_info.append({
'id': COCO_PS.color_to_id(ann.color),
'category_id': ann.category_id,
Expand All @@ -555,7 +555,7 @@ def single_core_to_PS_COCO(
_out_dir = os.path.join(out_dir, df_by_img.iloc[0]['slide_id'])

output_filename = os.path.join(_out_dir, output_basename)
Image.fromarray(out).save(output_filename)
out.save(output_filename)
annotations_panoptic.append(panoptic_record)
return annotations_panoptic

Expand Down
19 changes: 9 additions & 10 deletions CCAgT_utils/converters/masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import collections

import numpy as np
from skimage.draw import polygon
from PIL import Image
from PIL import ImageDraw

from CCAgT_utils.categories import Categories
from CCAgT_utils.types.annotation import Annotation
Expand Down Expand Up @@ -39,23 +40,21 @@ def annotations_to_mask(

annotations_sorted = order_annotations_to_draw(annotations)

out = np.zeros(shape, dtype=np.uint8)
out = Image.fromarray(np.zeros(shape, dtype=np.uint8))
for ann in annotations_sorted:
out = draw_annotation(out, ann, ann.category_id, shape)
out = draw_annotation(out, ann, ann.category_id)

return Mask(out)
return Mask(np.array(out))


def draw_annotation(
target: np.ndarray,
target: Image.Image,
annotation: Annotation,
value: int | tuple[int, int, int],
shape: tuple[int, int] | None = None,
) -> np.ndarray:
) -> Image.Image:
for geo in annotation:
pol_x, pol_y = geo.exterior.coords.xy

_x, _y = polygon(pol_y, pol_x, shape)
target[_x, _y] = value
coords = list(zip(pol_x, pol_y))
ImageDraw.Draw(target).polygon(coords, fill=value)

return target
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = CCAgT_utils
version = 0.2.3-alpha
version = 0.2.4-alpha
description = A framework of utilities to help at the use of the CCAgT dataset
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down Expand Up @@ -29,9 +29,7 @@ install_requires =
pandas>=1.1.5
pillow>=9.0.1
pyarrow>=7.0.0
scikit-image>=0.19.2
shapely>=1.8.0
virtualenv>=20.0.8
python_requires = >=3.7

[options.packages.find]
Expand Down

0 comments on commit 119a1a1

Please sign in to comment.