Skip to content

Commit

Permalink
Interface each processing method with pydantic models
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Dec 10, 2024
1 parent fa9a036 commit 3bbab4d
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 81 deletions.
6 changes: 3 additions & 3 deletions miniscope_io/data/config/process/denoise_example.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
interactive_display:
enable: True
start_frame: 40
end_frame: 90
end_frame: 140
noise_patch:
enable: True
method: "mean_error"
threshold: 30
threshold: 10
buffer_size: 5032
buffer_split: 10
diff_multiply: 1
Expand All @@ -14,7 +14,7 @@ noise_patch:
output_diff: True
frequency_masking:
enable: True
spatial_LPF_cutoff_radius: 15
spatial_LPF_cutoff_radius: 20
vertical_BEF_cutoff: 2
horizontal_BEF_cutoff: 0
display_mask: False
Expand Down
15 changes: 9 additions & 6 deletions miniscope_io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import contextlib
import csv
from pathlib import Path
from typing import Any, BinaryIO, Iterator, List, Literal, Optional, Union, overload
from typing import Any, BinaryIO, Iterator, List, Literal, Optional, Tuple, Union, overload

import cv2
import numpy as np
Expand Down Expand Up @@ -92,19 +92,22 @@ def __init__(self, video_path: str):

self.logger.info(f"Opened video at {video_path}")

def read_frames(self) -> Iterator[np.ndarray]:
def read_frames(self) -> Iterator[Tuple[int, np.ndarray]]:
"""
Read frames from the video file.
Read frames from the video file along with their index.
Yields:
np.ndarray: The next frame in the video.
Tuple[int, np.ndarray]: The index and the next frame in the video.
"""
while self.cap.isOpened():
ret, frame = self.cap.read()
self.logger.debug(f"Reading frame {self.cap.get(cv2.CAP_PROP_POS_FRAMES)}")
index = int(self.cap.get(cv2.CAP_PROP_POS_FRAMES))
self.logger.debug(f"Reading frame {index}")

if not ret:
break
yield frame

yield index, frame

def release(self) -> None:
"""
Expand Down
7 changes: 4 additions & 3 deletions miniscope_io/plots/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

logger = init_logger("videoplot")


class VideoPlotter:
"""
Class to display video streams and static images.
Expand All @@ -32,7 +33,7 @@ def show_video_with_controls(
start_frame: int,
end_frame: int,
fps: int = 20,
) -> None:
) -> None:
"""
Plot multiple video streams or static images side-by-side.
Can play/pause and navigate frames.
Expand Down Expand Up @@ -64,7 +65,7 @@ def show_video_with_controls(
titles = [video.name for video in videos]

num_streams = len(video_frames)

logger.info(f"Displaying {num_streams} video streams.")
if end_frame > start_frame:
logger.info(f"Displaying frames {start_frame} to {end_frame}.")
Expand All @@ -73,7 +74,7 @@ def show_video_with_controls(
if len(video_frames[stream_index]) > 1:
video_frames[stream_index] = video_frames[stream_index][start_frame:end_frame]
logger.info(f"Trimmed stream length: {len(video_frames[stream_index])}")

num_frames = max(len(stream) for stream in video_frames)
logger.info(f"Max stream length: {num_frames}")

Expand Down
Loading

0 comments on commit 3bbab4d

Please sign in to comment.