o
    bi                     @   sr   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ed							
		dddZdS )    N)backend)ops)keras_export)draw_segmentation_masks)plot_image_galleryz2keras.visualization.plot_segmentation_mask_galleryr      T皙?c
                 K   sz  |	pt  }	t| }t|dkrtd| |	dkr"t| d} t|dkr,|d nd}|}d}|dur:|d7 }|durB|d7 }t| }tj	t
|||||d}|durk|	dkr`t|d}t|d	}|||}|dur|	dkryt|d}t|d	}|||}g }t|D ]}|||  |dur|||  |dur|||  qtj|dd
}t|f|||d|
S )a  Plots a gallery of images with corresponding segmentation masks.

    Args:
        images: A 4D tensor or NumPy array of images. Shape should be
            `(batch_size, height, width, channels)`.
        num_classes: The number of segmentation classes.  Class indices should
            start from `1`.  Class `0` will be treated as background and
            ignored if `ignore_index` is not 0.
        value_range: A tuple specifying the value range of the images
            (e.g., `(0, 255)` or `(0, 1)`). Defaults to `(0, 255)`.
        y_true: A 3D/4D tensor or NumPy array representing the ground truth
            segmentation masks. Shape should be `(batch_size, height, width)` or
            `(batch_size, height, width, 1)`. Defaults to `None`.
        y_pred: A 3D/4D tensor or NumPy array representing the predicted
            segmentation masks.  Shape should be the same as `y_true`.
            Defaults to `None`.
        color_mapping: A dictionary mapping class indices to RGB colors.
            If `None`, a default color palette is used. Class indices start
            from `1`. Defaults to `None`.
        blend: Whether to blend the masks with the input image using the
            `alpha` value. If `False`, the masks are drawn directly on the
            images without blending. Defaults to `True`.
        alpha: The opacity of the segmentation masks (a float between 0 and 1).
            Defaults to `0.8`.
        ignore_index: The class index to ignore when drawing masks.
            Defaults to `-1`.
        data_format: The image data format `"channels_last"` or
            `"channels_first"`. Defaults to the Keras backend data format.
        kwargs: Additional keyword arguments to be passed to
            `keras.visualization.plot_image_gallery`.

    Returns:
        The output of `keras.visualization.plot_image_gallery`.

    Raises:
        ValueError: If `images` is not a 4D tensor/array.
       z;`images` must be batched 4D tensor. Received: images.shape=channels_first)r            r   r   N)num_classescolor_mappingalphaignore_indexblendint32)axis)value_rangerowscols)r   image_data_formatr   shapelen
ValueError	transposeconvert_to_numpy	functoolspartialr   castrangeappendnpstackr   )imagesr   r   y_truey_predr   r   r   r   data_formatkwargsimage_shape
batch_sizer   r   	images_npdraw_masks_fntrue_masks_drawnpredicted_masks_drawnimages_with_masksigallery_images r5   j/home/ubuntu/.local/lib/python3.10/site-packages/keras/src/visualization/plot_segmentation_mask_gallery.pyplot_segmentation_mask_gallery   sh   3

	

r7   )r   NNNTr	   r
   N)r    numpyr%   	keras.srcr   r   keras.src.api_exportr   /keras.src.visualization.draw_segmentation_masksr   *keras.src.visualization.plot_image_galleryr   r7   r5   r5   r5   r6   <module>   s"    