o
    Ͱg                     @   sp   d dl Z d dlmZ d dlZd dlZd dlZd dl	Z	dd Z
dd Zddd	Zdd
dZedkr6ed dS dS )    Nc                 C   s   t jdddd\}}|d |  |d d |d d |d j|dd	 |d d
 |d d |d j|dd	 |d d |d d |d j|dd	 |d d |d d |  |S )a  
    Creates a 4-panel matplotlib figure comparing the original image,
    ground truth mask, model output, and thresholded output.

    :param image: Original image (PIL Image or NumPy array)
    :param gt_mask: Ground truth mask (NumPy array)
    :param pred_mask: Model output (NumPy array)
    :param thresholded_mask: Thresholded prediction mask (NumPy array)
    :return: Matplotlib figure
          )   r   figsizer   Original ImageoffgraycmapzGround Truth Mask   zModel Output   zThresholded Output)pltsubplotsimshow	set_titleaxistight_layout)imagegt_mask	pred_maskthresholded_maskfigaxes r   /C:\muni\DP\seg1\Segment1\utils\visualization.pycreate_segmentation_plot   s   r   c                 C   s   t jdddd\}}|d |  |d d |d d |d j|dd	 |d d
 |d d |d j|dd	 |d d |d d |S )aU  
    Creates a 3-panel matplotlib figure comparing:
    1. Original image
    2. Predicted mask
    3. Thresholded mask

    :param image: Original image (PIL Image or NumPy array)
    :param pred_mask: Model output mask (NumPy array)
    :param thresholded_mask: Thresholded prediction mask (NumPy array)
    :return: Matplotlib figure
    r   r   )
   r   r   r   r   r   r	   r
   zPredicted Maskr   zThresholded Mask)r   r   r   r   r   )r   r   r   r   r   r   r   r   create_segmentation_plot_test(   s   r   #~/DP/data/syn_3d.py/extracted_data/1.nii.gzc                 C   s   t tj| d|}t tj| d|}| }| }||  | |   }||  | |   }t	 }|j
|ddd |j
|ddd t  d S )Nrawsegr	   zNIfTI Image)colormapnameinfernoz
NIfTI Mask)nibloadospathjoinZ	get_fdataminmaxnapariViewer	add_imagerun)rootfilenameimgmaskZdata_imgZ	data_maskviewerr   r   r   show_niiD   s   r6   c                 C   s`   d}t | d|  d}t | d|  d}t }|j|dd |j|dd t  d S )Nz+C:/muni/DP/CS2Net/CS-Net/samples/validationz/image_z.npyz/pred_Image)r$   Z
Prediction)npr'   r-   r.   r/   r0   )idxr)   r   predr5   r   r   r   
show_predsW   s   r;   __main__r   )r   r    )r   )r(   matplotlib.pyplotpyplotr   Znibabelr&   torchnumpyr8   r-   r   r   r6   r;   __name__r   r   r   r   <module>   s     

