U Ph @srddlmZddlZddlmZddgZdd d d d d d d d d dd ddZdd d d d d d d d d d dd ddZdS)) annotationsN) rescale_arraycreate_test_image_2dcreate_test_image_3d intfloatz int | Noneznp.random.RandomState | Noneztuple[np.ndarray, np.ndarray]) heightwidthnum_objsrad_maxrad_min noise_maxnum_seg_classes channel_dim random_statereturnc Cs||krtd|d|d|dkr6td|dt||} | d|krbtd| d|dt||f} |d krtjjjn|} t|D]} | |||} | |||}| ||}tj| || | ||f\}}||||||k}|dkrt | || |<q| d d | |<qt | j tj d d }| j d ||| j d}tt| |}|d k rt|tr|dkstd|d kr|d }|d }n|d}|d}||fS)a Return a noisy 2D image with `num_objs` circles and a 2D mask image. The maximum and minimum radii of the circles are given as `rad_max` and `rad_min`. The mask will have `num_seg_classes` number of classes for segmentations labeled sequentially from 1, plus a background class represented as 0. If `noise_max` is greater than 0 then noise will be added to the image taken from the uniform distribution on range `[0,noise_max)`. If `channel_dim` is None, will create an image without channel dimension, otherwise create an image with channel dimension as first dim or last dim. Args: height: height of the image. The value should be larger than `2 * rad_max`. width: width of the image. The value should be larger than `2 * rad_max`. num_objs: number of circles to generate. Defaults to `12`. rad_max: maximum circle radius. Defaults to `30`. rad_min: minimum circle radius. Defaults to `5`. noise_max: if greater than 0 then noise will be added to the image taken from the uniform distribution on range `[0,noise_max)`. Defaults to `0`. num_seg_classes: number of classes for segmentations. Defaults to `5`. channel_dim: if None, create an image without channel dimension, otherwise create an image with channel dimension as first dim or last dim. Defaults to `None`. random_state: the random generator to use. Defaults to `np.random`. Returns: Randomised Numpy array with shape (`height`, `width`) `rad_min`  should be less than `rad_max` .z should be no less than 1.the minimal size 4 of the image should be larger than `2 * rad_max` 2xN?Fcopyrsize)rrinvalid channel dim..N ValueErrorminnpzerosrandom__self__rangerandintogridceilastypeint32uniformshapermaximum isinstancer AssertionError)r r rrrrrrrmin_sizeimagers_xyradspyspxcirclelabelsnorm noisyimagerDI/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/data/synthetic.pyrs<#    &    ) r r depthrrrrrrrrc Cs||krtd|d|d|dkr.tdt|||} | d|kr\td| d|dt|||f} | d kr~tjjjn| } t|D]} | |||}| |||}| |||}| ||}tj| ||| ||| ||f\}}}||||||||k}|dkr@t | || |<q| d d | |<qt | j tj d d }| j d ||| j d}tt| |}|d k rt|tr|dkstd|d kr|d |d fn|d|df\}}||fS)an Return a noisy 3D image and segmentation. Args: height: height of the image. The value should be larger than `2 * rad_max`. width: width of the image. The value should be larger than `2 * rad_max`. depth: depth of the image. The value should be larger than `2 * rad_max`. num_objs: number of circles to generate. Defaults to `12`. rad_max: maximum circle radius. Defaults to `30`. rad_min: minimum circle radius. Defaults to `5`. noise_max: if greater than 0 then noise will be added to the image taken from the uniform distribution on range `[0,noise_max)`. Defaults to `0`. num_seg_classes: number of classes for segmentations. Defaults to `5`. channel_dim: if None, create an image without channel dimension, otherwise create an image with channel dimension as first dim or last dim. Defaults to `None`. random_state: the random generator to use. Defaults to `np.random`. Returns: Randomised Numpy array with shape (`height`, `width`, `depth`) See also: :py:meth:`~create_test_image_2d` rrrrz.f`rad_min` {rad_min} should be no less than 1.rrrNrFrrr )r"rr#r$r%)r r rFrrrrrrrr7r8r9r:r;r<zr=r>r?Zspzr@rArBrCrDrDrEras8$    4   ()rrrr rNN)rrrr rNN) __future__rnumpyr(monai.transforms.utilsr__all__rrrDrDrDrE s&  "P