-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from johnnychen94/psnr
reduce pakcage dependencies and introduce psnr_equality
- Loading branch information
Showing
5 changed files
with
54 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
name = "ReferenceTests" | ||
uuid = "324d217c-45ce-50fc-942e-d289b448e8cf" | ||
authors = ["Christof Stocker <stocker.christof@gmail.com>", "Lyndon White <oxinabox@ucc.asn.au>"] | ||
version = "0.7.0" | ||
version = "0.8.0" | ||
|
||
[deps] | ||
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" | ||
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6" | ||
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" | ||
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" | ||
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" | ||
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" | ||
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[compat] | ||
ColorTypes = ">= 0.4" | ||
FileIO = ">= 0.4" | ||
ImageInTerminal = ">= 0.3" | ||
Images = ">= 0.15" | ||
julia = ">= 1.0" | ||
FileIO = "1" | ||
ImageCore = "0.8.1" | ||
ImageInTerminal = "0.3, 0.4" | ||
julia = "1" | ||
|
||
[extras] | ||
CSVFiles = "5d742f6a-9f54-50ce-8119-2520741973ca" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" | ||
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" | ||
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" | ||
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990" | ||
|
||
[targets] | ||
test = ["CSVFiles", "DataFrames", "FixedPointNumbers", "ImageMagick", "TestImages"] | ||
test = ["CSVFiles", "DataFrames", "ImageMagick", "ImageTransformations", "TestImages"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
function default_image_equality(reference, actual) | ||
try | ||
Images.@test_approx_eq_sigma_eps(reference, actual, ones(length(axes(actual))), 0.01) | ||
return true | ||
catch err | ||
if err isa ErrorException | ||
return false | ||
# --------------------------------- | ||
# Image | ||
|
||
default_image_equality(reference, actual) = psnr_equality()(reference, actual) | ||
|
||
""" | ||
psnr_equality(threshold=25) -> f | ||
Generates an equality comparison function in terms of Peak Signal-to-Noise Ratio (PSNR). | ||
The return function `f` accepts two images `reference` and `actual` as its inputs; | ||
`f(reference, actual) == true` if `psnr(reference, actual) >= threshold`. | ||
This function is useful for image comparison, for example: | ||
```julia | ||
@test_reference "references/camera.png" testimage("cameraman") by=psnr_equality(20) | ||
``` | ||
""" | ||
function psnr_equality(threshold=25) | ||
function (ref, x) | ||
rst = _psnr(ref, x) | ||
if rst >= threshold | ||
return true | ||
else | ||
rethrow() | ||
@warn("test fails because PSNR $rst < $threshold") | ||
return false | ||
end | ||
end | ||
end | ||
|
||
# a simplified PSNR is sufficient since we only use it to approximately compare two images | ||
_psnr(ref::AbstractArray{<:Color3}, x::AbstractArray{<:Color3}) = | ||
_psnr(channelview(RGB.(ref)), channelview(RGB.(x)), 1.0) | ||
|
||
_psnr(ref::AbstractArray{<:AbstractGray}, x::AbstractArray{<:AbstractGray}) = | ||
_psnr(channelview(ref), channelview(x), 1.0) | ||
|
||
_psnr(ref::AbstractArray{<:Real}, x::AbstractArray{<:Real}, peakval::Real) = | ||
20log10(peakval) - 10log10(euclidean(ref, x)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31901ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to tag a release here :D @Evizero
31901ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
31901ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/3934
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via: