Skip to content

Commit

Permalink
different thresholds for noise detection methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakers-the-rat committed Jan 18, 2025
1 parent 80da61a commit 76d0c46
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
35 changes: 35 additions & 0 deletions mio/data/config/process/denoise_example_mean_error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
id: denoise_example_mean_error
mio_model: mio.models.process.DenoiseConfig
mio_version: 0.6.1
interactive_display:
enable: true
start_frame: 40
end_frame: 140
noise_patch:
enable: true
method: mean_error
threshold: 30
buffer_size: 5032
buffer_split: 8
diff_multiply: 1
output_result: true
output_noise_patch: true
output_diff: true
output_noisy_frames: true
frequency_masking:
enable: true
spatial_LPF_cutoff_radius: 15
vertical_BEF_cutoff: 2
horizontal_BEF_cutoff: 0
display_mask: false
output_mask: true
output_result: true
output_freq_domain: false
minimum_projection:
enable: true
normalize: true
output_result: true
output_min_proj: true
end_frame: -1 #-1 means all frames
output_result: true
output_dir: user_dir/output
6 changes: 3 additions & 3 deletions mio/process/frame_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ def detect_frame_with_noisy_buffer(
serialized_previous = previous_frame.flatten().astype(np.int16)
logger.debug(f"Serialized previous frame size: {len(serialized_previous)}")

split_previous = self.split_by_length(serialized_previous, config.buffer_size)
split_current = self.split_by_length(serialized_current, config.buffer_size)
split_size = config.buffer_size // config.buffer_split + 1
split_previous = self.split_by_length(serialized_previous, split_size)
split_current = self.split_by_length(serialized_current, split_size)

return self._detect_with_mean_error(split_current, split_previous, config)

Expand Down Expand Up @@ -122,7 +123,6 @@ def _detect_with_mean_error(
f"Actual total splits in current: {len(split_current)}, previous: {len(split_previous)}"
)


# Iterate over buffers and split sections
logger.debug(
f"Entering mean_error loop: Total splits: {len(split_current)}, "
Expand Down
21 changes: 13 additions & 8 deletions tests/test_process/test_frame_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..conftest import DATA_DIR


@pytest.mark.parametrize(
"noise_detection_method",
[
Expand All @@ -20,7 +21,13 @@ def test_noise_detection_contrast(noise_detection_method):
Contrast method of noise detection should correctly label frames corrupted
by speckled noise
"""
global_config: DenoiseConfig = DenoiseConfig.from_id("denoise_example")
if noise_detection_method == "gradient":
global_config: DenoiseConfig = DenoiseConfig.from_id("denoise_example")
elif noise_detection_method == "mean_error":
global_config: DenoiseConfig = DenoiseConfig.from_id("denoise_example_mean_error")
else:
raise ValueError("Invalid noise detection method")

config: NoisePatchConfig = global_config.noise_patch
config.method = noise_detection_method

Expand All @@ -45,19 +52,17 @@ def test_noise_detection_contrast(noise_detection_method):
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
if noise_detection_method == "gradient":
is_noisy, mask = detector.detect_frame_with_noisy_buffer(
current_frame = frame,
previous_frame = None,
config = config)
current_frame=frame, previous_frame=None, config=config
)
if noise_detection_method == "mean_error":
if previous_frame is None:
previous_frame = frame
is_noisy, mask = detector.detect_frame_with_noisy_buffer(
current_frame = frame,
previous_frame = previous_frame,
config = config)
current_frame=frame, previous_frame=previous_frame, config=config
)
if not is_noisy:
previous_frame = frame
frames.append(is_noisy)
masks.append(mask)

assert np.array_equal(np.where(frames)[0], expected["frames"])
assert np.array_equal(np.where(frames)[0], expected["frames"])

0 comments on commit 76d0c46

Please sign in to comment.