magmap.plot.plot_3d module¶
3D image stack interaction.
Prepare volumetric image stacks for plotting.
- magmap.plot.plot_3d.build_ground_truth(img3d, blobs, ellipsoid=False, labels=None, spacing=None)[source]¶
Build ground truth volumetric image from blobs.
- Variables:
img3d – Image as 3D Numpy array in which to store results
blobs – Numpy array of segments to display, given as an (n, 4) dimension array, where each segment is in (z, y, x, radius).
ellipsoid – True to draw blobs as ellipsoids; defaults to False.
labels – Array of labels the same length as
blobsto assign as the values for each ground truth; defaults to None to assign a default value of 1 instead.spacing – Spacing by which to multiply blobs` radii; defaults to None, in which case each blob’s radius will be used for all dimensions.
- Returns:
img3dwith ground drawn as circles or ellipsoids.
- magmap.plot.plot_3d.deconvolve(roi)[source]¶
Deconvolves the image.
- Parameters:
roi – ROI given as a (z, y, x) subset of image5d.
- Returns:
The ROI deconvolved.
- magmap.plot.plot_3d.denoise_roi(roi, channel=None)[source]¶
Denoise and further preprocess an image.
Applies saturation, denoising, unsharp filtering, and erosion as image preprocessing for blob detection.
Each step can be configured including turned off by
magmap.settings.config.roi_profiles.- Parameters:
roi (
ndarray) – Region of interest as a 3D (z, y, x) array. Note that 4D arrays with channels are not allowed as the Scikit-Image gaussian filter only accepts specifically 3 channels, presumably for RGB.channel (
Optional[Sequence[int]], default:None) – Sequence of channel indices inroito saturate. Defaults to None to use all channels.
- Return type:
- Returns:
Denoised region of interest.
- magmap.plot.plot_3d.get_isotropic_vis(settings)[source]¶
Get the isotropic factor scaled by the profile setting for visualization.
Visualization may require the isotropic factor to be further scaled, such as for images whose z resolution is less precise that x/y resolution.
- Parameters:
settings (
magmap.settings.profiles.SettingsDict) – Settings dictionary from which to retrieve the isotropic visualization value.- Returns:
Isotropic factor based on the profile setting.
- Return type:
- magmap.plot.plot_3d.pad_img(img, offset, shape)[source]¶
Pad image surroundings with zeros.
- Parameters:
img (
numpy.ndarray) – Image array.offset (tuple[int, int, int]) – Offset within padded image at which to place
img, given as a sequence ofz,y,x.shape (tuple[int, int, int]) – Shape of resulting image, given as a sequence of
z,y,x. Values can be None or sequence can stop early to use the corresponding original shape values fromimg.
- Returns:
Padded image.
- Return type:
- magmap.plot.plot_3d.prepare_roi(image5d, roi_offset, roi_size, *args, **kwargs)[source]¶
Extracts a region of interest (ROI).
Calls
prepare_subimage()but expects size and offset variables to be in x,y,z order following this software’s legacy convention.- Parameters:
image5d (
ndarray) – 5D image array in the order,t,z,y,x[,c], where the final dimension is optional as with many one channel images.roi_offset (
Sequence[int]) – Tuple of offset given asx,y,zfor the region of interest. Defaults to(0, 0, 0).roi_size (
Sequence[int]) – Size of the region of interest asx,y,z.args – Positional arguments to
prepare_subroi().kwargs – Named arguments to
prepare_subroi().
- Return type:
- Returns:
The region of interest without separate time dimension as a 3D (or 4-D array if channel dimension exists) array.
- magmap.plot.plot_3d.prepare_subimg(image5d, offset, size, ndim_base=5, border=None)[source]¶
Extracts a subimage from a larger image.
- Parameters:
image5d (
ndarray) – 5D image array in the order,t, z, y, x, [c]unlessndim_baseis given.offset (
Sequence[int]) – Tuple of offset given asz, y, xfor the region of interest.size (
Sequence[int]) – Size of the region of interest asz, y, x.ndim_base (
int, default:5) – Number of dimensions inimage5d. Defaults to 5 for t, z, y, x, [c]`; if fewer, thetdimension is removed.border (
Union[int,Sequence[int],None], default:None) – Border size as either a scalar for all dimensions of values forz, y, x. The resulting subimage will be expanded to include this border outsideoffset, with the same extra size on opposite sides along each axis.
- Return type:
- Returns:
The sub-imge without separate time dimension as a 3D (or 4-D array if channel dimension exists) array.
- magmap.plot.plot_3d.remap_intensity(roi, channel=None, **kwargs)[source]¶
Remap intensities, currently using adaptive histogram equalization.
May allow plugging in alternative methods in the future.
- Parameters:
roi (
ndarray) – Region of interest as a 3D or 3D+channel array.channel (
Optional[Sequence[int]], default:None) – Channel index ofroito saturate. Defaults to None to use all channels. If a specific channel is given, all other channels remain unchanged.kwargs – Additional arguments to
skimage.exposure.equalize_adapthist(). Values can be given as sequences, where each element corresponds to channels inchannel.
- Return type:
- Returns:
Remapped region of interest as a new array.
- magmap.plot.plot_3d.replace_vol(img, vol, center=None, offset=None, vol_as_mask=None)[source]¶
Replace a volume within an image, centering on the given coordinates and cropping the input volume to fit.
- Parameters:
img (
numpy.ndarray) – Image as a Numpy array into whichvolwill be placed. Updated in-place.vol (
numpy.ndarray) – Volume to place inimg.center (tuple[int, int, int]) – Coordinates of the center of volume, given as a sequence of
z,y,x. Eithercenteroroffsetmust be given. Takes precedence overoffset.offset (tuple[int, int, int]) – Coordinates of offset within
imgto placevol, given as a sequence ofz,y,x.vol_as_mask (
numpy.ndarray) – Ifvolshould be taken as a mask, where only its True values will replace the corresponding pixels inimg, assign this value to the mask locations. Defaults to None, in which case the entirevolwill be assigned.
- Returns:
imgmodified in-place.- Return type:
- Raises:
ValueError – if
centerandoffsetare both None.
- magmap.plot.plot_3d.roi_center_to_offset(offset, shape, reverse=False)[source]¶
Convert an ROI offset given as the center of the ROI to the coordinates of the upper left hand corner of the ROI.
- Parameters:
offset (
Sequence[int]) – Offset taken as the center of the ROI in any order, typically eitherx,y,zorz,y,x.shape (
Sequence[int]) – ROI shape in the same order as that ofoffset.reverse (
bool, default:False) – True to treatoffsetas the upper left hand corner of the ROI and to obtain the center coordinates of this ROI; defaults to False.
- Return type:
- Returns:
Coordinates of the upper left corner of the ROI, or the center of the ROI if
reverseis True.
- magmap.plot.plot_3d.saturate_roi(roi, clip_vmin=-1, clip_vmax=-1, max_thresh_factor=-1, channel=None)[source]¶
Saturates an image, clipping extreme values and stretching remaining values to fit the full range.
- Parameters:
roi (
ndarray) – Region of interest.clip_vmin (
float, default:-1) – Percent for lower clipping. Defaults to -1 to use each channel’s profile setting.clip_vmax (
float, default:-1) – Percent for upper clipping. Defaults to -1 to use each channel’s profile setting.max_thresh_factor (
float, default:-1) – Multiplier ofconfig.near_maxfor ROI’s scaled maximum value. If the max data range value adjusted through``clip_vmax``is below this product, this max value will be set to this product. Defaults to -1 to use each channel’s profile setting.channel (
Optional[Sequence[int]], default:None) – Sequence of channel indices inroito saturate. Defaults to None to use all channels.
- Return type:
- Returns:
Saturated region of interest.
- magmap.plot.plot_3d.setup_channels(roi, channel, dim_channel)[source]¶
Setup channels array for the given ROI dimensions.
- Parameters:
- Returns:
multichannel: boolean value where True indicates that the ROI is multichannel (ie 4D)channels: an array of the channel indices ofroito include, which is the same aschannelfor multichannel ROIs or only the first element ifroiis single channel
- Return type:
A tuple of