Skip to content

Commit

Permalink
single-channel support
Browse files Browse the repository at this point in the history
  • Loading branch information
pme0 committed Jun 22, 2023
1 parent cca21d9 commit 02fcf70
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions deeplightning/viz/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def plot_resized_image(
resize: Tuple[int,int] = None,
display_image: bool = True,
display_size: Tuple[int,int] = None,
channel: int = None,
channel_cmap: str = None,
save_fp : str = None,
):
"""Plot resized image & saves with new exact pixel size.
Expand All @@ -26,8 +28,10 @@ def plot_resized_image(
display_size : size of displayed image, in inches (width, height)
save_fp : output image save filepath
"""
assert isinstance(resize, tuple) and len(resize) == 2

assert resize is None or isinstance(resize, tuple) and len(resize) == 2
if resize is None:
resize = imagesize.get(image_fp) #(w,h)

image = Image.open(image_fp)
image = image.convert('RGB')
image = image.resize(resize)
Expand All @@ -40,7 +44,12 @@ def plot_resized_image(

if display_image:
fig = plt.figure(figsize=display_size)
plt.imshow(new_image)
if channel is not None:
new_image = np.array(new_image)
#new_image[:,:,(channel!=0, channel!=1, channel!=2)] *= 0
new_image = new_image[:,:,channel]
new_image = Image.fromarray(new_image)
plt.imshow(new_image, cmap=channel_cmap)
plt.axis("off")
plt.show()

Expand Down

0 comments on commit 02fcf70

Please sign in to comment.