cross_correlation
File containing Fourier-slice based cross-correlation functions for 2DTM.
do_batched_orientation_cross_correlate(image_dft, template_dft, rotation_matrices, projective_filters)
Batched projection and cross-correlation with fixed (batched) filters.
NOTE: This function is similar to do_streamed_orientation_cross_correlate
but
it computes cross-correlation batches over the orientation space. For example, if
there are 32 orientations to process and 10 different defocus values, then there
would be a total of 10 batched-32 cross-correlations computed.
NOTE: that this function returns a cross-correlogram with "same" mode (i.e. the same size as the input image). See numpy correlate docs for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_dft
|
Tensor
|
Real-fourier transform (RFFT) of the image with large image filters already applied. Has shape (H, W // 2 + 1). |
required |
template_dft
|
Tensor
|
Real-fourier transform (RFFT) of the template volume to take Fourier slices from. Has shape (l, h, w // 2 + 1) where (l, h, w) is the original real-space shape of the template volume. |
required |
rotation_matrices
|
Tensor
|
Rotation matrices to apply to the template volume. Has shape (num_orientations, 3, 3). |
required |
projective_filters
|
Tensor
|
Multiplied 'ctf_filters' with 'whitening_filter_template'. Has shape (num_Cs, num_defocus, h, w // 2 + 1). Is RFFT and not fftshifted. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Cross-correlation of the image with the template volume for each orientation and defocus value. Will have shape (num_Cs, num_defocus, num_orientations, H, W). |
Source code in src/leopard_em/backend/cross_correlation.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
do_batched_orientation_cross_correlate_cpu(image_dft, template_dft, rotation_matrices, projective_filters)
Same as do_streamed_orientation_cross_correlate
but on the CPU.
The only difference is that this function does not call into a compiled torch function for normalization.
TODO: Figure out a better way to split up CPU/GPU functions while remaining performant and not duplicating code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_dft
|
Tensor
|
Real-fourier transform (RFFT) of the image with large image filters already applied. Has shape (H, W // 2 + 1). |
required |
template_dft
|
Tensor
|
Real-fourier transform (RFFT) of the template volume to take Fourier slices from. Has shape (l, h, w // 2 + 1). |
required |
rotation_matrices
|
Tensor
|
Rotation matrices to apply to the template volume. Has shape (orientations, 3, 3). |
required |
projective_filters
|
Tensor
|
Multiplied 'ctf_filters' with 'whitening_filter_template'. Has shape (defocus_batch, h, w // 2 + 1). Is RFFT and not fftshifted. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Cross-correlation for the batch of orientations and defocus values.s |
Source code in src/leopard_em/backend/cross_correlation.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
do_streamed_orientation_cross_correlate(image_dft, template_dft, rotation_matrices, projective_filters, streams)
Calculates a grid of 2D cross-correlations over multiple CUDA streams.
NOTE: This function is more performant than a batched 2D cross-correlation with shape (N, H, W) when the kernel (template) is much smaller than the image (e.g. kernel is 512x512 and image is 4096x4096). Each cross-correlation is computed individually and stored in a batched tensor for the grid of orientations, defoci, and pixel size values.
NOTE: this function returns a cross-correlogram with "same" mode (i.e. the same size as the input image). See numpy correlate docs for more information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_dft
|
Tensor
|
Real-fourier transform (RFFT) of the image with large image filters already applied. Has shape (H, W // 2 + 1). |
required |
template_dft
|
Tensor
|
Real-fourier transform (RFFT) of the template volume to take Fourier slices from. Has shape (l, h, w // 2 + 1) where (l, h, w) is the original real-space shape of the template volume. |
required |
rotation_matrices
|
Tensor
|
Rotation matrices to apply to the template volume. Has shape (num_orientations, 3, 3). |
required |
projective_filters
|
Tensor
|
Multiplied 'ctf_filters' with 'whitening_filter_template'. Has shape (num_Cs, num_defocus, h, w // 2 + 1). Is RFFT and not fftshifted. |
required |
streams
|
list[Stream]
|
List of CUDA streams to use for parallel computation. Each stream will handle a separate cross-correlation. |
required |
Returns:
Type | Description |
---|---|
Tensor
|
Cross-correlation of the image with the template volume for each orientation and defocus value. Will have shape (num_Cs, num_defocus, num_orientations, H, W). |
Source code in src/leopard_em/backend/cross_correlation.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|