SSIM (structural similarity) implementation for OpenCV 2.x. SSIM is used for image quality assessment, such as PSNR.
Detail of algorism and caliculation method are described in original paper, which is;
Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, "Image quality assessment: From error visibility to structural similarity," IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, Apr. 2004."
This code is wrapper of these implementations: [Mehdi Rabah's implimentation], [denshikA (Japanese)].
Implementation
Source code and project file for visual studio 2008
Every default parameter has same value of original Matlab code.
double calcSSIM (cv::Mat& src1, cv::Mat& src2, int channel = 0, int method=CV_BGR2YUV,cv::Mat& mask=cv::Mat(),const double K1 = 0.01, const double K2 = 0.03, const int L = 255, const int downsamplewidth=256, const int gaussian_window=11, const double gaussian_sigma=1.5, cv::Mat& ssim_map=cv::Mat())
return value
SSIM
src1
source image 1
src2
source image 2
channel
color channel for computing SSIM. If this value is ALLCHANNEL or -1, this function compute all color channels and average the values.
method
color converting method for RGB image
mask
If a pixel in this mask data is 0, the pixel does not affect SSIM result
K1
parameter of SSIM
K2
parameter of SSIM
L
parameter of SSIM
downsamplewidth
parameter of SSIM: max length of width or height are resized to have this value keeping aspect rate
gaussian_window
parameter of SSIM: window size of gaussian filter
gaussian_sigma
parameter of SSIM: sigma of gauusian filter
ssim_map
output ssim map
double calcSSIMBB(cv::Mat& src1, cv::Mat& src2, int channel = 0, int method=CV_BGR2YUV, int boundx=0,int boundy=0,const double K1 = 0.01, const double K2 = 0.03, const int L = 255, const int downsamplewidth=256, const int gaussian_window=11, const double gaussian_sigma=1.5, cv::Mat& ssim_map=cv::Mat()
boundx
create bounding box for mask data
boundy
create bounding box for mask data
Example for use
using default setting:
calcSSIM(im1,im2)
using bounding box(10,10), i.e. ignoring the border of 10 pixels, and computing green color channel in BGR color space for ssim:
calcSSIMBB(im1,im2,1,CV_BGR2RGB,10,10);
using mask and averaging YUV ssim:
calcSSIM(im1,im2,ALLCHANNEL,CV_BGR2YUV,mask);
Result
Through observation, there is approximately 1% error max with the original matlab program.
Original data, Zhou Wang's HP