-
Notifications
You must be signed in to change notification settings - Fork 8
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 #37 from johnnychen94/moments
Refactor Moments using the functor API
- Loading branch information
Showing
5 changed files
with
78 additions
and
28 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,23 +1,69 @@ | ||
@testset "moments" begin | ||
original_image = testimage("lena") | ||
for T in (Gray{N0f8}, Gray{N0f16}, Gray{Float32}, Gray{Float64}) | ||
img = T.(original_image) | ||
img₀₁ = binarize(Moments(), img) | ||
@info "Test: Moments" | ||
|
||
# Check original image is unchanged. | ||
@test img == T.(testimage("lena")) | ||
@testset "API" begin | ||
img_gray = imresize(testimage("lena_gray_256"); ratio=0.25) | ||
img = copy(img_gray) | ||
|
||
# binarize | ||
f = Moments() | ||
binarized_img_1 = binarize(img, f) | ||
@test img == img_gray # img unchanged | ||
@test eltype(binarized_img_1) == Gray{N0f8} | ||
|
||
binarized_img_2 = binarize(Gray{Bool}, img, f) | ||
@test img == img_gray # img unchanged | ||
@test eltype(binarized_img_2) == Gray{Bool} | ||
|
||
binarized_img_3 = similar(img, Bool) | ||
binarize!(binarized_img_3, img, f) | ||
@test img == img_gray # img unchanged | ||
@test eltype(binarized_img_3) == Bool | ||
|
||
binarized_img_4 = copy(img_gray) | ||
binarize!(binarized_img_4, f) | ||
@test eltype(binarized_img_4) == Gray{N0f8} | ||
|
||
@test binarized_img_1 == binarized_img_2 | ||
@test binarized_img_1 == binarized_img_3 | ||
@test binarized_img_1 == binarized_img_4 | ||
end | ||
|
||
@testset "Types" begin | ||
# Gray | ||
img_gray = imresize(testimage("lena_gray_256"); ratio=0.25) | ||
f = Moments() | ||
|
||
type_list = generate_test_types([Float32, N0f8], [Gray]) | ||
for T in type_list | ||
img = T.(img_gray) | ||
@test_reference "References/Moments_Gray.png" Gray.(binarize(img, f)) | ||
end | ||
|
||
# Color3 | ||
img_color = imresize(testimage("lena_color_256"); ratio=0.25) | ||
f = Moments() | ||
|
||
type_list = generate_test_types([Float32, N0f8], [RGB, Lab]) | ||
for T in type_list | ||
img = T.(img_gray) | ||
@test_reference "References/Moments_Color3.png" Gray.(binarize(img, f)) | ||
end | ||
end | ||
|
||
@testset "Numerical" begin | ||
# Check that the image only has ones or zeros. | ||
img = imresize(testimage("lena_gray_256"); ratio=0.25) | ||
f = Moments() | ||
img₀₁ = binarize(img, f) | ||
non_zeros = findall(x -> x != 0.0 && x != 1.0, img₀₁) | ||
@test length(non_zeros) == 0 | ||
|
||
# Check type of binarized image. | ||
@test typeof(img₀₁) == Array{Gray{Bool},2} | ||
|
||
# Check that ones and zeros have been assigned to the correct side of the threshold. | ||
maxval, maxpos = findmax(Gray.(img)) | ||
@test img₀₁[maxpos] == 1 | ||
minval, minpos = findmin(Gray.(img)) | ||
@test img₀₁[minpos] == 0 | ||
end | ||
|
||
end |
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