o
    #i                     @  s`   d dl mZ d dlZd dlmZ ddgZ								ddddZ								ddddZdS )    )annotationsN)rescale_arraycreate_test_image_2dcreate_test_image_3d                 heightintwidthnum_objsrad_maxrad_min	noise_maxfloatnum_seg_classeschannel_dim
int | Nonerandom_statenp.random.RandomState | Nonereturntuple[np.ndarray, np.ndarray]c	                 C  s  ||krt d| d| d|dk rt d| dt| |}	|	d| kr1t d|	 d| dt| |f}
|d	u rAtjjjn|}t|D ]Q}||| | }|||| }|||}tj| | | | || f \}}|| ||  || k}|dkrt	| | |
|< qG| d
 d
 |
|< qGt	|
j
tjdd}|jd|| |
jd}tt|
|}|d	urt|tr|dv std|dkr|d	 }|d	 }||fS |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 rG   V/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/data/synthetic.pyr      s>   #
&depthc
                 C  s  ||krt d| d| d|dk rt dt| ||}
|
d| kr.t d|
 d| dt| ||f}|	d	u r?tjjjn|	}t|D ]d}||| | }|||| }|||| }|||}tj| | | | || | || f \}}}|| ||  ||  || k}|dkrt	| | ||< qE| d
 d
 ||< qEt	|j
tjdd}|jd|| |jd}tt||}|d	urt|tr|dv 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   rI   r   r   r   r   r   r   r   r:   r;   r<   r=   r>   r?   zr@   rA   rB   ZspzrC   rD   rE   rF   rG   rG   rH   r   a   s8   $4 &)r   r   r   r	   r   NN)r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r
   r   r   r   rI   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )	
__future__r   numpyr+   monai.transforms.utilsr   __all__r   r   rG   rG   rG   rH   <module>   s(   P