|
5 | 5 |
|
6 | 6 | extension_name = "ndx-microscopy" |
7 | 7 |
|
| 8 | +# PlanarImagingSpace API functions |
| 9 | + |
| 10 | +PlanarImagingSpace = get_class("PlanarImagingSpace", extension_name) |
| 11 | + |
| 12 | + |
| 13 | +@docval( |
| 14 | + { |
| 15 | + "name": "dimensions_in_pixels", |
| 16 | + "type": (tuple, "array_data"), |
| 17 | + "doc": "the size of the image in pixels", |
| 18 | + "default": None, |
| 19 | + }, |
| 20 | + { |
| 21 | + "name": "pixel_size_in_um", |
| 22 | + "type": (tuple, "array_data"), |
| 23 | + "doc": "the size of a pixel in micrometers", |
| 24 | + "default": None, |
| 25 | + }, |
| 26 | + allow_extra=True, |
| 27 | +) |
| 28 | +def get_FOV_size(self, **kwargs): |
| 29 | + """Get the size of the Field of View (FOV) in micrometers. |
| 30 | +
|
| 31 | + Parameters |
| 32 | + ---------- |
| 33 | + dimension_in_pixels : int or tuple, optional |
| 34 | + The size of the image in pixels. If not provided, will use the imaging space's dimension. |
| 35 | + pixel_size_in_um : float or tuple, optional |
| 36 | + The size of a pixel in micrometers. If not provided, will use the imaging space's pixel size. |
| 37 | +
|
| 38 | + Returns |
| 39 | + ------- |
| 40 | + tuple |
| 41 | + The size of the FOV in micrometers as (height, width). |
| 42 | + """ |
| 43 | + dimensions_in_pixels, pixel_size_in_um = popargs("dimensions_in_pixels", "pixel_size_in_um", kwargs) |
| 44 | + # Use instance attributes if parameters not provided |
| 45 | + if dimensions_in_pixels is None: |
| 46 | + dimensions_in_pixels = getattr(self, "dimensions_in_pixels", None) |
| 47 | + if dimensions_in_pixels is None: |
| 48 | + raise ValueError("dimensions_in_pixels must be provided either as parameter or set on the imaging space") |
| 49 | + |
| 50 | + if pixel_size_in_um is None: |
| 51 | + pixel_size_in_um = getattr(self, "pixel_size_in_um", None) |
| 52 | + if pixel_size_in_um is None: |
| 53 | + raise ValueError("pixel_size_in_um must be provided either as parameter or set on the imaging space") |
| 54 | + |
| 55 | + # Convert to numpy arrays for element-wise multiplication |
| 56 | + dimensions_in_pixels = np.asarray(dimensions_in_pixels) |
| 57 | + pixel_size_in_um = np.asarray(pixel_size_in_um) |
| 58 | + |
| 59 | + FOV_size = dimensions_in_pixels * pixel_size_in_um |
| 60 | + return tuple(FOV_size) |
| 61 | + |
| 62 | + |
| 63 | +PlanarImagingSpace.get_FOV_size = get_FOV_size |
| 64 | + |
| 65 | + |
| 66 | +# VolumetricImagingSpace API functions |
| 67 | + |
| 68 | +VolumetricImagingSpace = get_class("VolumetricImagingSpace", extension_name) |
| 69 | + |
| 70 | + |
| 71 | +@docval( |
| 72 | + { |
| 73 | + "name": "dimensions_in_voxels", |
| 74 | + "type": (tuple, "array_data"), |
| 75 | + "doc": "the size of the image in voxels", |
| 76 | + "default": None, |
| 77 | + }, |
| 78 | + { |
| 79 | + "name": "voxel_size_in_um", |
| 80 | + "type": (tuple, "array_data"), |
| 81 | + "doc": "the size of a voxel in micrometers", |
| 82 | + "default": None, |
| 83 | + }, |
| 84 | + allow_extra=True, |
| 85 | +) |
| 86 | +def get_FOV_size(self, **kwargs): |
| 87 | + """Get the size of the Field of View (FOV) in micrometers. |
| 88 | +
|
| 89 | + Parameters |
| 90 | + ---------- |
| 91 | + dimension_in_voxels : int or tuple, optional |
| 92 | + The size of the image in voxels. If not provided, will use the imaging space's dimension. |
| 93 | + voxel_size_in_um : float or tuple, optional |
| 94 | + The size of a voxel in micrometers. If not provided, will use the imaging space's voxel size. |
| 95 | +
|
| 96 | + Returns |
| 97 | + ------- |
| 98 | + tuple |
| 99 | + The size of the FOV in micrometers as (depth, height, width). |
| 100 | + """ |
| 101 | + dimensions_in_voxels, voxel_size_in_um = popargs("dimensions_in_voxels", "voxel_size_in_um", kwargs) |
| 102 | + # Use instance attributes if parameters not provided |
| 103 | + if dimensions_in_voxels is None: |
| 104 | + dimensions_in_voxels = getattr(self, "dimensions_in_voxels", None) |
| 105 | + if dimensions_in_voxels is None: |
| 106 | + raise ValueError("dimensions_in_voxels must be provided either as parameter or set on the imaging space") |
| 107 | + |
| 108 | + if voxel_size_in_um is None: |
| 109 | + voxel_size_in_um = getattr(self, "voxel_size_in_um", None) |
| 110 | + if voxel_size_in_um is None: |
| 111 | + raise ValueError("voxel_size_in_um must be provided either as parameter or set on the imaging space") |
| 112 | + |
| 113 | + # Convert to numpy arrays for element-wise multiplication |
| 114 | + dimensions_in_voxels = np.asarray(dimensions_in_voxels) |
| 115 | + voxel_size_in_um = np.asarray(voxel_size_in_um) |
| 116 | + |
| 117 | + FOV_size = dimensions_in_voxels * voxel_size_in_um |
| 118 | + return tuple(FOV_size) |
| 119 | + |
| 120 | + |
| 121 | +VolumetricImagingSpace.get_FOV_size = get_FOV_size |
| 122 | + |
8 | 123 |
|
9 | 124 | # PlanarSegmentation API functions |
10 | 125 |
|
|
0 commit comments