Skip to content

Commit

Permalink
Fix the confusion of cval and border in tile()
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed Apr 29, 2020
1 parent 86eab26 commit 5dba63b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Binary file modified .readme/getting_started.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 18 additions & 11 deletions imgviz/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def tile(
if shape is None:
shape = _get_tile_shape(len(imgs), hw_ratio=1.0 * max_h / max_w)

if cval is None:
cval = 0

if border is not None:
border = np.asarray(border, dtype=np.uint8)

Expand All @@ -94,17 +97,21 @@ def tile(
assert channel in [3, 4]

# tile images
for i, img in enumerate(imgs):
assert img.dtype == np.uint8

if ndim == 3 and img.ndim == 2:
img = gray2rgb(img)
if channel == 4 and img.shape[2] == 3:
img = rgb2rgba(img)

img = centerize(src=img, shape=(max_h, max_w, channel), cval=cval)

imgs[i] = img
for i in range(shape[0] * shape[1]):
if i < len(imgs):
img = imgs[i]
assert img.dtype == np.uint8

if ndim == 3 and img.ndim == 2:
img = gray2rgb(img)
if channel == 4 and img.shape[2] == 3:
img = rgb2rgba(img)

img = centerize(src=img, shape=(max_h, max_w, channel), cval=cval)
imgs[i] = img
else:
img = np.full((max_h, max_w, channel), cval, dtype=np.uint8)
imgs.append(img)

return _tile(
imgs=imgs, shape=shape, border=border, border_width=border_width
Expand Down

0 comments on commit 5dba63b

Please sign in to comment.