Skip to content

Commit

Permalink
feat: allow png in tiling
Browse files Browse the repository at this point in the history
  • Loading branch information
duypham2108 committed Dec 28, 2023
1 parent 79700e0 commit e46f738
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ click>=8.0.4
leidenalg
louvain
numpy>=1.18,<1.22
numba<=0.57.1
Pillow>=9.0.1
scanpy>=1.8.2
scikit-image>=0.19.2
Expand Down
14 changes: 11 additions & 3 deletions stlearn/image_preprocessing/image_tiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def tiling(
library_id: Union[str, None] = None,
crop_size: int = 40,
target_size: int = 299,
img_fmt: str = "JPEG",
verbose: bool = False,
copy: bool = False,
) -> Optional[AnnData]:
Expand Down Expand Up @@ -80,15 +81,22 @@ def tiling(
tile.thumbnail((target_size, target_size), Image.Resampling.LANCZOS)
tile = tile.resize((target_size, target_size))
tile_name = str(imagecol) + "-" + str(imagerow) + "-" + str(crop_size)
out_tile = Path(out_path) / (tile_name + ".jpeg")
tile_names.append(str(out_tile))

if img_fmt == "JPEG":
out_tile = Path(out_path) / (tile_name + ".jpeg")
tile_names.append(str(out_tile))
tile.save(out_tile, "JPEG")
else:
out_tile = Path(out_path) / (tile_name + ".png")
tile_names.append(str(out_tile))
tile.save(out_tile, "PNG")

if verbose:
print(
"generate tile at location ({}, {})".format(
str(imagecol), str(imagerow)
)
)
tile.save(out_tile, "JPEG")

pbar.update(1)

Expand Down

0 comments on commit e46f738

Please sign in to comment.