JuliaTesting / ReferenceTests.jl

Utility package for comparing data against reference files
https://juliatesting.github.io/ReferenceTests.jl/latest/
Other
82 stars 14 forks source link

Missing psnr method for RGBA #102

Closed Octogonapus closed 2 years ago

Octogonapus commented 2 years ago

I ran into this missing _psnr method when comparing images: MethodError: no method matching _psnr(::Matrix{ColorTypes.RGBA{FixedPointNumbers.N0f8}}, ::Matrix{ColorTypes.RGBA{FixedPointNumbers.N0f8}})

Here's a possible implementation: _psnr(ref::AbstractArray{<:ColorTypes.RGBA}, x::AbstractArray{<:ColorTypes.RGBA}) = _psnr(ReferenceTests.channelview(ref), ReferenceTests.channelview(x), 1.0)

using ReferenceTests v0.9.8

johnnychen94 commented 2 years ago

I'm unsure of this. According to wikipedia, psnr is reported per-channel.

For color images with three RGB values per pixel, the definition of PSNR is the same except the MSE is the sum over all squared value differences (now for each color, i.e. three times as many differences as in a monochrome image) divided by image size and by three. Alternately, for color images the image is converted to a different color space and PSNR is reported against each channel of that color space, e.g., YCbCr or HSL.[1][2]

Maybe this is the case where you need to test against color.(img)?

Octogonapus commented 2 years ago

I used the precedent of the other psnr implementations on images: https://github.com/JuliaTesting/ReferenceTests.jl/blob/master/src/equality_metrics.jl#L51

johnnychen94 commented 2 years ago

hahaha! Yes! I'm more conservative in ImageQualityIndexes https://github.com/JuliaImages/ImageQualityIndexes.jl/blob/aca3975c8ef5b2adf1cfbf3a14be35025cd0445f/src/psnr.jl#L13-L20 but the psnr of this package is mainly to track the changes so people don't use it to do real image quality benchmarks.

Feel free to open a PR for this.