U
    Ph                     @  sr   d dl mZ d dlZd dlmZ ddgZdd
d
d
d
d
dd
dddd
ddZdd
d
d
d
d
d
dd
ddddddZdS )    )annotationsN)rescale_arraycreate_test_image_2dcreate_test_image_3d                 intfloatz
int | Noneznp.random.RandomState | Noneztuple[np.ndarray, np.ndarray])
heightwidthnum_objsrad_maxrad_min	noise_maxnum_seg_classeschannel_dimrandom_statereturnc	                 C  s  ||krt d| d| d|dk r6t d| dt| |}	|	d| krbt d|	 d| dt| |f}
|d	krtjjjn|}t|D ]}||| | }|||| }|||}tj| | | | || f \}}|| ||  || k}|dkrt	| | |
|< q| d
 d
 |
|< qt	|
j
tjdd}|jd|| |
jd}tt|
|}|d	k	rt|tr|dkstd|dkr|d	 }|d	 }n|d }|d }||fS )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      ?Fcopyr   size)r   r   invalid channel dim..N
ValueErrorminnpzerosrandom__self__rangerandintogridceilastypeint32uniformshaper   maximum
isinstancer
   AssertionError)r   r   r   r   r   r   r   r   r   min_sizeimagers_xyradspyspxcirclelabelsnorm
noisyimage rD   I/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/data/synthetic.pyr      s<    #
&



)r   r   depthr   r   r   r   r   r   r   r   c
                 C  s  ||krt d| d| d|dk r.t dt| ||}
|
d| kr\t d|
 d| dt| ||f}|	d	kr~tjjjn|	}t|D ]}||| | }|||| }|||| }|||}tj| | | | || | || f \}}}|| ||  ||  || k}|dkr@t	| | ||< q| d
 d
 ||< qt	|j
tjdd}|jd|| |jd}tt||}|d	k	rt|tr|dkstd|dkr|d	 |d	 fn|d |d f\}}||fS )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`
    r   r   r   r   z.f`rad_min` {rad_min} should be no less than 1.r   r   r   Nr   Fr   r   r    )r"   r      r#   r$   r%   )r   r   rF   r   r   r   r   r   r   r   r7   r8   r9   r:   r;   r<   zr=   r>   r?   Zspzr@   rA   rB   rC   rD   rD   rE   r   a   s8    $4 

()r   r   r   r	   r   NN)r   r   r   r	   r   NN)	
__future__r   numpyr(   monai.transforms.utilsr   __all__r   r   rD   rD   rD   rE   <module>   s&          "P       