The Proof of the ssim_end1() in FFmpeg

这篇文章是对FFmpeg中计算SSIM算法中用到的公式的证明。其中的fs1fs1fs2fs2fs12fs12fssfss的含义和FFmpeg保持一致,具体可以参考FFmpeg如何计算图像的SSIM中的说明。

SSIM(a,b)=(2μaμb+C1)(2σab+C2)(μa2+μb2+C1)(σa2+σb2+C2)μa=164fs1μb=164fs2σa2+σb2=163(i,j(a(i,j)μa)2+i,j(b(i,j)μb)2)=163i,j(a(i,j)2+μa22a(i,j)μa+b(i,j)2+μb22b(i,j)μb)=163(i,j(a(i,j)2+b(i,j)2)2(μai,ja(i,j)+μbi,jb(i,j))+i,j(μa2+μb2))=163(fss2164(fs12+fs22)+164(fs12+fs22)=163(fss164(fs12+fs22))=163164(64fssfs12fs22)σab=163i,j((a(i,j)μa)(b(i,j)μb))=163i,j(a(i,j)b(i,j)a(i,j)μbb(i,j)μa+μaμb)=163(fs12fs1μbfs2μa+fs1μb)=163(fs12164fs1fs2)=163164(64fs12fs1fs2)SSIM(a,b)=(2fs1fs2+642C1)(264fs122fs1fs2+6364C2)(fs12+fs22+642C1)(64fssfs12fs22+6364C2)\begin{aligned} SSIM(a,b)&=\frac{(2\mu_a\mu_b+C_1)(2\sigma_{ab}+C_2)}{(\mu_a^2+\mu_b^2+C_1)(\sigma_a^2+\sigma_b^2+C_2)} \\ \mu_a&=\frac{1}{64}fs1 \\ \mu_b&=\frac{1}{64}fs2 \\ \sigma_a^2+\sigma_b^2&=\frac{1}{63}(\sum_{i,j}(a(i,j)-\mu_a)^2 + \sum_{i,j}(b(i,j)-\mu_b)^2) \\ &=\frac{1}{63}\sum_{i,j}(a(i,j)^2+\mu_a^2-2 \cdot a(i,j) \cdot \mu_a+b(i,j)^2+\mu_b^2-2 \cdot b(i,j) \cdot \mu_b) \\ &=\frac{1}{63}(\sum_{i,j}(a(i,j)^2+b(i,j)^2)-2(\mu_a\sum_{i,j}a(i,j)+\mu_b\sum_{i,j}b(i,j))+\sum_{i,j} (\mu_a^2+\mu_b^2)) \\ &=\frac{1}{63}(fss-2 \cdot \frac{1}{64}(fs1^2+fs2^2)+\frac{1}{64}(fs1^2+fs2^2) \\ &=\frac{1}{63}(fss-\frac{1}{64}(fs1^2+fs2^2)) \\ &=\frac{1}{63}\frac{1}{64}(64fss-fs1^2-fs2^2) \\ \sigma_{ab}&=\frac{1}{63}\sum_{i,j}((a(i,j)-\mu_a)(b(i,j)-\mu_b)) \\ &=\frac{1}{63}\sum_{i,j}(a(i,j) \cdot b(i,j)-a(i,j)\mu_b-b(i,j)\mu_a+\mu_a \cdot \mu_b) \\ &=\frac{1}{63}(fs12-fs1 \cdot \mu_b-fs2 \cdot \mu_a+fs1 \cdot \mu_b) \\ &=\frac{1}{63}(fs12-\frac{1}{64}fs1 \cdot fs2) \\ &=\frac{1}{63}\frac{1}{64}(64fs12-fs1 \cdot fs2) \\ \therefore SSIM(a,b)&=\frac{(2fs1 \cdot fs2+64^2C_1)(2 \cdot 64fs12-2fs1fs2+63 \cdot 64C_2)}{(fs1^2+fs2^2+64^2C_1)(64fss-fs1^2-fs2^2+63 \cdot 64C_2)} \end{aligned}

打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • Copyrights © 2020-2024 Wang Wei
  • 本站访问人数: | 本站浏览次数:

请我喝杯咖啡吧~

微信