Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential test case: Linear intensity matching #156

Open
Romain-Laine opened this issue Nov 29, 2024 · 0 comments
Open

Potential test case: Linear intensity matching #156

Romain-Laine opened this issue Nov 29, 2024 · 0 comments

Comments

@Romain-Laine
Copy link

Here's a suggestion of a test case: perform intensity rescaling of one image to match the intensity distribution of another image, by linear rescaling. This can be done by simple explicit minimisation of the mean square error, which leads to this expression:

def linear_intensity_matching(imA: np.ndarray, imB: np.ndarray) -> np.ndarray:
    """
    Perform a linear intensity match between 2 images so that they are in 
    the same intensity range, assuming: imB ~ slope*imA + intercept
    Arguments:
    - imA: first image, the one that will be adjusted
    - imB: the second image, the one that sets the range to match
    Output:
    - a rescaled version of imA such that  
    """
    meanA = imA.mean()
    meanB = imB.mean()
    meanAB = (imA*imB).mean()
    meanA2 = (imA**2).mean()

    slope = (meanAB-meanA*meanB)/(meanA2-meanA*meanB)
    intercept = meanB - slope*meanA

    return slope*imA+intercept

The use case for instance is to compare images through MSE afterwards once they're intensity matched, or applying other metrics to compare similarity.

@Romain-Laine Romain-Laine changed the title Potential test case: Linear intensity mathing Potential test case: Linear intensity matching Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant