Skip to content

Volume Downsample Unexpected Behavior #1155

@j-c-c

Description

@j-c-c

After some investigation into our 3D downsample I'm seeing some unexpected behavior regarding centering and scaling.

Here is a small example script I'm running:

import numpy as np

from aspire.volume import Volume

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

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

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

        # Look at center                                                                                                                                                                                                                  
        cent_vals = vol_ds.asnumpy()[0][
            res_ds//2 - 1: res_ds//2 + 2,
            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.    0.   ]
  [0.    0.    0.   ]]

 [[0.    0.    0.   ]
  [0.    0.125 0.   ]
  [0.    0.    0.   ]]

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


res:64, res_ds:33

[[[-0.00132346  0.00395838  0.00395838]
  [ 0.00395838 -0.0118393  -0.0118393 ]
  [ 0.00395838 -0.0118393  -0.0118393 ]]

 [[ 0.00395838 -0.0118393  -0.0118393 ]
  [-0.0118393   0.03541068  0.03541068]
  [-0.0118393   0.03541068  0.03541068]]

 [[ 0.00395838 -0.0118393  -0.0118393 ]
  [-0.0118393   0.03541068  0.03541068]
  [-0.0118393   0.03541068  0.03541068]]]


res:65, res_ds:32

[[[ 0.00299453  0.0093219  -0.00185942]
  [ 0.0093219   0.02873575 -0.00567675]
  [-0.00185942 -0.00567675  0.00111061]]

 [[ 0.0093219   0.02873575 -0.00567675]
  [ 0.02873575  0.08772943 -0.01716358]
  [-0.00567675 -0.01716358  0.0033247 ]]

 [[-0.00185942 -0.00567675  0.00111061]
  [-0.00567675 -0.01716358  0.0033247 ]
  [ 0.00111061  0.0033247  -0.00063736]]]


res:65, res_ds:33

[[[-0.00074854  0.00378095  0.00123554]
  [ 0.00378095 -0.01909793 -0.00624084]
  [ 0.00123554 -0.00624084 -0.00203939]]

 [[ 0.00378095 -0.01909793 -0.00624084]
  [-0.01909793  0.09646548  0.0315231 ]
  [-0.00624084  0.0315231   0.01030116]]

 [[ 0.00123554 -0.00624084 -0.00203939]
  [-0.00624084  0.0315231   0.01030116]
  [-0.00203939  0.01030116  0.00336622]]]

My expectation is that all of the pixel intensity would be in the center pixel and have value 1.

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