Skip to content

Image Downsample Scaling Bug #1156

@j-c-c

Description

@j-c-c

It looks like there is a scaling issue with our 2D downsample. Here is a small script that illustrates:

import numpy as np

from aspire.image import Image

SIZES = [64, 65]
DS_SIZES = [32, 33]
dtype = np.float64

for res in SIZES:
    one_hot = np.zeros((res,) * 2, dtype=dtype)
    one_hot[res//2, res//2] = 1
    im = Image(one_hot)

    # Check vol.downsample()                                                                                                                                                                   
    for res_ds in DS_SIZES:
        im_ds = im.downsample(res_ds)

        # Look at center                                                                                                                                                                       
        cent_vals = im_ds.asnumpy()[0][
            res_ds//2 - 1: res_ds//2 + 2,
            res_ds//2 - 1: res_ds//2 + 2,
        ]
        print(f"res:{res}, res_ds:{res_ds}\n")
        print(f"{cent_vals}\n\n")

And the output:

res:64, res_ds:32

[[0.   0.   0.  ]
 [0.   0.25 0.  ]
 [0.   0.   0.  ]]


res:64, res_ds:33

[[0.         0.         0.        ]
 [0.         0.26586914 0.        ]
 [0.         0.         0.        ]]


res:65, res_ds:32

[[0.         0.         0.        ]
 [0.         0.24236686 0.        ]
 [0.         0.         0.        ]]


res:65, res_ds:33

[[0.         0.         0.        ]
 [0.         0.25775148 0.        ]
 [0.         0.         0.        ]]

I would expect there to be a 1 in each center pixel.

This can be fixed by removing the rescaling factor in the line below.

out = np.real(fft.centered_ifft2(crop_fx)) * (ds_res**2 / self.resolution**2)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions