mmagic.evaluation.metrics.ssim
¶
Module Contents¶
Functions¶
|
Calculate SSIM (structural similarity) for one channel images. |
|
Calculate SSIM (structural similarity). |
- class mmagic.evaluation.metrics.ssim.SSIM(gt_key: str = 'gt_img', pred_key: str = 'pred_img', collect_device: str = 'cpu', prefix: Optional[str] = None, crop_border=0, input_order='CHW', convert_to=None)[source]¶
Bases:
mmagic.evaluation.metrics.base_sample_wise_metric.BaseSampleWiseMetric
Calculate SSIM (structural similarity).
Ref: Image quality assessment: From error visibility to structural similarity
The results are the same as that of the official released MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/.
For three-channel images, SSIM is calculated for each channel and then averaged.
- Parameters
gt_key (str) – Key of ground-truth. Default: ‘gt_img’
pred_key (str) – Key of prediction. Default: ‘pred_img’
collect_device (str) – Device name used for collecting results from different ranks during distributed training. Must be ‘cpu’ or ‘gpu’. Defaults to ‘cpu’.
prefix (str, optional) – The prefix that will be added in the metric names to disambiguate homonymous metrics of different evaluators. If prefix is not provided in the argument, self.default_prefix will be used instead. Default: None
crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the PSNR calculation. Default: 0.
input_order (str) – Whether the input order is ‘HWC’ or ‘CHW’. Default: ‘HWC’.
convert_to (str) – Whether to convert the images to other color models. If None, the images are not altered. When computing for ‘Y’, the images are assumed to be in BGR order. Options are ‘Y’ and None. Default: None.
- Metrics:
SSIM (float): Structural similarity
- mmagic.evaluation.metrics.ssim._ssim(img1, img2)[source]¶
Calculate SSIM (structural similarity) for one channel images.
It is called by func:ssim.
- Parameters
img1 (np.ndarray) – Images with range [0, 255] with order ‘HWC’.
img2 (np.ndarray) – Images with range [0, 255] with order ‘HWC’.
- Returns
SSIM result.
- Return type
float
- mmagic.evaluation.metrics.ssim.ssim(img1, img2, crop_border=0, input_order='HWC', convert_to=None, channel_order='rgb')[source]¶
Calculate SSIM (structural similarity).
Ref: Image quality assessment: From error visibility to structural similarity
The results are the same as that of the official released MATLAB code in https://ece.uwaterloo.ca/~z70wang/research/ssim/.
For three-channel images, SSIM is calculated for each channel and then averaged.
- Parameters
img1 (ndarray) – Images with range [0, 255].
img2 (ndarray) – Images with range [0, 255].
crop_border (int) – Cropped pixels in each edges of an image. These pixels are not involved in the SSIM calculation. Default: 0.
input_order (str) – Whether the input order is ‘HWC’ or ‘CHW’. Default: ‘HWC’.
convert_to (str) – Whether to convert the images to other color models. If None, the images are not altered. When computing for ‘Y’, the images are assumed to be in BGR order. Options are ‘Y’ and None. Default: None.
channel_order (str) – The channel order of image. Default: ‘rgb’
- Returns
SSIM result.
- Return type
float