fix(v5): average noisy copies from clean source
This commit is contained in:
@@ -165,6 +165,8 @@ def image_state_apply_operation(*, state, operation, params):
|
||||
return image_state_fft_spectrum_create(state=state, params=params or {})
|
||||
if operation == "inverse_fft_reconstruction":
|
||||
return image_state_inverse_fft_create(state=state, params=params or {})
|
||||
if operation == "average_noisy_copies":
|
||||
return image_state_average_noisy_copies_create(state=state, params=params or {})
|
||||
|
||||
source = load_image_array(state.image)
|
||||
result = apply_registered_operation(source, operation, params or {})
|
||||
@@ -180,6 +182,40 @@ def image_state_apply_operation(*, state, operation, params):
|
||||
return image_state_payload(state=new_state, include_image=True)
|
||||
|
||||
|
||||
def image_state_average_noisy_copies_create(*, state, params):
|
||||
"""Create averaged noisy copies from the clean source behind a Gaussian-noise state.
|
||||
|
||||
If the active state is already a Gaussian-noisy image, the averaging must regenerate independent
|
||||
noisy copies from its parent image, not from the already-noisy pixels.
|
||||
"""
|
||||
|
||||
source_state = state
|
||||
if (
|
||||
state.operation == "noise_filter"
|
||||
and isinstance(state.params, dict)
|
||||
and state.params.get("kind", "gaussian") == "gaussian"
|
||||
and state.parent is not None
|
||||
):
|
||||
source_state = state.parent
|
||||
|
||||
operation_params = dict(params or {})
|
||||
if source_state.id != state.id:
|
||||
operation_params["source_state_id"] = str(source_state.id)
|
||||
|
||||
source = load_image_array(source_state.image)
|
||||
result = apply_registered_operation(source, "average_noisy_copies", operation_params)
|
||||
new_state = image_state_create(
|
||||
session=state.session,
|
||||
parent=state,
|
||||
image=result,
|
||||
operation="average_noisy_copies",
|
||||
params=operation_params,
|
||||
label=None,
|
||||
prefix="state-average_noisy_copies",
|
||||
)
|
||||
return image_state_payload(state=new_state, include_image=True)
|
||||
|
||||
|
||||
def image_state_fft_spectrum_create(*, state, params):
|
||||
"""Create an FFT visualization state and persist the actual complex spectrum.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user