Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
benchmark/tune.json
docs/build
docs/site
Manifest.toml
8 changes: 6 additions & 2 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using ImageFiltering
using PkgBenchmark
using TestImages, ImageTransformations
using BenchmarkTools

include("mapwindow.jl")
const SUITE = BenchmarkGroup(["ImageFIltering"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const SUITE = BenchmarkGroup(["ImageFIltering"])
const SUITE = BenchmarkGroup(["ImageFiltering"])


include("utils.jl")
include("imfilter.jl")
39 changes: 39 additions & 0 deletions benchmark/imfilter.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
SUITE["imfilter"] = BenchmarkGroup(["imfilter"])
SUITE["imfilter_naive"] = BenchmarkGroup(["imfilter", "naive implementation"])
SUITE["imfilter_naive"]["CPU1"] = BenchmarkGroup(["CPU", "single thread"])
SUITE["imfilter"]["CPU1"] = BenchmarkGroup(["CPU", "single thread"])
# SUITE["imfilter"]["CPUThread"] = BenchmarkGroup(["CPU", "multi threads"])
# SUITE["imfilter"]["CUDA"] = BenchmarkGroup(["GPU", "CUDA"])
# SUITE["imfilter"]["ArrayFire"] = BenchmarkGroup(["GPU", "ArrayFire"])
# SUITE["imfilter"]["OpenCL"] = BenchmarkGroup(["GPU", "OpenCL"])

img_gray_256 = testimage("lena_gray_256")
img_rgb_256 = testimage("lena_color_256")
img_list_gray = [imresize(img_gray_256, ratio=ratio) for ratio in (0.5, 1.0, 2.0, 4.0)]
img_list_rgb = [imresize(img_rgb_256, ratio=ratio) for ratio in (0.5, 1.0, 2.0, 4.0)]

default_kernel = centered(ones((31, 31))./prod((31, 31)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What led you to choose the sizes here? (Both for the kernel and the images in the lists.) If running time is a concern we could do everything with smaller images and/or kernels.


for (imfilter_impl, imfilter_name) in ((imfilter, "imfilter"),
(imfilter_naive, "imfilter_naive"))
SUITE[imfilter_name]["CPU1"]["image"] = BenchmarkGroup(["image"])
for img in img_list_gray
SUITE[imfilter_name]["CPU1"]["image"]["size", size(img)] =
@benchmarkable ($imfilter_impl)($img, default_kernel)
end

SUITE[imfilter_name]["CPU1"]["kernel"] = BenchmarkGroup(["kernel"])
for n in 1:2:19
w = 2n+1
kern = centered(ones((w, w))./prod((w, w)))
SUITE[imfilter_name]["CPU1"]["kernel"]["size", (w, w)] =
@benchmarkable ($imfilter_impl)(img_gray_256, $(kern))
end

SUITE[imfilter_name]["CPU1"]["padding"] = BenchmarkGroup(["padding style"])
for padding_style in ("replicate", "circular", "symmetric", "reflect")
# TODO: Inner(), NA(), NoPad()
SUITE[imfilter_name]["CPU1"]["padding"][padding_style] =
@benchmarkable ($imfilter_impl)(img_gray_256, default_kernel, $padding_style)
end
end
13 changes: 13 additions & 0 deletions benchmark/utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function imfilter_naive(img, kernel, padding_style=:replicate)
padding_size = (size(kernel).-1).÷2
out = similar(img)
R = CartesianIndices(img)
img = padarray(img, Pad(padding_style, padding_size, padding_size))
offset = last(CartesianIndices(kernel))
for p in R
patch = img[p-offset:p+offset]
patch = centered(patch)
out[p] = sum(patch .* kernel)
end
out
end