Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Joon-June committed Jun 20, 2023
1 parent 960736c commit c5307bd
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
def tile():
pass
import os.path as osp
from math import ceil, sqrt
from typing import List, Tuple

import cv2
import numpy as np


def get_base_fn(fn: str):
return osp.basename(fn).split(".")[0]


def tile_images(paths: List[str], row_col: Tuple[int, int] = None, max_size: int = 10, image_size: int = 512):
if paths is None or len(paths) == 0:
return

num_images = len(paths)
if row_col is not None:
row, col = min(row_col[0], max_size), min(row_col[1], max_size)
else:
fitted_size = ceil(sqrt(num_images))
row, col = min(fitted_size, max_size), min(fitted_size, max_size)

def read_images(curr_paths: List[str]):
images = []
for p in curr_paths:
images.append(cv2.cvtColor(cv2.imread(p), cv2.COLOR_BGR2RGB))
return images

images = []
for i in range(row):
row_canvas = np.zeros((image_size, image_size*col, 3), dtype=np.uint8)
row_image = np.hstack(read_images(paths[i*col:(i+1)*col]))
row_canvas[:row_image.shape[0], :row_image.shape[1]] = row_image
images.append(row_canvas)
final_image = np.vstack(images)

return final_image

0 comments on commit c5307bd

Please sign in to comment.