prep_for_imshow#

prep_for_imshow(im, mask=None, axis=0, slice=None)[source]#

Adjusts the range of greyscale values in an image to improve visualization by matplotlib.pyplot.imshow

Parameters:
  • im (ndimage) – The image to show. If im includes +inf or -inf values, they are converted to 1 above or below the minimum and maximum finite values in im, respectively.

  • mask (ndimage, optional) – An image of the porous material with True indicating voxels of interest. The False voxels are excluded from the vmax and vmin calculation.

  • axis (int, optional) – If the image is 3D, a 2D image is returned with the specified slice taken along this axis (default = 0). If None then a 3D image is returned. If the image is 2D this is ignored.

  • slice (int, optional) – If im is 3D, a 2D image is be returned showing this slice along the given axis. If None, then a slice at the mid-point of the axis is returned. If axis is None or the image is 2D this is ignored.

Returns:

kwargs – A python dicionary designed to be passed directly to matplotlib.pyplot.imshow using the “**kwargs” features (i.e. plt.imshow(\*\*data)). It contains the following key-value pairs:

key

value

’X’

The adjusted image with +inf replaced by vmax + 1, and all solid voxels replacd by np.nan to show as white in imshow

’vmax’

The maximum of values not including +inf or values in False voxels in mask.

’vmin’

The minimum of values not including -inf or values in False voxels in mask.

’interpolation’

Set to ‘none’ to avoid artifacts in imshow

’origin’

Set to ‘lower’ to put (0, 0) on the bottom-left corner

Return type:

dict

Notes

If any of the extra items are unwanted they can be removed with del data['interpolation'] or data.pop('interpolation').

Examples

Click here to view online example.