Opened 5 years ago
Last modified 4 months ago
#8529 open defect
the ssim_c1 has bug in vf_ssim.c
Reported by: | none | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | avfilter |
Version: | git-master | Keywords: | ssim |
Cc: | Blocked By: | ||
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug:
I'm learning the SSIM, and I find FFMpeg provides this capability in the vf_ssim.c and tiny_ssim.c. I analyzed the code of the tiny_ssim.c and find a bug for the define of the ssim_c1 variable in the
ssim_end1() function.
I recalculate the mathematical formula of SSIM according to the algorithm of tiny_ssim, and get the following formula:
SSIM(x,y)=((2*s1*s2+64*64*C1)(2*(64*s12-s1*s2)+64*63*C2))/((s1*s1+s2*s2+64*64*C1)(64*ss-s1*s1-s2*s2+64*63*C2))
Thus the ssim_c1 shoule be (.01*.01*PIXEL_MAX*PIXEL_MAX*64*64 + .5) instead of ssim_c1 = (int)(.01*.01*PIXEL_MAX*PIXEL_MAX*64 + .5).
How to reproduce:
static const int ssim_c1 = (int)(.01*.01*PIXEL_MAX*PIXEL_MAX*64*64 + .5);
Attachments (2)
Change History (8)
by , 5 years ago
Attachment: | tiny_ssim.jpg added |
---|
comment:1 by , 5 years ago
Keywords: | ssim added; ssim_c1 removed |
---|---|
Priority: | important → normal |
comment:3 by , 5 years ago
The proof of the formula is as the following link (ssim_end1() calculate the ssim for 8x8 block sums): https://wangwei1237.github.io/2020/02/18/the-proof-of-the-SSIM-in-FFMpeg/
Replying to richardpl:
I nowhere do not see proof of your claim.
comment:4 by , 5 years ago
So, c1 is defined as (k_1 * L)2, where k_1 is 0.01 and L is PIXEL_MAX (it is a define that is 255 for 8 bit). It means that everything is already squared... so it can be 64 == 8 * 8, dunno or maybe a comfortable shortcat. Anyway, you forgot + 0.5
comment:5 by , 5 years ago
Status: | new → open |
---|
Holy... https://github.com/wangwei1237/video_codec_evaluation/blob/1e02900b8212538104ed813733c5e2fefd1108ff/test/test_msssim.cpp#L99 looks like he really uses it, is there a way to check on smth obvious? For example smth like these images https://wangwei1237.github.io/2020/02/15/how-to-calculate-the-SSIM-in-FFMpeg/
comment:6 by , 4 months ago
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20240824112247.16237-2-aamastroberti@gmail.com/
Some new code and new metrics
Btw, here is this code above, commit from another fork https://github.com/bodhisatan/video_codec_evaluation/tree/1e02900b8212538104ed813733c5e2fefd1108ff
Oops
mathematical formula of the tiny_ssim