o  i&@sddlmZddlmZmZddlZddlZddlm Z m Z ddl m Z ddl mZddlmZddlmZdd lmZmZerGdd lmZned d d \ZZddgZdddddddddddejdejfd=d1dZ 2 3 4 4d>d?d>> import numpy as np >>> import matplotlib.pyplot as plt >>> from monai.visualize import matshow3d # create a figure of a 3D volume >>> volume = np.random.rand(10, 10, 10) >>> fig = plt.figure() >>> matshow3d(volume, fig=fig, title="3D Volume") >>> plt.show() # create a figure of a list of channel-first 3D volumes >>> volumes = [np.random.rand(1, 10, 10, 10), np.random.rand(1, 10, 10, 10)] >>> fig = plt.figure() >>> matshow3d(volumes, fig=fig, title="List of Volumes") >>> plt.show() )data output_typerN)rr)rzKchannel_dim must be: None, 0 or 1, and channels of image must be 1, 3 or 4.z volume must be a list of arrays.cSsg|]}|jqS)shape.0vr3r3W/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/visualize/utils.py nszmatshow3d..axisrcsg|]}|qSr3r3r5)padr3r8r9psr1rF)copyconstant)modeconstant_valuescs&g|]fddtDqS)csg|] }|qSr3r3)r6j)colsivolr3r8r9sz(matshow3d...)range)r6)rFrH)rGr8r9s&T) tight_layouto)r!r#r%offset_size_inches)%r npndarrayr4 ValueError isinstancelisttuplemaxasarrayr concatenatelen expand_dimsmoveaxisreshapenanminnanmaxrceilsqrtminr<astypeblockrIpltAxesfigureaxes add_subplotmatshowr; set_titlehasattrrMr')rrrrrrr r!r#r$r%r'r)r*r+r,pad_sizerowswidthimaxr3)rFr<rHr8r"sbC &         ?hsvTimagelabelalphafloat | NdarrayOrTensorcmaprescale_arraystransparent_backgroundc Cs0|jddkr td|jddvrtd|jdd|jddkr(tdt|tjtjfrC|jdd|jddkrCtd|rMt|}t|}|jddkr[t|d dd }ddd}|||}t|tjtjfrq|}nt|tjr~t ||}nt ||}|rd||dk<d|} | |||S)a Blend an image and a label. Both should have the shape CHW[D]. The image may have C==1 or 3 channels (greyscale or RGB). The label is expected to have C==1. Args: image: the input image to blend with label data. label: the input label to blend with image data. alpha: this specifies the weighting given to the label, where 0 is completely transparent and 1 is completely opaque. This can be given as either a single value or an array/tensor that is the same size as the input image. cmap: specify colormap in the matplotlib, default to `hsv`, for more details, please refer to: https://matplotlib.org/2.0.2/users/colormaps.html. rescale_arrays: whether to rescale the array to [0, 1] first, default to `True`. transparent_background: if true, any zeros in the label field will not be colored. .. image:: ../../docs/images/blend_images.png rrzLabel should have 1 channel.)rr1z"Image should have 1 or 3 channels.Nz3image and label should have matching spatial sizes.z;if alpha is image, size should match input image and label.r1r:rur&rrrr-cSsPtj|}t|tj^}}||d}t|dddd}t||^}}|S)Nrr>r1)rb colormapsget_cmapr rNrOrYr )rurrZ_cmapZlabel_np_Z label_rgb_np label_rgbr3r3r8 get_label_rgbs  z#blend_images..get_label_rgb)rur&rrrr-r) r4rPrQrNrOtorchTensorrr full_like) rqrrrsrurvrwr|r{Zw_labelZw_imager3r3r8rs2     )"rrrrrrrrrrrrr rr!r"r#r"r$rr%r&r'r(r)rr*rr+rr,rr-r.)rorpTT)rqrrrrrsrtrur&rvr(rwr(r-r) __future__rtypingrrnumpyrNr}monai.config.type_definitionsrrmonai.transforms.croppad.arrayrmonai.transforms.utilsr0monai.transforms.utils_pytorch_numpy_unificationr monai.utils.moduler monai.utils.type_conversionr r rr rbrz__all__nanfloat32rrr3r3r3r8sF