HJ-harry / score-MRI

Apache License 2.0
139 stars 21 forks source link

Incorrect Normalization of Complex-Valued Image #16

Open bayesbreeze opened 1 year ago

bayesbreeze commented 1 year ago

Hello,

I believe I've identified an issue with the normalization of complex-valued images in the normalize_complex() function defined in this utils.py (lines 55-59).

The current implementation separately normalizes the magnitude and phase of the complex numbers, like so:

def normalize_complex(img):
    """ normalizes the magnitude of complex-valued image to range [0, 1] """
    abs_img = normalize(torch.abs(img))
    ang_img = normalize(torch.angle(img))
    return abs_img * torch.exp(1j * ang_img)

However, normalizing the phase of a complex number is not meaningful because the phase already lies within a fixed range (-pi to pi or 0 to 2pi).

Instead, the function should only normalize the magnitudes of the complex numbers, while preserving their phases. Here's a suggested revision of the normalize_complex() function:

def normalize_complex(img):
    """ normalizes the magnitude of complex-valued image to range [0, 1] """
    norm_mag_img = normalize(torch.abs(img))
    ang_img = torch.angle(img)
    return norm_mag_img * torch.exp(1j * ang_img)

This revised function maintains the phases of the complex numbers, while scaling the magnitudes to fall within the range [0, 1]. Please note that it scales the largest magnitude in the image to 1 and adjusts all other magnitudes relative to that.

I hope this is helpful and look forward to your feedback.

Note: this feedback is written under the help of ChatGPT-4.