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

build_template is darker in regions that are not always fully in field of view. #729

Open
dyollb opened this issue Nov 11, 2024 · 0 comments · May be fixed by #730
Open

build_template is darker in regions that are not always fully in field of view. #729

dyollb opened this issue Nov 11, 2024 · 0 comments · May be fixed by #730

Comments

@dyollb
Copy link
Contributor

dyollb commented Nov 11, 2024

Is your feature request related to a problem? Please describe.

build_template produces an atlas that is blurry in regions that are not always fully in the field-of-view. See the attached screenshot.

I believe the reason is partly because the mean image is not normalized correctly in these regions.

Describe the solution you'd like
I would propose to calculate the sum of the transformed weight images. The mean image can then be normalized using this weight image.

the inner for loop could could be modified like this

        for k in range(len(image_list)):
            w1 = ants.registration(
                xavg, image_list[k], type_of_transform=type_of_transform, **kwargs
            )
            L = len(w1["fwdtransforms"])
            # affine is the last one
            affinelist.append(w1["fwdtransforms"][L-1])

            if k == 0:
                if L == 2:
                    wavg = ants.image_read(w1["fwdtransforms"][0]) * weights[k]
                xavgNew = w1["warpedmovout"] * weights[k]
                wimgNew = ants.apply_transforms(xavg, ants.ones_like(image_list[k]) * weights[k], transformlist=w1["fwdtransforms"])
            else:
                if L == 2:
                    wavg = wavg + ants.image_read(w1["fwdtransforms"][0]) * weights[k]
                xavgNew = xavgNew + w1["warpedmovout"] * weights[k]
                wimgNew = wimgNew + ants.apply_transforms(xavg, ants.ones_like(image_list[k]) * weights[k], transformlist=w1["fwdtransforms"])

        # normalize
        nonzero = wimgNew.view() != 0
        xavgNew.view()[nonzero] = xavgNew.view()[nonzero] / wimgNew.view()[nonzero]

Note I introduced a ones_like helper, to make this modification more readable.

Describe alternatives you've considered
Re-implement the build_template function in my own code.

Additional context
using the current implementation:
image

with re-normalization using the code above. While the image is still blurry (because registration is less accurate near the boundary), the brightness stays more homogeneous:
image

@dyollb dyollb linked a pull request Nov 11, 2024 that will close this issue
@dyollb dyollb changed the title build_template is blury in regions that are not always fully in field of view. build_template is darked in regions that are not always fully in field of view. Nov 11, 2024
@dyollb dyollb changed the title build_template is darked in regions that are not always fully in field of view. build_template is darker in regions that are not always fully in field of view. Nov 13, 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

Successfully merging a pull request may close this issue.

1 participant