magmap.atlas.transformer module¶
Transform large images with multiprocessing, including up/downsampling and image transposition.
- class magmap.atlas.transformer.Downsampler[source]¶
Bases:
objectDownsample (or theoretically upsample) a large image in a way that allows multiprocessing without global variables.
- Variables:
img (
np.ndarray) – Full image array.
- img = None¶
- classmethod rescale_sub_roi(coord, slices, target_size, multichannel, sub_roi=None)[source]¶
Rescale or resize a sub-ROI.
- Parameters:
coord (
Sequence[int]) – Coordinates as a tuple of (z, y, x) of the sub-ROI within the chunked ROI.slices (
Sequence[slice]) – Sequence of slices within :attr:imgdefining the sub-ROI.target_size (
Optional[Sequence[int]]) – Target rescaling size for the given sub-ROI in (z, y, x). Ifrescaleis not None,target_sizewill be ignored.multichannel (
bool) – True if the final dimension is for channels.sub_roi (
Optional[ndarray], default:None) – Array chunk to rescale/resize; defaults to None to extract fromimgif available.
- Return type:
- Returns:
Tuple of
coordand the rescaled sub-ROI, wherecoordis the same as the given parameter to identify where the sub-ROI is located during multiprocessing tasks.
- magmap.atlas.transformer.get_transposed_image_path(img_path, scale=None, target_size=None)[source]¶
Get path modified for any transposition.
- Parameters:
- Return type:
- Returns:
Modified path for the given transposition, or
img_pathunmodified if all transposition factors are None.
- magmap.atlas.transformer.make_modifier_plane(plane)[source]¶
Make a string designating a plane orthogonal transformation.
- Parameters:
plane – Plane to which the image was transposed.
- Returns:
String designating the orthogonal plane transformation.
- magmap.atlas.transformer.make_modifier_resized(target_size)[source]¶
Make a string designating a resize transformation.
Note that the final image size may differ slightly from this size as it only reflects the size targeted.
- Parameters:
target_size – Target size of rescaling in x,y,z.
- Returns:
String designating the resize transformation.
- magmap.atlas.transformer.make_modifier_scale(scale)[source]¶
Make a string designating a scaling transformation, typically for filenames of rescaled images.
- magmap.atlas.transformer.preprocess_img(image5d, preprocs, channel, out_path)[source]¶
Pre-process an image in 3D.
- Parameters:
- Returns:
The pre-processed image array.
- Return type:
np.ndarray
- magmap.atlas.transformer.rotate_img(roi, rotate=None, order=None)[source]¶
Rotate an ROI based on atlas profile settings.
- Parameters:
roi (
np.ndarray) – Region of interst array (z,y,x[,c]).rotate (dict) – Dictionary of rotation settings in
magmap.settings.atlas_profile. Defaults to None to take the value fromconfig.register_settings.order (int) – Spline interpolation order; defalts to None to use the value from within
rotate. Should be 0 for labels.
- Returns:
The rotated image array.
- Return type:
np.ndarray
- magmap.atlas.transformer.transpose_img(filename, series, plane=None, rescale=None, target_size=None)[source]¶
Transpose large NumPy saved arrays, including rescaling or resizing.
Loads a saved array to tranpose its planar orientation. Supports large arrays, with rescaling/resizing performed in multiprocessing and file saving through memmap-based arrays to minimize RAM usage. Output filenames are based on the
make_modifer_[task]functions. Currently, transposes all channels, ignoring :attr:magmap.settings.config.channelparameter.- Parameters:
filename (
str) – Full file path in :attribute:cli:`filename` format.plane (
Optional[str], default:None) – Planar orientation (seemagmap.settings.config.PLANES). Defaults to None, in which case no planar transformation will occur.rescale (
Optional[float], default:None) – Rescaling factor; defaults to None. Takes precedence overtarget_size.target_size (
Optional[Sequence[int]], default:None) – Target shape in x,y,z; defaults to None, in which case the target size will be extracted from the register profile if available.