Skip to content

Commit 302283e

Browse files
Docs
1 parent aca6319 commit 302283e

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/image_utils/im.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,16 +340,17 @@ def get_opencv(self):
340340

341341
@property
342342
def copy(self):
343+
"""Returns a deep copy of the image."""
343344
return copy.deepcopy(self)
344345

345346
@property
346347
def height(self):
347-
"""Returns the height of the image"""
348+
"""Returns the height of the image."""
348349
return self.image_shape[0]
349350

350351
@property
351352
def width(self):
352-
"""Returns the width of the image"""
353+
"""Returns the width of the image."""
353354
return self.image_shape[1]
354355

355356
@property
@@ -632,6 +633,7 @@ def concat_horizontal(*args, **kwargs) -> Im:
632633
return concat_variable(concat_horizontal_, *args, **kwargs)
633634

634635
def save_video(self, filepath: Optional[Path] = None, fps: int = 4, format="mp4", use_pyav: bool = False):
636+
"""Saves a video to disk. If filepath is not specified, the video will be saved to $CWD/outputs with a timestamp as the filename."""
635637
if filepath is None:
636638
filepath = Path(get_date_time_str())
637639

@@ -650,13 +652,16 @@ def save_video(self, filepath: Optional[Path] = None, fps: int = 4, format="mp4"
650652

651653
@_convert_to_datatype(desired_datatype=ndarray, desired_order=ChannelOrder.HWC, desired_range=ChannelRange.UINT8)
652654
def encode_video(self, fps: int, format="mp4") -> BytesIO:
653-
"""Encodes a batched image to a video."""
655+
"""Encodes a batched image to a video. Requires ImageIO."""
654656
assert len(self.arr.shape) == 4, "Video data must be 4D (time, height, width, channels)"
655657
byte_stream = BytesIO()
656658

657659
# TODO: We shouldn't need to write -> read. An imageio/ffmpeg issue is causing this.
658660
with tempfile.NamedTemporaryFile(suffix=f".{format}") as ntp:
659-
import imageio
661+
try:
662+
import imageio
663+
except ImportError:
664+
raise ImportError("ImageIO is required to encode videos. Please install it with `pip install imageio[ffmpeg]`.")
660665

661666
if format == "webm":
662667
writer = imageio.get_writer(ntp.name, format="webm", codec="libvpx-vp9", pixelformat="yuv420p", output_params=["-lossless", "1"], fps=fps) # type: ignore
@@ -740,6 +745,7 @@ def show(self):
740745

741746
@_convert_to_datatype(desired_datatype=Tensor, desired_order=ChannelOrder.HWC, desired_range=ChannelRange.UINT8)
742747
def bool_to_rgb(self) -> Im:
748+
"""Converts a boolean array to a RGB image (B / W)."""
743749
return self
744750

745751
pil = property(get_pil)

0 commit comments

Comments
 (0)