Image Processing Module
Image processing functions for qi2lab 3D MERFISH.
This module includes various utilities for image processing, such as downsampling, padding, and chunked GPU-based deconvolution.
History:
- 2024/12: Refactored repo structure.
- 2024/07: Added numba-accelerated downsampling, padding helper functions, and chunked GPU deconvolution.
Functions:
Name | Description |
---|---|
chunked_cudadecon | Chunked and padded GPU deconvolution using pycudadecon. |
correct_shading | Perform illumination shading correction. |
downsample_axis | Numba accelerated downsampling for 3D images along a specified axis. |
downsample_image_isotropic | Numba accelerated isotropic downsampling |
next_multiple_of_32 | Calculate next multiple of 32 for the given integer. |
no_op | Function to monkey patch print to suppress output. |
pad_z | Pad z-axis of 3D array by 32 (zyx order). |
remove_padding_z | Removing z-axis padding of 3D array (zyx order). |
replace_hot_pixels | Replace hot pixels with median values surrounding them. |
chunked_cudadecon(image, psf, image_voxel_zyx_um, psf_voxel_zyx_um, wavelength_um, na, ri, n_iters=10, background=100.0)
Chunked and padded GPU deconvolution using pycudadecon.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image | ArrayLike | 3D image to deconvolve | required |
psf | ArrayLike | 3D psf | required |
image_voxel_zyx_um | Sequence[float] | image voxel spacing in microns | required |
psf_voxel_zyx_um | Sequence[float] | psf voxel spacing in microns | required |
wavelength_um | float | emission wavelength in microns | required |
na | float | numerical aperture | required |
ri | float | immersion media refractive index | required |
n_iters | int | number of deconvolution iterations | 10 |
background | float | background level to subtract | 100.0 |
Returns:
Name | Type | Description |
---|---|---|
image_decon | ArrayLike | deconvolved image |
Source code in src/merfish3danalysis/utils/imageprocessing.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
correct_shading(noise_map, darkfield_image, shading_image, data)
Perform illumination shading correction.
I_corrected = (I_raw - I_dark) / (I_bright - I_dark). Here, we assume I_bright is not normalized or background corrected.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
noise_map | ArrayLike | darkfield image collected at long exposure time to get hot pixels | required |
darkfield_image | ArrayLike | darkfield image collected at data's exposure time | required |
shading_image | ArrayLike | illumination shading correction | required |
data | ArrayLike | ND data [broadcast_dim,z,y,x] | required |
Returns:
Name | Type | Description |
---|---|---|
data | ArrayLike | shading corrected data |
Source code in src/merfish3danalysis/utils/imageprocessing.py
downsample_axis(image, level=2, axis=0)
Numba accelerated downsampling for 3D images along a specified axis.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image | ArrayLike | 3D image to be downsampled. | required |
level | int | Amount of downsampling. | 2 |
axis | int | Axis along which to downsample (0, 1, or 2). | 0 |
Returns:
Name | Type | Description |
---|---|---|
downsampled_image | ArrayLike | 3D downsampled image. |
Source code in src/merfish3danalysis/utils/imageprocessing.py
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 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
downsample_image_isotropic(image, level=2)
Numba accelerated isotropic downsampling
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image | ArrayLike | 3D image to be downsampled | required |
level | int | isotropic downsampling level | 2 |
Returns:
Name | Type | Description |
---|---|---|
downsampled_image | ArrayLike | downsampled 3D image |
Source code in src/merfish3danalysis/utils/imageprocessing.py
next_multiple_of_32(x)
Calculate next multiple of 32 for the given integer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x | int | value to check. | required |
Returns:
Name | Type | Description |
---|---|---|
next_32_x | int | next multiple of 32 above x. |
Source code in src/merfish3danalysis/utils/imageprocessing.py
no_op(*args, **kwargs)
Function to monkey patch print to suppress output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args | positional arguments | () | |
kwargs | keyword arguments | {} |
pad_z(image)
Pad z-axis of 3D array by 32 (zyx order).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image | ArrayLike | 3D image to pad. | required |
Returns:
Name | Type | Description |
---|---|---|
padded_image | ArrayLike | padded 3D image |
pad_z_before | int | amount of padding at beginning |
pad_z_after | int | amount of padding at end |
Source code in src/merfish3danalysis/utils/imageprocessing.py
remove_padding_z(padded_image, pad_z_before, pad_z_after)
Removing z-axis padding of 3D array (zyx order).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
padded_image | ArrayLike | padded 3D image | required |
pad_z_before | int | amount of padding at beginning | required |
pad_z_after | int | amount of padding at end | required |
Returns:
Name | Type | Description |
---|---|---|
image | ArrayLike | unpadded 3D image |
Source code in src/merfish3danalysis/utils/imageprocessing.py
replace_hot_pixels(noise_map, data, threshold=375.0)
Replace hot pixels with median values surrounding them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
noise_map | ArrayLike | darkfield image collected at long exposure time to get hot pixels | required |
data | ArrayLike | ND data [broadcast_dim,z,y,x] | required |
Returns:
Name | Type | Description |
---|---|---|
data | ArrayLike | hotpixel corrected data |