From fe481318a55bc0ee07d3fae1fa9789edc1cc4f98 Mon Sep 17 00:00:00 2001 From: Dale Black Date: Tue, 19 Sep 2023 17:31:12 -0700 Subject: [PATCH] rm in favor of just fenz --- Manifest.toml | 284 ++++---- src/DistanceTransforms.jl | 14 +- src/borgefors.jl | 107 --- src/felzenszwalb.jl | 33 - src/maurer.jl | 8 +- src/utils.jl | 51 +- src/wenbo.jl | 1361 ------------------------------------- test/borgefors.jl | 110 --- test/felzenszwalb.jl | 226 ------ test/maurer.jl | 2 - test/runtests.jl | 4 +- test/utils.jl | 28 - test/wenbo.jl | 532 --------------- 13 files changed, 131 insertions(+), 2629 deletions(-) delete mode 100644 src/borgefors.jl delete mode 100644 src/wenbo.jl delete mode 100644 test/borgefors.jl delete mode 100644 test/wenbo.jl diff --git a/Manifest.toml b/Manifest.toml index 9722bf3..2ff20a1 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,8 +1,8 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.2" +julia_version = "1.9.3" manifest_format = "2.0" -project_hash = "d98f1de81a5659089b681e852b37b668393533be" +project_hash = "51de63795e2a4ac2d8f4a34019e1f3454df5b400" [[deps.AbstractFFTs]] deps = ["LinearAlgebra"] @@ -18,12 +18,6 @@ version = "1.5.0" ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[deps.AbstractPlutoDingetjes]] -deps = ["Pkg"] -git-tree-sha1 = "91bd53c39b9cbfb5ef4b015e8b582d344532bd0a" -uuid = "6e696c72-6542-2067-7265-42206c756150" -version = "1.2.0" - [[deps.Accessors]] deps = ["CompositionsBase", "ConstructionBase", "Dates", "InverseFunctions", "LinearAlgebra", "MacroTools", "Requires", "Test"] git-tree-sha1 = "954634616d5846d8e216df1298be2298d55280b2" @@ -145,21 +139,27 @@ version = "0.4.2" [[deps.CPUSummary]] deps = ["CpuId", "IfElse", "PrecompileTools", "Static"] -git-tree-sha1 = "89e0654ed8c7aebad6d5ad235d6242c2d737a928" +git-tree-sha1 = "601f7e7b3d36f18790e2caf83a882d88e9b71ff1" uuid = "2a0fbf3d-bb9c-48f3-b0a9-814d99fd7ab9" -version = "0.2.3" +version = "0.2.4" [[deps.CUDA]] -deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CUDA_Driver_jll", "CUDA_Runtime_Discovery", "CUDA_Runtime_jll", "ExprTools", "GPUArrays", "GPUCompiler", "KernelAbstractions", "LLVM", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "Preferences", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "SpecialFunctions", "UnsafeAtomicsLLVM"] -git-tree-sha1 = "35160ef0f03b14768abfd68b830f8e3940e8e0dc" +deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CUDA_Driver_jll", "CUDA_Runtime_Discovery", "CUDA_Runtime_jll", "Crayons", "DataFrames", "ExprTools", "GPUArrays", "GPUCompiler", "KernelAbstractions", "LLVM", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "NVTX", "Preferences", "PrettyTables", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "Statistics", "UnsafeAtomicsLLVM"] +git-tree-sha1 = "f062a48c26ae027f70c44f48f244862aec47bf99" uuid = "052768ef-5323-5732-b1bb-66c8b64840ba" -version = "4.4.0" +version = "5.0.0" + + [deps.CUDA.extensions] + SpecialFunctionsExt = "SpecialFunctions" + + [deps.CUDA.weakdeps] + SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" [[deps.CUDA_Driver_jll]] deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "Pkg"] -git-tree-sha1 = "498f45593f6ddc0adff64a9310bb6710e851781b" +git-tree-sha1 = "35a37bb72b35964f2895c12c687ae263b4ac170c" uuid = "4ee394cb-3365-5eb0-8335-949819d2adfc" -version = "0.5.0+1" +version = "0.6.0+3" [[deps.CUDA_Runtime_Discovery]] deps = ["Libdl"] @@ -169,9 +169,9 @@ version = "0.2.2" [[deps.CUDA_Runtime_jll]] deps = ["Artifacts", "CUDA_Driver_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] -git-tree-sha1 = "5248d9c45712e51e27ba9b30eebec65658c6ce29" +git-tree-sha1 = "bfe5a693a11522d58392f742243f2b50dc27afd6" uuid = "76a88914-d11a-5bdc-97e0-2f5a05c973a2" -version = "0.6.0+0" +version = "0.9.2+0" [[deps.CloseOpenIntervals]] deps = ["Static", "StaticArrayInterface"] @@ -179,12 +179,6 @@ git-tree-sha1 = "70232f82ffaab9dc52585e0dd043b5e0c6b714f1" uuid = "fb6a15b2-703c-40df-9091-08a04967cfa9" version = "0.1.12" -[[deps.CodeTracking]] -deps = ["InteractiveUtils", "UUIDs"] -git-tree-sha1 = "a1296f0fe01a4c3f9bf0dc2934efbf4416f5db31" -uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2" -version = "1.3.4" - [[deps.ColorTypes]] deps = ["FixedPointNumbers", "Random"] git-tree-sha1 = "eb7f0f8307f71fac7c606984ea5fb2817275d6e4" @@ -196,11 +190,13 @@ deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "Requires", "Statist git-tree-sha1 = "a1f44953f2382ebb937d60dafbe2deea4bd23249" uuid = "c3611d14-8923-5661-9e6a-0046d554d3a4" version = "0.10.0" -weakdeps = ["SpecialFunctions"] [deps.ColorVectorSpace.extensions] SpecialFunctionsExt = "SpecialFunctions" + [deps.ColorVectorSpace.weakdeps] + SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" + [[deps.Colors]] deps = ["ColorTypes", "FixedPointNumbers", "Reexport"] git-tree-sha1 = "fc08e5930ee9a4e03f84bfb5211cb54e7769758a" @@ -233,9 +229,9 @@ weakdeps = ["InverseFunctions"] [[deps.ConstructionBase]] deps = ["LinearAlgebra"] -git-tree-sha1 = "fe2838a593b5f776e1597e086dcd47560d94e816" +git-tree-sha1 = "c53fc348ca4d40d7b371e71fd52251839080cbc9" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" -version = "1.5.3" +version = "1.5.4" [deps.ConstructionBase.extensions] ConstructionBaseIntervalSetsExt = "IntervalSets" @@ -257,11 +253,22 @@ git-tree-sha1 = "fcbb72b032692610bfbdb15018ac16a36cf2e406" uuid = "adafc99b-e345-5852-983c-f28acb93d879" version = "0.3.1" +[[deps.Crayons]] +git-tree-sha1 = "249fe38abf76d48563e2f4556bebd215aa317e15" +uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" +version = "4.1.1" + [[deps.DataAPI]] git-tree-sha1 = "8da84edb865b0b5b0100c0666a9bc9a0b71c553c" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.15.0" +[[deps.DataFrames]] +deps = ["Compat", "DataAPI", "DataStructures", "Future", "InlineStrings", "InvertedIndices", "IteratorInterfaceExtensions", "LinearAlgebra", "Markdown", "Missings", "PooledArrays", "PrecompileTools", "PrettyTables", "Printf", "REPL", "Random", "Reexport", "SentinelArrays", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] +git-tree-sha1 = "04c738083f29f86e62c8afc341f0967d8717bdb8" +uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" +version = "1.6.1" + [[deps.DataStructures]] deps = ["Compat", "InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "3dbd312d370723b6bb43ba9d02fc36abade4518d" @@ -277,11 +284,6 @@ version = "1.0.0" deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" -[[deps.DeepDiffs]] -git-tree-sha1 = "9824894295b62a6a4ab6adf1c7bf337b3a9ca34c" -uuid = "ab62b9b5-e342-54a8-a765-a90f495de1a6" -version = "1.2.0" - [[deps.DefineSingletons]] git-tree-sha1 = "0fba8b706d0178b4dc7fd44a96a92382c9065c2c" uuid = "244e2a9f-e319-4986-a169-4d1fe445cd52" @@ -345,9 +347,9 @@ uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" [[deps.GPUArrays]] deps = ["Adapt", "GPUArraysCore", "LLVM", "LinearAlgebra", "Printf", "Random", "Reexport", "Serialization", "Statistics"] -git-tree-sha1 = "2e57b4a4f9cc15e85a24d603256fe08e527f48d1" +git-tree-sha1 = "8ad8f375ae365aa1eb2f42e2565a40b55a4b69a8" uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" -version = "8.8.1" +version = "9.0.0" [[deps.GPUArraysCore]] deps = ["Adapt"] @@ -357,9 +359,9 @@ version = "0.1.5" [[deps.GPUCompiler]] deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"] -git-tree-sha1 = "72b2e3c2ba583d1a7aa35129e56cf92e07c083e3" +git-tree-sha1 = "fa7dcf83344770adde87b256784155b194e05c9a" uuid = "61eb1bfa-7361-4325-ad38-22787b887f55" -version = "0.21.4" +version = "0.24.4" [[deps.HostCPUFeatures]] deps = ["BitTwiddlingConvenienceFunctions", "IfElse", "Libdl", "Static"] @@ -367,24 +369,6 @@ git-tree-sha1 = "eb8fed28f4994600e29beef49744639d985a04b2" uuid = "3e5b6fbb-0976-4d2c-9146-d79de83f2fb0" version = "0.1.16" -[[deps.Hyperscript]] -deps = ["Test"] -git-tree-sha1 = "8d511d5b81240fc8e6802386302675bdf47737b9" -uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91" -version = "0.0.4" - -[[deps.HypertextLiteral]] -deps = ["Tricks"] -git-tree-sha1 = "c47c5fa4c5308f27ccaac35504858d8914e102f9" -uuid = "ac1192a8-f4b3-4bfe-ba22-af5b92cd3ab2" -version = "0.9.4" - -[[deps.IOCapture]] -deps = ["Logging", "Random"] -git-tree-sha1 = "d75853a0bdbfb1ac815478bacd89cd27b550ace6" -uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" -version = "0.2.3" - [[deps.IfElse]] git-tree-sha1 = "debdd00ffef04665ccbb3e150747a77560e8fad1" uuid = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" @@ -407,6 +391,12 @@ git-tree-sha1 = "4da0f88e9a39111c2fa3add390ab15f3a44f3ca3" uuid = "22cec73e-a1b8-11e9-2c92-598750a2cf9c" version = "0.3.1" +[[deps.InlineStrings]] +deps = ["Parsers"] +git-tree-sha1 = "9cc2baf75c6d09f9da536ddf58eb2f29dedaf461" +uuid = "842dd82b-1e85-43dc-bf29-5d0ee9dffc48" +version = "1.4.0" + [[deps.InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" @@ -417,10 +407,10 @@ git-tree-sha1 = "68772f49f54b479fa88ace904f6127f0a3bb2e46" uuid = "3587e190-3f89-42d0-90ee-14403ec27112" version = "0.1.12" -[[deps.IrrationalConstants]] -git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2" -uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" -version = "0.2.2" +[[deps.InvertedIndices]] +git-tree-sha1 = "0dc7b50b8d436461be01300fd8cd45aa0274b038" +uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" +version = "1.3.0" [[deps.IteratorInterfaceExtensions]] git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" @@ -433,17 +423,11 @@ git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca" uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" version = "1.5.0" -[[deps.JSON]] -deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a" -uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.4" - -[[deps.JuliaInterpreter]] -deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "e8ab063deed72e14666f9d8af17bd5f9eab04392" -uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.9.24" +[[deps.JuliaNVTXCallbacks_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "af433a10f3942e882d3c671aacb203e006a5808f" +uuid = "9c1d0b0a-7046-5b2e-a33f-ea22f176ac7e" +version = "0.2.1+0" [[deps.JuliaVariables]] deps = ["MLStyle", "NameResolution"] @@ -465,15 +449,20 @@ version = "0.9.8" [[deps.LLVM]] deps = ["CEnum", "LLVMExtra_jll", "Libdl", "Printf", "Unicode"] -git-tree-sha1 = "8695a49bfe05a2dc0feeefd06b4ca6361a018729" +git-tree-sha1 = "a9d2ce1d5007b1e8f6c5b89c5a31ff8bd146db5c" uuid = "929cbde3-209d-540e-8aea-75f648917ca0" -version = "6.1.0" +version = "6.2.1" [[deps.LLVMExtra_jll]] deps = ["Artifacts", "JLLWrappers", "LazyArtifacts", "Libdl", "TOML"] -git-tree-sha1 = "c35203c1e1002747da220ffc3c0762ce7754b08c" +git-tree-sha1 = "7ca6850ae880cc99b59b88517545f91a52020afa" uuid = "dad2f222-ce93-54a1-a47d-0025e8a3acab" -version = "0.0.23+0" +version = "0.0.25+0" + +[[deps.LaTeXStrings]] +git-tree-sha1 = "f2355693d6778a178ade15952b7ac47a4ff97996" +uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" +version = "1.3.0" [[deps.LayoutPointers]] deps = ["ArrayInterface", "LinearAlgebra", "ManualMemory", "SIMDTypes", "Static", "StaticArrayInterface"] @@ -511,22 +500,6 @@ uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -[[deps.LogExpFunctions]] -deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] -git-tree-sha1 = "5ab83e1679320064c29e8973034357655743d22d" -uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" -version = "0.3.25" - - [deps.LogExpFunctions.extensions] - LogExpFunctionsChainRulesCoreExt = "ChainRulesCore" - LogExpFunctionsChangesOfVariablesExt = "ChangesOfVariables" - LogExpFunctionsInverseFunctionsExt = "InverseFunctions" - - [deps.LogExpFunctions.weakdeps] - ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" - ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" - InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" - [[deps.Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -545,17 +518,6 @@ version = "0.12.165" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" -[[deps.LoweredCodeUtils]] -deps = ["JuliaInterpreter"] -git-tree-sha1 = "60168780555f3e663c536500aa790b6368adc02a" -uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "2.3.0" - -[[deps.MIMEs]] -git-tree-sha1 = "65f28ad4b594aebe22157d6fac869786a255b7eb" -uuid = "6c6e2e6c-3030-632d-7369-2d6c69616d65" -version = "0.1.4" - [[deps.MLStyle]] git-tree-sha1 = "bc38dff0548128765760c79eb7388a4b37fae2c8" uuid = "d8e11817-5142-5d16-987a-aa16d5891078" @@ -563,9 +525,9 @@ version = "0.4.17" [[deps.MacroTools]] deps = ["Markdown", "Random"] -git-tree-sha1 = "42324d08725e200c23d4dfb549e0d5d89dede2d2" +git-tree-sha1 = "9ee1618cbf5240e6d4e0371d6f24065083f60c48" uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.10" +version = "0.5.11" [[deps.ManualMemory]] git-tree-sha1 = "bcaef4fc7a0cfe2cba636d84cda54b5e4e4ca3cd" @@ -592,8 +554,11 @@ git-tree-sha1 = "629afd7d10dbc6935ec59b32daeb33bc4460a42e" uuid = "128add7d-3638-4c79-886c-908ea0c25c34" version = "0.1.4" -[[deps.Mmap]] -uuid = "a63ad114-7e13-5084-954f-fe012c677804" +[[deps.Missings]] +deps = ["DataAPI"] +git-tree-sha1 = "f66bdc5de519e8f8ae43bdc598782d35a25b1272" +uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" +version = "1.1.0" [[deps.MosaicViews]] deps = ["MappedArrays", "OffsetArrays", "PaddedViews", "StackViews"] @@ -605,6 +570,18 @@ version = "0.3.4" uuid = "14a3606d-f60d-562e-9121-12d972cd8159" version = "2022.10.11" +[[deps.NVTX]] +deps = ["Colors", "JuliaNVTXCallbacks_jll", "Libdl", "NVTX_jll"] +git-tree-sha1 = "8bc9ce4233be3c63f8dcd78ccaf1b63a9c0baa34" +uuid = "5da4648a-3479-48b8-97b9-01cb529c0a1f" +version = "0.3.3" + +[[deps.NVTX_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "ce3269ed42816bf18d500c9f63418d4b0d9f5a3b" +uuid = "e98f9f5b-d649-5603-91fd-7774390e6439" +version = "3.1.0+2" + [[deps.NameResolution]] deps = ["PrettyPrint"] git-tree-sha1 = "1a0fa0e9613f46c9b8c11eee38ebb4f590013c5e" @@ -626,17 +603,6 @@ deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" version = "0.3.21+4" -[[deps.OpenLibm_jll]] -deps = ["Artifacts", "Libdl"] -uuid = "05823500-19ac-5b8b-9628-191a04bc5112" -version = "0.8.1+0" - -[[deps.OpenSpecFun_jll]] -deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] -git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" -uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" -version = "0.5.5+0" - [[deps.OrderedCollections]] git-tree-sha1 = "2e73fe17cac3c62ad1aebe70d44c963c3cfdc3e3" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" @@ -659,23 +625,23 @@ deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", " uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" version = "1.9.2" -[[deps.PlutoUI]] -deps = ["AbstractPlutoDingetjes", "Base64", "ColorTypes", "Dates", "FixedPointNumbers", "Hyperscript", "HypertextLiteral", "IOCapture", "InteractiveUtils", "JSON", "Logging", "MIMEs", "Markdown", "Random", "Reexport", "URIs", "UUIDs"] -git-tree-sha1 = "e47cd150dbe0443c3a3651bc5b9cbd5576ab75b7" -uuid = "7f904dfe-b85e-4ff6-b463-dae2292396a8" -version = "0.7.52" - [[deps.PolyesterWeave]] deps = ["BitTwiddlingConvenienceFunctions", "CPUSummary", "IfElse", "Static", "ThreadingUtilities"] git-tree-sha1 = "240d7170f5ffdb285f9427b92333c3463bf65bf6" uuid = "1d0040c9-8b98-4ee7-8388-3f51789ca0ad" version = "0.2.1" +[[deps.PooledArrays]] +deps = ["DataAPI", "Future"] +git-tree-sha1 = "36d8b4b899628fb92c2749eb488d884a926614d3" +uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" +version = "1.4.3" + [[deps.PrecompileTools]] deps = ["Preferences"] -git-tree-sha1 = "9673d39decc5feece56ef3940e5dafba15ba0f81" +git-tree-sha1 = "03b4c25b43cb84cee5c90aa9b5ea0a78fd848d2f" uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" -version = "1.1.2" +version = "1.2.0" [[deps.Preferences]] deps = ["TOML"] @@ -688,6 +654,12 @@ git-tree-sha1 = "632eb4abab3449ab30c5e1afaa874f0b98b586e4" uuid = "8162dcfd-2161-5ef2-ae6c-7681170c5f98" version = "0.2.0" +[[deps.PrettyTables]] +deps = ["Crayons", "LaTeXStrings", "Markdown", "Printf", "Reexport", "StringManipulation", "Tables"] +git-tree-sha1 = "ee094908d720185ddbdc58dbe0c1cbe35453ec7a" +uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" +version = "2.2.7" + [[deps.Printf]] deps = ["Unicode"] uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" @@ -723,12 +695,6 @@ git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7" uuid = "ae029012-a4dd-5104-9daa-d747884805df" version = "1.3.0" -[[deps.Revise]] -deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"] -git-tree-sha1 = "1e597b93700fa4045d7189afa7c004e0584ea548" -uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" -version = "3.5.3" - [[deps.SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" version = "0.7.0" @@ -750,6 +716,12 @@ git-tree-sha1 = "30449ee12237627992a99d5e30ae63e4d78cd24a" uuid = "6c6a2e73-6563-6170-7368-637461726353" version = "1.2.0" +[[deps.SentinelArrays]] +deps = ["Dates", "Random"] +git-tree-sha1 = "04bdff0b09c65ff3e06a05e3eb7b120223da3d39" +uuid = "91c51154-3ec4-41a3-a24f-3f23e20d615c" +version = "1.4.0" + [[deps.Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -768,22 +740,16 @@ version = "1.0.3" [[deps.Sockets]] uuid = "6462fe0b-24de-5631-8697-dd941f90decc" +[[deps.SortingAlgorithms]] +deps = ["DataStructures"] +git-tree-sha1 = "c60ec5c62180f27efea3ba2908480f8055e17cee" +uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" +version = "1.1.1" + [[deps.SparseArrays]] deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -[[deps.SpecialFunctions]] -deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] -git-tree-sha1 = "e2cfc4012a19088254b3950b85c3c1d8882d864d" -uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "2.3.1" - - [deps.SpecialFunctions.extensions] - SpecialFunctionsChainRulesCoreExt = "ChainRulesCore" - - [deps.SpecialFunctions.weakdeps] - ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" - [[deps.SplittablesBase]] deps = ["Setfield", "Test"] git-tree-sha1 = "e08a62abc517eb79667d0a29dc08a3b589516bb5" @@ -803,10 +769,10 @@ uuid = "aedffcd0-7271-4cad-89d0-dc628f76c6d3" version = "0.8.8" [[deps.StaticArrayInterface]] -deps = ["ArrayInterface", "Compat", "IfElse", "LinearAlgebra", "Requires", "SnoopPrecompile", "SparseArrays", "Static", "SuiteSparse"] -git-tree-sha1 = "33040351d2403b84afce74dae2e22d3f5b18edcb" +deps = ["ArrayInterface", "Compat", "IfElse", "LinearAlgebra", "PrecompileTools", "Requires", "SparseArrays", "Static", "SuiteSparse"] +git-tree-sha1 = "03fec6800a986d191f64f5c0996b59ed526eda25" uuid = "0d7ed370-da01-4f52-bd93-41d350b8b718" -version = "1.4.0" +version = "1.4.1" weakdeps = ["OffsetArrays", "StaticArrays"] [deps.StaticArrayInterface.extensions] @@ -815,9 +781,9 @@ weakdeps = ["OffsetArrays", "StaticArrays"] [[deps.StaticArrays]] deps = ["LinearAlgebra", "Random", "StaticArraysCore"] -git-tree-sha1 = "9cabadf6e7cd2349b6cf49f1915ad2028d65e881" +git-tree-sha1 = "51621cca8651d9e334a659443a74ce50a3b6dfab" uuid = "90137ffa-7385-5640-81b9-e52037218182" -version = "1.6.2" +version = "1.6.3" weakdeps = ["Statistics"] [deps.StaticArrays.extensions] @@ -833,6 +799,12 @@ deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" version = "1.9.0" +[[deps.StringManipulation]] +deps = ["PrecompileTools"] +git-tree-sha1 = "a04cabe79c5f01f4d723cc6704070ada0b9d46d5" +uuid = "892a3eda-7b42-436c-8928-eab12a02cf0e" +version = "0.3.4" + [[deps.SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" @@ -854,10 +826,10 @@ uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" version = "1.0.1" [[deps.Tables]] -deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits", "Test"] -git-tree-sha1 = "1544b926975372da01227b382066ab70e574a3ec" +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "OrderedCollections", "TableTraits"] +git-tree-sha1 = "a1f34829d5ac0ef499f6d84428bd6b4c71f02ead" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "1.10.1" +version = "1.11.0" [[deps.Tar]] deps = ["ArgTools", "SHA"] @@ -874,12 +846,6 @@ version = "0.1.1" deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[deps.TestSetExtensions]] -deps = ["DeepDiffs", "Distributed", "Test"] -git-tree-sha1 = "3a2919a78b04c29a1a57b05e1618e473162b15d0" -uuid = "98d24dd4-01ad-11ea-1b02-c9a08f80db04" -version = "2.0.0" - [[deps.ThreadingUtilities]] deps = ["ManualMemory"] git-tree-sha1 = "eda08f7e9818eb53661b3deb74e3159460dfbc27" @@ -918,16 +884,6 @@ version = "0.4.78" OnlineStatsBase = "925886fa-5bf2-5e8e-b522-a9147a512338" Referenceables = "42d2dcc6-99eb-4e98-b66c-637b7d73030e" -[[deps.Tricks]] -git-tree-sha1 = "aadb748be58b492045b4f56166b5188aa63ce549" -uuid = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775" -version = "0.1.7" - -[[deps.URIs]] -git-tree-sha1 = "b7a5e99f24892b6824a954199a45e9ffcc1c70f0" -uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" -version = "1.5.0" - [[deps.UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" diff --git a/src/DistanceTransforms.jl b/src/DistanceTransforms.jl index 5f4ad5b..18c409f 100644 --- a/src/DistanceTransforms.jl +++ b/src/DistanceTransforms.jl @@ -1,22 +1,15 @@ module DistanceTransforms -using CUDA -using FLoops -# using FoldsCUDA +abstract type DistanceTransform end -include("./borgefors.jl") include("./felzenszwalb.jl") include("./maurer.jl") include("./utils.jl") -include("./wenbo.jl") export DistanceTransform, transform, transform!, - # Export chamfer.jl functions - Borgefors, - # Export maurer.jl functions Maurer, @@ -24,8 +17,5 @@ export DistanceTransform, Felzenszwalb, # Export utils.jl functions - boolean_indicator, - - # Export wenbo.jl functions - Wenbo + boolean_indicator end diff --git a/src/borgefors.jl b/src/borgefors.jl deleted file mode 100644 index 2fdf9e7..0000000 --- a/src/borgefors.jl +++ /dev/null @@ -1,107 +0,0 @@ - -""" -## DistanceTransform - -```julia -abstract type DistanceTransform end -``` -Main type for all distance transforms -""" -abstract type DistanceTransform end - - -""" -## Borgefors - -```julia -struct Borgefors{T} <: DistanceTransform end -``` - -Prepares an array to be `transform`ed using the 3-4 chamfer algorithm laid out in 'Distance transformations in digital images, Computer Vision, Graphics, and Image Processing' [Gunilla Borgefors](https://studentportalen.uu.se/uusp-filearea-tool/download.action?nodeId=214320&toolAttachmentId=64777) -""" -struct Borgefors <: DistanceTransform end - - -""" -## transform (Borgefors) -```julia -transform(img::AbstractMatrix, dt::AbstractMatrix, tfm::Borgefors) - -transform(img::AbstractArray, dt::AbstractArray, tfm::Borgefors) -``` - -2D chamfer distance transform using the 3-4 chamfer algorithm laid out in 'Distance transformations in digital images, Computer Vision, Graphics, and Image Processing' [Gunilla Borgefors](https://studentportalen.uu.se/uusp-filearea-tool/download.action?nodeId=214320&toolAttachmentId=64777) - -3D chamfer distance transform using the 3-4 chamfer algorithm laid out in 'Distance transformations in digital images, Computer Vision, Graphics, and Image Processing' [Gunilla Borgefors](https://studentportalen.uu.se/uusp-filearea-tool/download.action?nodeId=214320&toolAttachmentId=64777) -""" -function transform(img::AbstractMatrix, dt::AbstractMatrix, tfm::Borgefors) - w, h = size(img) - # Forward pass - x = 1 - y = 1 - if img[x, y] == 0 - dt[x, y] = 65535 # some large value - end - for x in 1:(w - 1) - if img[x + 1, y] == 0 - dt[x + 1, y] = 3 + dt[x, y] - end - end - for y in 1:(h - 1) - x = 1 - if img[x, y + 1] == 0 - dt[x, y + 1] = min(3 + dt[x, y], 4 + dt[x + 1, y]) - end - for x in 1:(w - 2) - if img[x + 1, y + 1] == 0 - dt[x + 1, y + 1] = min( - 4 + dt[x, y], 3 + dt[x + 1, y], 4 + dt[x + 2, y], 3 + dt[x, y + 1] - ) - end - end - x = w - - if img[x, y + 1] == 0 - dt[x, y + 1] = min(4 + dt[x - 1, y], 3 + dt[x, y], 3 + dt[x - 1, y + 1]) - end - end - - # Backward pass - for x in (w - 1):-1:1 - y = h - if img[x, y] == 0 - dt[x, y] = min(dt[x, y], 3 + dt[x + 1, y]) - end - end - for y in (h - 1):-1:1 - x = w - if img[x, y] == 0 - dt[x, y] = min(dt[x, y], 3 + dt[x, y + 1], 4 + dt[x - 1, y + 1]) - end - for x in 1:(w - 2) - if img[x + 1, y] == 0 - dt[x + 1, y] = min( - dt[x + 1, y], - 4 + dt[x + 2, y + 1], - 3 + dt[x + 1, y + 1], - 4 + dt[x, y + 1], - 3 + dt[x + 2, y], - ) - end - end - x = 1 - if img[x, y] == 0 - dt[x, y] = min( - dt[x, y], 4 + dt[x + 1, y + 1], 3 + dt[x, y + 1], 3 + dt[x + 1, y] - ) - end - end - return dt -end - -function transform(img::AbstractArray, dt::AbstractArray, tfm::Borgefors) - for z in 1:size(img)[3] - dt[:, :, z] = transform(img[:, :, z], dt[:, :, z], tfm) - end - return dt -end diff --git a/src/felzenszwalb.jl b/src/felzenszwalb.jl index cf41724..e899fe5 100644 --- a/src/felzenszwalb.jl +++ b/src/felzenszwalb.jl @@ -1,7 +1,5 @@ - using FLoops using CUDA -using FoldsThreads """ ## Felzenszwalb @@ -184,34 +182,3 @@ function transform(vol::CuArray{T, 3}, tfm::Felzenszwalb; output=similar(vol, Fl end return output end - -function transform(img::AbstractMatrix, tfm::Felzenszwalb, ex; output=similar(img, Float32), v=ones(size(img)), z=ones(size(img) .+ 1)) - # 1 - @floop ex for k in CartesianIndices(@view(img[:, 1])) - @views transform(img[k,:], tfm; output=output[k,:], v=v[k,:], z=z[k,:]) - end - output2 = similar(output) - # 2 - @floop ex for k in CartesianIndices(@view(img[1, :])) - @views transform(output[:,k], tfm; output=output2[:,k], v=fill!(v[:,k], 1), z=fill!(z[:,k], 1)) - end - # end - return output2 -end - -function transform(vol::AbstractArray, tfm::Felzenszwalb, ex; output=similar(vol, Float32), v=ones(size(vol)), z=ones(size(vol) .+ 1)) - # 1 - @floop ex for k in CartesianIndices(@view(vol[1,:,:])) - @views transform(vol[:, k], tfm; output=output[:, k], v=v[:, k], z=z[:, k]) - end - output2 = similar(output) - # 2 - @floop ex for k in CartesianIndices(@view(vol[:,1,:])) - @views transform(output[k[1], :, k[2]], tfm; output=output2[k[1], :, k[2]], v=fill!(v[k[1], :, k[2]], 1), z=fill!(z[k[1], :, k[2]], 1)) - end - # 3 - @floop ex for k in CartesianIndices(@view(vol[:,:,1])) - @views transform(output2[k, :], tfm; output=output[k, :], v=fill!(v[k, :], 1), z=fill!(z[k, :], 1)) - end - return output -end diff --git a/src/maurer.jl b/src/maurer.jl index 0a27d27..55ae63d 100644 --- a/src/maurer.jl +++ b/src/maurer.jl @@ -6,26 +6,24 @@ using ImageMorphology ```julia struct Maurer <: DistanceTransform end ``` - Wrapper function for `ImageMorphology.feature_transform` and `ImageMorphology.distance_transform`. Applies a true Euclidean distance transform to the array elements and returns an array with spatial information embedded in the elements. """ struct Maurer <: DistanceTransform end """ -## transform (Maurer) +## transform (Felzenszwalb) ```julia transform(img, tfm::Maurer) - transform(img::BitArray, tfm::Maurer) ``` Wrapper function for `ImageMorphology.feature_transform` and `ImageMorphology.distance_transform`. Applies a true Euclidean distance transform to the array elements and returns an array with spatial information embedded in the elements. -Arguments +#### Arguments - img: N-dimensional array to be transformed based on location to the nearest background (0) pixel -Citation +#### Citation - 'A Linear Time Algorithm for Computing Exact Euclidean Distance Transforms of Binary Images in Arbitrary Dimensions' [Maurer et al., 2003] (DOI: 10.1109/TPAMI.2003.1177156) """ transform(img, tfm::Maurer) = distance_transform(feature_transform(Bool.(img))) diff --git a/src/utils.jl b/src/utils.jl index 504e422..4d3691b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,48 +1,14 @@ -### A Pluto.jl notebook ### -# v0.19.8 +using LoopVectorization -using Markdown -using InteractiveUtils - -# ╔═╡ 4b4b6c39-e155-462a-b0ad-65688c949577 -# ╠═╡ show_logs = false -begin - using Pkg - Pkg.activate("..") - using Revise - using PlutoUI - using Test - using CUDA - using DistanceTransforms - using LoopVectorization -end - -# ╔═╡ 4db00b10-0440-4f28-bf91-01dca21847b0 -TableOfContents() - -# ╔═╡ 64661943-81d4-40c5-9479-fcc381544185 -md""" -## Boolean Indicator -""" - -# ╔═╡ 5f558b4b-d109-45d7-b2f8-fa03c0ff5db6 -begin """ -```julia -boolean_indicator(f) -``` + boolean_indicator(f) + boolean_indicator(f::BitArray) -If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10` +If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10`. +Uses LoopVectorization.jl for speed up if array is `BitArray` """ boolean_indicator(f) = @. ifelse(f < 0.5, 1.0f10, 0.0f0) -""" -```julia -boolean_indicator(f::BitArray) -``` - -If `f` is a boolean indicator where 0's correspond to background and 1s correspond to the foreground, then mark background pixels with a large number `1e10`. Uses LoopVectorization.jl for speed up -""" function boolean_indicator(f::BitArray) f_new = similar(f, Float32) @turbo warn_check_args=false for i in CartesianIndices(f_new) @@ -50,10 +16,3 @@ function boolean_indicator(f::BitArray) end return f_new end -end - -# ╔═╡ Cell order: -# ╠═4b4b6c39-e155-462a-b0ad-65688c949577 -# ╠═4db00b10-0440-4f28-bf91-01dca21847b0 -# ╟─64661943-81d4-40c5-9479-fcc381544185 -# ╠═5f558b4b-d109-45d7-b2f8-fa03c0ff5db6 diff --git a/src/wenbo.jl b/src/wenbo.jl deleted file mode 100644 index efb91a8..0000000 --- a/src/wenbo.jl +++ /dev/null @@ -1,1361 +0,0 @@ -# ### A Pluto.jl notebook ### -# # v0.19.14 - -# using Markdown -# using InteractiveUtils - -# # ╔═╡ 19f1c4b6-23c4-11ed-02f2-fb3e9263a1a1 -# # ╠═╡ show_logs = false -# begin -# using Pkg -# Pkg.activate("..") -# using Revise -# using PlutoUI -# using Test -# using DistanceTransforms -# using FLoops -# using CUDA -# using FoldsThreads -# end - -# # ╔═╡ 69d06c40-9861-41d5-b1c3-cc7b7ccd1d48 -# TableOfContents() - -# # ╔═╡ 8e63a0f7-9c14-4817-9053-712d5d306a90 -# md""" -# # `Wenbo` -# """ - -# # ╔═╡ 26ee61d8-10ee-411a-9d60-0d2c0b8a6833 -# """ -# ```julia -# struct Wenbo <: DistanceTransform end -# ``` -# Prepares an array to be `transform`ed -# """ -# struct Wenbo <: DistanceTransform end - -# # ╔═╡ 86168cdf-7f07-42bf-81ee-6fae7d68cebd -# md""" -# ## CPU -# """ - -# # ╔═╡ fa21c417-6b0e-48a0-8993-f13c995141a6 -# md""" -# ### 1D -# """ - -# # ╔═╡ 0ea3985d-8361-4511-8e28-07418e2f2539 -# function _fill_with_inf(f::AbstractVector) -# f .= 1f10 -# return false -# end - -# # ╔═╡ 9db7eb7e-e47d-4e8d-81c0-f597eae51c04 -# function _transform1!(f::AbstractVector, f_org::AbstractVector, l) -# pointerA = 1 -# while pointerA <= l -# while pointerA <= l && @inbounds f_org[pointerA] >= 0.5 -# f[pointerA] = 0f0 -# pointerA+=1 -# end -# pointerB = pointerA -# while pointerB <= l && @inbounds f_org[pointerB] < 0.5 -# pointerB+=1 -# end -# if pointerB > l -# pointerA != 1 || return _fill_with_inf(f) -# i = pointerA -# temp=i-1 -# l = length(f) -# while i<=l -# @inbounds f[i]=(i-temp)^2 -# i+=1 -# end -# else -# if pointerA == 1 -# j = pointerB-1 -# temp=j+1 -# while j>0 -# @inbounds f[j]=(temp-j)^2 -# j-=1 -# end -# else -# i, j = pointerA, pointerB-1 -# temp=1 -# while(i<=j) -# @inbounds f[i]=f[j]=temp^2 -# temp+=1 -# i+=1 -# j-=1 -# end -# end -# end -# pointerA=pointerB -# end -# return true -# end - -# # ╔═╡ 167c008e-5a5f-4ba1-b1ff-2ae137b10c98 -# """ -# ```julia -# transform(f::AbstractVector, tfm::Wenbo) -# ``` - -# Applies a squared euclidean distance transform to an input 1D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. -# """ -# function transform(f_org::AbstractVector, tfm::Wenbo) -# l = size(f_org)[1] -# f = Array{Float32}(undef, l) -# _transform1!(f, f_org, l) -# return f -# end - -# # ╔═╡ cf740dd8-79bb-4dd8-b40c-7efcf7844256 -# md""" -# ### 2D -# """ - -# # ╔═╡ 16991d8b-ec84-49d0-90a9-15a78f1668bb -# function _encode(leftD::Float32, rightf::Float32) -# rightf != 1f10 || return -leftD -# rightf -= leftD -# idx = 1f0 -# while (rightf /= 10f0) >= 1f0 -# idx += 1f0 -# end -# return -leftD-idx/10f0-rightf/10f0 -# end - -# # ╔═╡ e7dbc916-c5cb-4f86-8ea1-adbcb0bdf8ea -# function _decode(curr::Float32) -# curr = abs(curr) -# new_d = floor(curr) -# curr -= new_d -# curr *= 10f0 -# temp = floor(curr % 10f0) -# temp != 0f0 || return 1f10 -# curr -= temp -# curr *= 10f0 -# while (temp-=1f0) > 0f0 -# curr *= 10f0 -# end -# return round(curr)+new_d -# end - -# # ╔═╡ 32a4bf03-98f8-4ed9-9c12-f45c09b0b0dd -# function _transform2!(f::AbstractVector, org::AbstractVector, l, d_left, d_right) -# pointerA = 0 -# # left section -# p = d_left - 1 -# templ = d_right -# while 0 < p -# templ -= 1 -# pointerA += 1 -# curr = 1f10 -# # right -# temp = p -# while temp <= templ && (curr==1f10 || muladd(temp, temp, -curr)<0) -# @inbounds curr = min(curr, muladd(temp, temp, f[pointerA+temp])) -# temp += 1 -# end -# @inbounds f[pointerA] = curr -# p -= 1 -# end -# pointerA += 1 -# # mid section -# while pointerA<=d_right && @inbounds f[pointerA] <= 1f0 -# pointerA += 1 -# end -# p = 0 -# while pointerA<=d_right -# @inbounds curr = f[pointerA] -# prev = curr -# # left -# temp = min(pointerA-d_left, p+1) -# p = 0 -# while 0 < temp -# @inbounds newDistance = muladd(temp, temp, org[pointerA-temp]) -# if newDistance < curr -# curr = newDistance -# p = temp -# end -# temp -= 1 -# end -# # right -# temp = 1 -# templ = d_right - pointerA -# while temp <= templ && muladd(temp, temp, -curr) < 0 -# @inbounds curr = min(curr, muladd(temp, temp, f[pointerA+temp])) -# temp += 1 -# end -# # record -# f[pointerA] = curr -# pointerA+=1 -# while pointerA<=d_right && @inbounds f[pointerA] <= 1f0 -# pointerA += 1 -# p += 1 -# end -# end -# # right section -# templ = pointerA-d_right -# while pointerA <= l -# curr = 1f10 -# # left -# temp = p+1 -# while templ <= temp -# newDistance = muladd(temp, temp, org[pointerA-temp]) -# if newDistance < curr -# curr = newDistance -# p = temp -# end -# temp -= 1 -# end -# @inbounds f[pointerA] = curr -# pointerA += 1 -# templ += 1 -# end -# end - -# # ╔═╡ 89fed2a6-b09e-47b1-a020-efed76ba57de -# function _transform2_EN_DE!(f::AbstractVector, l, d_left, d_right) -# pointerA = 0 -# # left section -# p = d_left - 1 -# templ = d_right -# while 0 < p -# templ -= 1 -# pointerA += 1 -# curr = 1f10 -# # right -# temp = p -# while temp <= templ && (curr==1f10 || muladd(temp, temp, -curr)<0) -# @inbounds curr = min(curr, muladd(temp, temp, f[pointerA+temp])) -# temp += 1 -# end -# @inbounds f[pointerA] = curr -# p -= 1 -# end -# pointerA += 1 -# # mid section -# while pointerA<=d_right && @inbounds f[pointerA] <= 1f0 -# pointerA += 1 -# end -# p = 0 -# while pointerA<=d_right -# @inbounds curr = f[pointerA] -# prev = curr -# # left -# temp = min(pointerA-d_left, p+1) -# p = 0 -# while 0 < temp -# @inbounds fi = f[pointerA-temp] -# fi = fi < 0f0 ? _decode(fi) : fi -# newDistance = muladd(temp, temp, fi) -# if newDistance < curr -# curr = newDistance -# p = temp -# end -# temp -= 1 -# end -# # right -# temp = 1 -# templ = d_right - pointerA -# while temp <= templ && muladd(temp, temp, -curr) < 0 -# @inbounds curr = min(curr, muladd(temp, temp, f[pointerA+temp])) -# temp += 1 -# end -# # record -# curr == prev || (@inbounds f[pointerA] = _encode(curr, prev)) -# pointerA+=1 -# while pointerA<=d_right && @inbounds f[pointerA] <= 1f0 -# pointerA += 1 -# p += 1 -# end -# end -# # right section -# dp_cache = Array{Float32}(undef, p+1) -# left_bound = pointerA-p-2 -# i = left_bound+1 -# while i <= left_bound+p+1 -# @inbounds fi = f[i] -# fi = fi < 0 ? _decode(fi) : fi -# dp_cache[i-left_bound] = fi -# i += 1 -# end - - -# templ = pointerA-d_right -# while pointerA <= l -# # println("pointerA = $pointerA, p = $p") -# curr = 1f10 -# # left -# temp = p+1 -# while templ <= temp -# @inbounds fi = dp_cache[pointerA-temp - left_bound] -# # @inbounds fi = f[pointerA-temp] -# # fi = fi < 0 ? _decode_32(fi) : fi -# newDistance = muladd(temp, temp, fi) -# if newDistance < curr -# curr = newDistance -# p = temp -# end -# temp -= 1 -# end -# @inbounds f[pointerA] = curr -# pointerA += 1 -# templ += 1 -# end -# # record -# i = d_left -# while i<=d_right -# f[i] = floor(abs(f[i])) -# i+=1 -# end -# end - -# # ╔═╡ edd255fa-e1bc-45f0-8b3a-92be5084dc23 -# function _set_bound_2D_1!(flags, l) -# idx = 0 -# while idx < l -# @inbounds flags[idx+=1] && return idx -# end -# return 0 -# end - -# # ╔═╡ a3fd1e1c-4cbb-4310-b6be-a4e61d43e8a5 -# function _set_bound_2D_2!(flags, l) -# idx = l+1 -# while idx > 1 -# @inbounds flags[idx-=1] && return idx -# end -# return 0 -# end - -# # ╔═╡ 423df2ac-b9a2-4d59-b5fc-8de0e8cc6691 -# """ -# ```julia -# transform(f::AbstractMatrix, tfm::Wenbo) -# ``` - -# Applies a squared euclidean distance transform to an input 2D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. -# """ -# function transform(f_org::AbstractMatrix, tfm::Wenbo) -# l, l2 = size(f_org) -# f = Array{Float32, 2}(undef, l, l2) -# # phase 1 -# flags = Array{Bool}(undef, l) -# for i = 1 : l -# flags[i] = @inbounds _transform1!(@view(f[i, :]), @view(f_org[i, :]), l2) -# end -# d1 = _set_bound_2D_1!(flags, l) -# d2 = _set_bound_2D_2!(flags, l) -# # phase 2 -# org = copy(f) -# for i = 1 : l2 -# @inbounds _transform2!(@view(f[:,i]), @view(org[:,i]), l, d1, d2) -# end -# return f -# end - -# # ╔═╡ dd8014b7-3960-4a2e-878c-c86bbc5e7303 -# md""" -# ### 3D -# """ - -# # ╔═╡ 43f3a316-82f2-4f30-b5aa-497455f24e86 -# function _set_bound_3D_1!(flags, l2, l3) -# col = 0 -# while (col+=1) <= l3 -# i = 0 -# while i < l2 -# @inbounds flags[i+=1, col] && return col -# end -# end -# return 0 -# end - -# # ╔═╡ 3253554d-4725-41f7-b086-a02137491d8f -# function _set_bound_3D_2!(flags, l2, l3) -# col = l3+1 -# while (col-=1) > 0 -# i = 0 -# while i < l2 -# @inbounds flags[i+=1, col] && return col -# end -# end -# return 0 -# end - -# # ╔═╡ 05fdaf94-2ff6-4084-b8a5-5a70908f22d1 -# function _set_bound_3D_3!(flags, l2, l3) -# row = 0 -# while (row+=1) <= l2 -# i = 0 -# while i < l3 -# @inbounds flags[row, i+=1] && return row -# end -# end -# return 0 -# end - -# # ╔═╡ baf3942d-b627-47aa-84dc-7352b5d1b0f6 -# function _set_bound_3D_4!(flags, l2, l3) -# row = l2+1 -# while (row-=1) > 0 -# i = 0 -# while i < l3 -# @inbounds flags[row, i+=1] && return row -# end -# end -# return 0 -# end - -# # ╔═╡ b2328983-1c71-49b8-9b43-39bb3febf54b -# """ -# ```julia -# transform(f::AbstractArray, tfm::Wenbo) -# ``` - -# Applies a squared euclidean distance transform to an input 3D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. -# """ -# function transform(f_org::AbstractArray, tfm::Wenbo) -# l, l2, l3 = size(f_org) -# f = Array{Float32, 3}(undef, l, l2, l3) -# # phase 1 -# flags = Array{Bool, 2}(undef, l2, l3) -# for i in CartesianIndices(@view(f[1,:,:])) -# @inbounds flags[i] = _transform1!(@view(f[:, i]), @view(f_org[:, i]), l) -# end -# d1 = _set_bound_3D_1!(flags, l2, l3) -# d2 = _set_bound_3D_2!(flags, l2, l3) -# d3 = _set_bound_3D_3!(flags, l2, l3) -# d4 = _set_bound_3D_4!(flags, l2, l3) -# # phase 2 -# for i in CartesianIndices(@view(f[:,1,d1:d2])) -# @inbounds _transform2_EN_DE!(@view(f[i[1], :, i[2]+d1-1]), l2, d3, d4) -# end -# # phase 3 -# for i in CartesianIndices(@view(f[:,:,1])) -# @inbounds _transform2_EN_DE!(@view(f[i, :]), l3, d1, d2) -# end -# return f -# end - -# # ╔═╡ 58e1cdff-59b8-44d9-a1b7-ecc14b09556c -# md""" -# ## Multi-Threaded -# """ - -# # ╔═╡ d663cf13-4a3a-4667-8971-ddb5c455d85c -# # function _transform4!(f) -# # Threads.@threads for i in axes(f, 1) -# # @inbounds _transform1!(@view(f[i, :])) -# # end -# # org = copy(f) -# # Threads.@threads for j in axes(f, 2) -# # @inbounds _transform2!(@view(f[:,j]), @view(org[:,j])) -# # end -# # end - -# # ╔═╡ 0f0675ad-899d-4808-9757-deaae19a58a5 -# md""" -# ### 2D -# """ - -# # ╔═╡ 7fecbf6c-59b0-4465-a7c3-c5217b3980c0 -# """ -# ```julia -# transform(f::AbstractMatrix, tfm::Wenbo, nthreads::Number) -# ``` - -# Applies a squared euclidean distance transform to an input 2D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. Multi-threaded version of `transform(..., tfm::Wenbo)` -# """ -# function transform(f_org::AbstractMatrix, tfm::Wenbo, nthreads::Number) -# l, l2 = size(f_org) -# f = Array{Float32, 2}(undef, l, l2) -# # phase 1 -# flags = Array{Bool}(undef, l) -# Threads.@threads for i = 1 : l -# flags[i] = @inbounds _transform1!(@view(f[i, :]), @view(f_org[i, :]), l2) -# end -# d1, d2 = 0,0 -# @sync begin -# Threads.@spawn d1 = _set_bound_2D_1!(flags, l) -# Threads.@spawn d2 = _set_bound_2D_2!(flags, l) -# end -# # phase 2 -# Threads.@threads for i = 1 : l2 -# @inbounds _transform2_EN_DE!(@view(f[:,i]), l, d1, d2) -# end -# return f -# end - -# # ╔═╡ 37cccaee-053d-4f9c-81ef-58b274ec25b8 -# md""" -# ### 3D -# """ - -# # ╔═╡ f1977b4e-1834-449a-a8c9-f984a55eeca4 -# """ -# ```julia -# transform(f::AbstractArray, tfm::Wenbo, nthreads::Number) -# ``` - -# Applies a squared euclidean distance transform to an input 3D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. Multi-threaded version of `transform(..., tfm::Wenbo)` -# """ -# function transform(f_org::AbstractArray, tfm::Wenbo, nthreads::Number) -# l, l2, l3 = size(f_org) -# f = Array{Float32, 3}(undef, l, l2, l3) -# # phase 1 -# flags = Array{Bool, 2}(undef, l2, l3) -# Threads.@threads for i in CartesianIndices(@view(f[1,:,:])) -# @inbounds flags[i] = _transform1!(@view(f[:, i]), @view(f_org[:, i]), l) -# end -# d1, d2, d3, d4 = 0,0,0,0 -# @sync begin -# Threads.@spawn d1 = _set_bound_3D_1!(flags, l2, l3) -# Threads.@spawn d2 = _set_bound_3D_2!(flags, l2, l3) -# Threads.@spawn d3 = _set_bound_3D_3!(flags, l2, l3) -# Threads.@spawn d4 = _set_bound_3D_4!(flags, l2, l3) -# end -# # phase 2 -# Threads.@threads for i in CartesianIndices(@view(f[:,1,d1:d2])) -# @inbounds _transform2_EN_DE!(@view(f[i[1], :, i[2]+d1-1]), l2, d3, d4) -# end -# # phase 3 -# Threads.@threads for i in CartesianIndices(@view(f[:,:,1])) -# @inbounds _transform2_EN_DE!(@view(f[i, :]), l3, d1, d2) -# end -# return f -# end - -# # ╔═╡ 948a0099-bc78-4707-9fa1-ad5dc59c34a5 -# md""" -# ### CPU-Batch -# """ - -# # ╔═╡ 84555ba9-ac32-4409-81e4-1e21d02aa1a1 -# """ -# ```julia -# transform(batch_size::Number, f::AbstractArray, tfm::Wenbo, _) -# ``` - -# Applies squared euclidean distance transforms to a number of batch_size N-dimension images using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. The length of last dimension of input should be equal to the batch size. -# """ -# function transform(is_batch::Bool, f::AbstractArray, tfm::Wenbo, _) -# n_dims = ndims(f) -# num_channels, num_batchs = size(f)[n_dims-1], size(f)[n_dims] -# f_new = similar(f, Float32) -# for batch_idx = 1: num_batchs -# for channel_idx = 1:num_channels -# @inbounds selectdim(selectdim(f_new, n_dims, batch_idx), n_dims-1, channel_idx)[:] = transform(selectdim(selectdim(f, n_dims, batch_idx), n_dims-1, channel_idx), tfm, 16) -# end -# end -# return f_new -# end - -# # ╔═╡ 8da39536-8765-40fe-a158-335c905e99e6 -# md""" -# ## GPU -# """ - -# # ╔═╡ c41c40b2-e23a-4ddd-a4ae-62b37e399f5c -# md""" -# ### 2D -# """ - -# # ╔═╡ ad52080b-7d59-459d-829d-2a77ddf12c5f -# function _kernel_2D_1_1!(out, f, row_l, l) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# row = cld(i, row_l) -# col = i%row_l+1 -# @inbounds if f[row, col] >= 0.5f0 -# return -# end -# ct = 1 -# curr_l = min(col-1, row_l-col) -# while ct <= curr_l -# @inbounds if f[row, col-ct] >= 0.5f0 || f[row, col+ct] >= 0.5f0 -# @inbounds out[row, col] = ct*ct -# return -# end -# ct += 1 -# end -# while ct < col -# @inbounds if f[row, col-ct] >= 0.5f0 -# @inbounds out[row, col] = ct*ct -# return -# end -# ct += 1 -# end -# while col+ct <= row_l -# @inbounds if f[row, col+ct] >= 0.5f0 -# @inbounds out[row, col] = ct*ct -# return -# end -# ct += 1 -# end -# @inbounds out[row, col] = 1f10 -# return -# end - -# # ╔═╡ b5963be3-7794-4ae0-9330-6177a82605ef -# # function _kernel_2D_1_2!(out, f, row_l, l) -# # i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# # if i > l -# # return -# # end -# # row = cld(i, row_l) -# # col = i%row_l+1 -# # @inbounds if f[row, col] -# # return -# # end -# # ct = 1 -# # curr_l = min(col-1, row_l-col) -# # while ct <= curr_l -# # @inbounds if f[row, col-ct] || f[row, col+ct] -# # @inbounds out[row, col] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while ct < col -# # @inbounds if f[row, col-ct] -# # @inbounds out[row, col] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while col+ct <= row_l -# # @inbounds if f[row, col+ct] -# # @inbounds out[row, col] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # @inbounds out[row, col] = 1f10 -# # return -# # end - -# # ╔═╡ 927f25f9-1687-415f-b5bb-8a8f40afdd0f -# function _kernel_2D_2!(org, out, row_l, col_l, l) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# row = cld(i, row_l) -# col = i%row_l+1 -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[row, col]) -# @inbounds while ct < curr_l && row+ct <= col_l -# @inbounds temp = muladd(ct,ct,org[row+ct, col]) -# @inbounds if temp < out[row, col] -# @inbounds out[row, col] = temp -# curr_l = CUDA.sqrt(temp) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && row > ct -# @inbounds temp = muladd(ct,ct,org[row-ct, col]) -# @inbounds if temp < out[row, col] -# @inbounds out[row, col] = temp -# curr_l = CUDA.sqrt(temp) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ 2a1c7734-805e-4971-9e07-a39c840457f0 -# function _kernel_2D_1_1_batch!(out, f, row_l, l, channel_idx, batch_idx) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# row = cld(i, row_l) -# col = i%row_l+1 -# @inbounds if f[row, col, channel_idx, batch_idx] >= 0.5f0 -# return -# end -# ct = 1 -# curr_l = min(col-1, row_l-col) -# while ct <= curr_l -# @inbounds if f[row, col-ct, channel_idx, batch_idx] >= 0.5f0 || f[row, col+ct, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# while ct < col -# @inbounds if f[row, col-ct, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# while col+ct <= row_l -# @inbounds if f[row, col+ct, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# @inbounds out[row, col, channel_idx, batch_idx] = 1f10 -# return -# end - -# # ╔═╡ 716e061a-dec8-4515-b2ce-f893ca23f99e -# # function _kernel_2D_1_2_batch!(out, f, row_l, l, channel_idx, batch_idx) -# # i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# # if i > l -# # return -# # end -# # row = cld(i, row_l) -# # col = i%row_l+1 -# # @inbounds if f[row, col, channel_idx, batch_idx] -# # return -# # end -# # ct = 1 -# # curr_l = min(col-1, row_l-col) -# # while ct <= curr_l -# # @inbounds if f[row, col-ct, channel_idx, batch_idx] || f[row, col+ct, channel_idx, batch_idx] -# # @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while ct < col -# # @inbounds if f[row, col-ct, channel_idx, batch_idx] -# # @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while col+ct <= row_l -# # @inbounds if f[row, col+ct, channel_idx, batch_idx] -# # @inbounds out[row, col, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # @inbounds out[row, col, channel_idx, batch_idx] = 1f10 -# # return -# # end - -# # ╔═╡ aaf5a46a-67c7-457b-bc83-d1c2163583b8 -# function _kernel_2D_2_batch!(org, out, row_l, col_l, l, channel_idx, batch_idx) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# row = cld(i, row_l) -# col = i%row_l+1 -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[row, col, channel_idx, batch_idx]) -# @inbounds while ct < curr_l && row+ct <= col_l -# @inbounds temp = muladd(ct,ct,org[row+ct, col, channel_idx, batch_idx]) -# @inbounds if temp < out[row, col, channel_idx, batch_idx] -# @inbounds out[row, col, channel_idx, batch_idx] = temp -# curr_l = CUDA.sqrt(temp) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && row > ct -# @inbounds temp = muladd(ct,ct,org[row-ct, col, channel_idx, batch_idx]) -# @inbounds if temp < out[row, col, channel_idx, batch_idx] -# @inbounds out[row, col, channel_idx, batch_idx] = temp -# curr_l = CUDA.sqrt(temp) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ 25b46272-9f45-45f1-bf81-128a4bcf041f -# function _transform_batch(f::CuArray{T, 4}, tfm::Wenbo, kernels) where T -# col_length, row_length, num_channels, batch_size = size(f) -# # println("size = $col_length, $row_length, $batch_size") -# l = col_length * row_length -# f_new = CUDA.zeros(col_length,row_length,num_channels,batch_size) -# @inbounds threads = min(l, kernels[6]) -# blocks = cld(l, threads) -# # @inbounds k1 = T<:Bool ? kernels[10] : kernels[9] -# for batch_idx = 1:batch_size -# for channel_idx = 1:num_channels -# @inbounds kernels[7](f_new, f, row_length, l, channel_idx, batch_idx; threads, blocks) -# @inbounds kernels[8](copy(f_new), f_new, row_length, col_length, l, channel_idx, batch_idx; threads, blocks) -# end -# end -# return f_new -# end - -# # ╔═╡ 58441e91-b837-496c-b1db-5dd428a6eba7 -# """ -# ```julia -# transform(f::CuArray{T, 2}, tfm::Wenbo, kernels) where T -# transform(batch_size, f::CuArray{T, 2}, tfm::Wenbo, kernels, ) where T -# ``` - -# Applies a squared euclidean distance transform to an input 2D boolean image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. GPU version of `transform(..., tfm::Wenbo)` -# """ -# function transform(f::CuArray{T, 2}, tfm::Wenbo, kernels) where T -# col_length, row_length = size(f) -# l = length(f) -# f_new = CUDA.zeros(col_length,row_length) -# threads = min(l, kernels[6]) -# blocks = cld(l, threads) -# # k1 = T<:Bool ? kernels[2] : kernels[1] -# @inbounds kernels[1](f_new, f, row_length, l; threads, blocks) -# @inbounds kernels[2](copy(f_new), f_new, row_length, col_length, l; threads, blocks) -# return f_new -# end - -# # ╔═╡ 01719cd4-f69e-47f5-9d84-36229fc3e73c -# md""" -# ### 3D -# """ - -# # ╔═╡ 24527d9b-1fa2-443d-ad4c-76a53b1ba4c2 -# function _kernel_3D_1_1!(out, f, dim2_l, dim3_l, l) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = CUDA.cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = CUDA.cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 1d DT along dim2 -# @inbounds if f[dim1, dim2, dim3] < 0.5f0 -# ct = 1 -# curr_l = CUDA.min(dim2-1, dim2_l-dim2) -# while ct <= curr_l -# @inbounds if f[dim1, dim2-ct, dim3]>=0.5f0 || f[dim1, dim2+ct, dim3]>=0.5f0 -# @inbounds out[dim1, dim2, dim3] = ct*ct -# return -# end -# ct += 1 -# end -# while ct < dim2 -# @inbounds if f[dim1, dim2-ct, dim3]>=0.5f0 -# @inbounds out[dim1, dim2, dim3] = ct*ct -# return -# end -# ct += 1 -# end -# while dim2+ct <= dim2_l -# @inbounds if f[dim1, dim2+ct, dim3]>=0.5f0 -# @inbounds out[dim1, dim2, dim3] = ct*ct -# return -# end -# ct += 1 -# end -# @inbounds out[dim1, dim2, dim3] = 1f10 -# end -# return -# end - -# # ╔═╡ 36bee155-1c27-40be-a956-30ef54ab14ef -# # function _kernel_3D_1_2!(out, f, dim2_l, dim3_l, l) -# # i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# # if i > l -# # return -# # end -# # temp = dim2_l*dim3_l -# # dim1 = CUDA.cld(i, temp) -# # temp2 = (i-1)%temp+1 -# # dim2 = CUDA.cld(temp2, dim3_l) -# # dim3 = temp2 % dim3_l + 1 -# # # 1d DT alone dim2 -# # @inbounds if !f[dim1, dim2, dim3] -# # ct = 1 -# # curr_l = CUDA.min(dim2-1, dim2_l-dim2) -# # while ct <= curr_l -# # @inbounds if f[dim1, dim2-ct, dim3] || f[dim1, dim2+ct, dim3] -# # @inbounds out[dim1, dim2, dim3] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while ct < dim2 -# # @inbounds if f[dim1, dim2-ct, dim3] -# # @inbounds out[dim1, dim2, dim3] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while dim2+ct <= dim2_l -# # @inbounds if f[dim1, dim2+ct, dim3] -# # @inbounds out[dim1, dim2, dim3] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # @inbounds out[dim1, dim2, dim3] = 1f10 -# # end -# # return -# # end - -# # ╔═╡ 22c9dd53-6ae6-45f9-8a44-c3777aefef5c -# function _kernel_3D_2!(out, org, dim1_l, dim2_l, dim3_l, l) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 2d DT along dim1 -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# @inbounds while ct < curr_l && dim1+ct <= dim1_l -# @inbounds if org[dim1+ct, dim2, dim3] < out[dim1, dim2, dim3] -# @inbounds out[dim1, dim2, dim3] = min(out[dim1, dim2, dim3], muladd(ct,ct,org[dim1+ct, dim2, dim3])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && dim1-ct > 0 -# @inbounds if org[dim1-ct, dim2, dim3] < out[dim1, dim2, dim3] -# @inbounds out[dim1, dim2, dim3] = min(out[dim1, dim2, dim3], muladd(ct,ct,org[dim1-ct, dim2, dim3])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ 678c8a54-0b50-4419-8984-e0f0507e9b48 -# function _kernel_3D_3!(out, org, dim2_l, dim3_l, l) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 2d DT along dim3= -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# @inbounds while ct < curr_l && dim3+ct <= dim3_l -# @inbounds if org[dim1, dim2, dim3+ct] < out[dim1, dim2, dim3] -# @inbounds out[dim1, dim2, dim3] = min(out[dim1, dim2, dim3], muladd(ct,ct,org[dim1, dim2, dim3+ct])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && ct < dim3 -# @inbounds if org[dim1, dim2, dim3-ct] < out[dim1, dim2, dim3] -# @inbounds out[dim1, dim2, dim3] = min(out[dim1, dim2, dim3], muladd(ct,ct,org[dim1, dim2, dim3-ct])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3]) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ a0dc7da8-54dc-43d6-a501-49ae35951563 -# function _kernel_3D_1_1_batch!(out, f, dim2_l, dim3_l, l, channel_idx, batch_idx) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = CUDA.cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = CUDA.cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 1d DT alone dim2 -# @inbounds if f[dim1, dim2, dim3, channel_idx, batch_idx] < 0.5f0 -# ct = 1 -# curr_l = CUDA.min(dim2-1, dim2_l-dim2) -# while ct <= curr_l -# @inbounds if f[dim1, dim2-ct, dim3, channel_idx, batch_idx] >= 0.5f0 || f[dim1, dim2+ct, dim3, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# while ct < dim2 -# @inbounds if f[dim1, dim2-ct, dim3, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# while dim2+ct <= dim2_l -# @inbounds if f[dim1, dim2+ct, dim3, channel_idx, batch_idx] >= 0.5f0 -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# return -# end -# ct += 1 -# end -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = 1f10 -# end -# return -# end - -# # ╔═╡ e4872d2f-1931-4019-993f-14c318362be6 -# # function _kernel_3D_1_2_batch!(out, f, dim2_l, dim3_l, l, channel_idx, batch_idx) -# # i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# # if i > l -# # return -# # end -# # temp = dim2_l*dim3_l -# # dim1 = CUDA.cld(i, temp) -# # temp2 = (i-1)%temp+1 -# # dim2 = CUDA.cld(temp2, dim3_l) -# # dim3 = temp2 % dim3_l + 1 -# # # 1d DT alone dim2 -# # @inbounds if !f[dim1, dim2, dim3, channel_idx, batch_idx] -# # ct = 1 -# # curr_l = CUDA.min(dim2-1, dim2_l-dim2) -# # while ct <= curr_l -# # @inbounds if f[dim1, dim2-ct, dim3, channel_idx, batch_idx] || f[dim1, dim2+ct, dim3, channel_idx, batch_idx] -# # @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while ct < dim2 -# # @inbounds if f[dim1, dim2-ct, dim3, channel_idx, batch_idx] -# # @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # while dim2+ct <= dim2_l -# # @inbounds if f[dim1, dim2+ct, dim3, channel_idx, batch_idx] -# # @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = ct*ct -# # return -# # end -# # ct += 1 -# # end -# # @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = 1f10 -# # end -# # return -# # end - -# # ╔═╡ 8d4ea8ae-1fd6-4448-9852-4beb552425a7 -# function _kernel_3D_2_batch!(out, org, dim1_l, dim2_l, dim3_l, l, channel_idx, batch_idx) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 2d DT along dim1 -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# @inbounds while ct < curr_l && dim1+ct <= dim1_l -# @inbounds if org[dim1+ct, dim2, dim3, channel_idx, batch_idx] < out[dim1, dim2, dim3, channel_idx, batch_idx] -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = min(out[dim1, dim2, dim3, channel_idx, batch_idx], muladd(ct,ct,org[dim1+ct, dim2, dim3, channel_idx, batch_idx])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && dim1-ct > 0 -# @inbounds if org[dim1-ct, dim2, dim3, channel_idx, batch_idx] < out[dim1, dim2, dim3, channel_idx, batch_idx] -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = min(out[dim1, dim2, dim3, channel_idx, batch_idx], muladd(ct,ct,org[dim1-ct, dim2, dim3, channel_idx, batch_idx])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ 1d497ec9-12fb-4289-b2f2-2e51cbf042e5 -# function _kernel_3D_3_batch!(out, org, dim2_l, dim3_l, l, channel_idx, batch_idx) -# i = threadIdx().x + (blockIdx().x - 1) * blockDim().x -# if i > l -# return -# end -# temp = dim2_l*dim3_l -# dim1 = cld(i, temp) -# temp2 = (i-1)%temp+1 -# dim2 = cld(temp2, dim3_l) -# dim3 = temp2 % dim3_l + 1 -# # 2d DT along dim3 -# ct = 1 -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# @inbounds while ct < curr_l && dim3+ct <= dim3_l -# @inbounds if org[dim1, dim2, dim3+ct, channel_idx, batch_idx] < out[dim1, dim2, dim3, channel_idx, batch_idx] -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = min(out[dim1, dim2, dim3, channel_idx, batch_idx], muladd(ct,ct,org[dim1, dim2, dim3+ct, channel_idx, batch_idx])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# end -# ct += 1 -# end -# ct = 1 -# @inbounds while ct < curr_l && ct < dim3 -# @inbounds if org[dim1, dim2, dim3-ct, channel_idx, batch_idx] < out[dim1, dim2, dim3, channel_idx, batch_idx] -# @inbounds out[dim1, dim2, dim3, channel_idx, batch_idx] = min(out[dim1, dim2, dim3, channel_idx, batch_idx], muladd(ct,ct,org[dim1, dim2, dim3-ct, channel_idx, batch_idx])) -# @inbounds curr_l = CUDA.sqrt(out[dim1, dim2, dim3, channel_idx, batch_idx]) -# end -# ct += 1 -# end -# return -# end - -# # ╔═╡ 1062d2aa-902a-42e2-98d2-e560fc63e7ae -# """ -# ```julia -# get_GPU_kernels(tfm::Wenbo) -# ``` - -# Returns an array with the needed kernels for GPU version of `transform(..., tfm::Wenbo)`. This function should be called before calling any GPU version of `transform(..., tfm::Wenbo)`. -# """ -# function get_GPU_kernels(tfm::Wenbo) -# kernels = [] -# # 2D kernels: -# push!(kernels, @cuda launch=false _kernel_2D_1_1!(CuArray{Float32, 2}(undef,0,0), CuArray{Float32, 2}(undef, 0, 0),0,0)) #1 -# # push!(kernels, @cuda launch=false _kernel_2D_1_2!(CuArray{Float32, 2}(undef,0,0), CuArray{Bool, 2}(undef, 0, 0),0,0)) -# push!(kernels, @cuda launch=false _kernel_2D_2!(CuArray{Float32, 2}(undef, 0,0),CuArray{Float32, 2}(undef, 0,0),0,0,0)) #2 -# # 3D kernels: -# push!(kernels, @cuda launch=false _kernel_3D_1_1!(CuArray{Float32, 3}(undef, 0, 0, 0), CuArray{Float32, 3}(undef, 0, 0, 0),0,0,0)) #3 -# # push!(kernels, @cuda launch=false _kernel_3D_1_2!(CuArray{Float32, 3}(undef, 0, 0, 0), CuArray{Bool, 3}(undef, 0, 0, 0),0,0,0)) -# push!(kernels, @cuda launch=false _kernel_3D_2!(CuArray{Float32, 3}(undef, 0, 0, 0), CuArray{Float32, 3}(undef, 0, 0, 0),0,0,0,0)) #4 -# push!(kernels, @cuda launch=false _kernel_3D_3!(CuArray{Float32, 3}(undef, 0, 0, 0), CuArray{Float32, 3}(undef, 0, 0, 0),0,0,0)) #5 -# # GPU_threads: -# GPU_threads = launch_configuration(kernels[1].fun).threads -# println("GPU threads = $GPU_threads.") -# push!(kernels, GPU_threads) #6 -# # Batch 2D kernels: -# push!(kernels, @cuda launch=false _kernel_2D_1_1_batch!(CuArray{Float32, 4}(undef,0,0,0,0), CuArray{Float32, 4}(undef, 0,0,0,0),0,0,0,0)) #7 -# # push!(kernels, @cuda launch=false _kernel_2D_1_2_batch!(CuArray{Float32, 4}(undef,0,0,0,0), CuArray{Bool, 4}(undef, 0,0,0,0),0,0,0,0)) -# push!(kernels, @cuda launch=false _kernel_2D_2_batch!(CuArray{Float32, 4}(undef, 0,0,0,0),CuArray{Float32, 4}(undef, 0,0,0,0),0,0,0,0,0)) #8 -# # Batch 3D kernels: -# push!(kernels, @cuda launch=false _kernel_3D_1_1_batch!(CuArray{Float32, 5}(undef, 0,0,0,0,0), CuArray{Float32, 5}(undef, 0,0,0,0,0),0,0,0,0,0)) #9 -# # push!(kernels, @cuda launch=false _kernel_3D_1_2_batch!(CuArray{Float32, 5}(undef, 0,0,0,0,0), CuArray{Bool, 4}(undef, 0,0,0,0,0),0,0,0,0,0)) -# push!(kernels, @cuda launch=false _kernel_3D_2_batch!(CuArray{Float32, 5}(undef, 0,0,0,0,0), CuArray{Float32, 5}(undef, 0,0,0,0,0),0,0,0,0,0,0)) #10 -# push!(kernels, @cuda launch=false _kernel_3D_3_batch!(CuArray{Float32, 5}(undef, 0,0,0,0,0), CuArray{Float32, 5}(undef, 0,0,0,0,0),0,0,0,0,0)) #11 -# return kernels -# end - -# # ╔═╡ 83ded49e-77e3-49da-8c77-ac7375670b3d -# function _transform_batch(f::CuArray{T, 5}, tfm::Wenbo, kernels) where T -# d1, d2, d3, num_channels, batch_size = size(f) -# # println("size = $d1, $d2, $d3") -# l = d1 * d2 * d3 -# f_new = CUDA.zeros(d1, d2, d3, num_channels, batch_size) -# @inbounds threads = min(l, kernels[6]) -# blocks = cld(l, threads) -# # @inbounds k1 = T<:Bool ? kernels[13] : kernels[12] -# for batch_idx = 1:batch_size -# for channel_idx = 1:num_channels -# @inbounds kernels[9](f_new, f, d2, d3, l, channel_idx, batch_idx; threads, blocks) -# @inbounds kernels[10](f_new, copy(f_new), d1, d2, d3, l, channel_idx, batch_idx; threads, blocks) -# @inbounds kernels[11](f_new, copy(f_new), d2, d3, l, channel_idx, batch_idx; threads, blocks) -# end -# end -# return f_new -# end - -# # ╔═╡ f8a18f6e-8d35-43a3-a9a8-ae2f4abfe803 -# """ -# ```julia -# function transform(f::CuArray{T, 3}, tfm::Wenbo, kernels) where T -# ``` - -# Applies a squared euclidean distance transform to an input 3D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. GPU version of `transform(..., tfm::Wenbo)` -# """ -# function transform(f::CuArray{T, 3}, tfm::Wenbo, kernels) where T -# d1, d2, d3 = size(f) -# l = length(f) -# f_new = CUDA.zeros(d1,d2,d3) -# threads = min(l, kernels[6]) -# blocks = cld(l, threads) -# # k1 = T<:Bool ? kernels[5] : kernels[4] -# @inbounds kernels[3](f_new, f, d2, d3, l; threads, blocks) -# @inbounds kernels[4](f_new, copy(f_new), d1, d2, d3, l; threads, blocks) -# @inbounds kernels[5](f_new, copy(f_new), d2, d3, l; threads, blocks) -# return f_new -# end - -# # ╔═╡ 882322db-dd8e-415d-a5d4-b6cc68761f07 -# md""" -# ### GPU-Batch -# """ - -# # ╔═╡ 14358a91-52aa-4f39-9d75-884ca53a7ce8 -# """ -# ```julia -# transform(is_batched::Bool, f::CuArray, tfm::Wenbo, kernels) -# ``` - -# Applies squared euclidean distance transforms to a number of batch_size N-dimension images using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. The length of last dimension of input should be equal to the batch size. GPU version of 'CPU-Batch'. -# """ -# function transform(is_batched::Bool, f::CuArray, tfm::Wenbo, kernels) -# return _transform_batch(f, tfm, kernels) -# end - -# # ╔═╡ 42a77639-403a-42a1-8d69-fc6bdbc9c613 -# # begin -# # img2D_batch = CuArray(rand(Float32, 8,6,2,2)) -# # img3D_batch = CuArray(rand(Float32, 6,6,6,2,2)) -# # "" -# # end - -# # ╔═╡ 5c10f6c3-1755-4cb8-a9fd-923447291998 -# # ks = get_GPU_kernels(Wenbo()); - -# # ╔═╡ ea1da50b-22b5-4323-b0d4-142e717c7e40 -# # Array(transform(true, img3D_batch, Wenbo(), ks)) - -# # ╔═╡ ebee3240-63cf-4323-9755-a135834208c8 -# md""" -# ## Various Multi-Threading -# """ - -# # ╔═╡ fccb36b9-ee1b-411f-aded-147a88b23872 -# md""" -# ### 2D -# """ - -# # ╔═╡ 88806a34-a025-40b2-810d-b3320a137543 -# """ -# ```julia -# transform(f::AbstractMatrix, tfm::Wenbo, ex) -# ``` - -# Applies a squared euclidean distance transform to an input 2D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. Multi-threaded version of `transform(..., tfm::Wenbo)` but utilizes FoldsThreads.jl for different threaded executors. `ex`=(FoldsThreads.DepthFirstEx(), FoldsThreads.NonThreadedEx(), FoldsThreads.WorkStealingEx()) -# """ -# function transform(f_org::AbstractMatrix, tfm::Wenbo, ex) -# l, l2 = size(f_org) -# f = Array{Float32, 2}(undef, l, l2) -# # phase 1 -# flags = Array{Bool}(undef, l) -# @floop for i = 1 : l -# flags[i] = @inbounds _transform1!(@view(f[i, :]), @view(f_org[i, :]), l2) -# end -# d1, d2 = 0,0 -# @sync begin -# Threads.@spawn d1 = _set_bound_2D_1!(flags, l) -# Threads.@spawn d2 = _set_bound_2D_2!(flags, l) -# end -# # phase 2 -# @floop for i = 1 : l2 -# @inbounds _transform2_EN_DE!(@view(f[:,i]), l, d1, d2) -# end -# return f -# end - -# # ╔═╡ 91e09975-e7df-4d05-9e77-dbd6c35430f0 -# md""" -# ### 3D -# """ - -# # ╔═╡ da6e01c4-5ef9-4628-a77f-4b43a05aad36 -# """ -# ```julia -# transform(f::AbstractArray, tfm::Wenbo, ex) -# ``` - -# Applies a squared euclidean distance transform to an input 3D image using the Wenbo algorithm. Returns an array with spatial information embedded in the array elements. Multi-threaded version of `transform!(..., tfm::Wenbo)` but utilizes FoldsThreads.jl for different threaded executors. `ex`=(FoldsThreads.DepthFirstEx(), FoldsThreads.NonThreadedEx(), FoldsThreads.WorkStealingEx()) -# """ -# function transform(f_org::AbstractArray, tfm::Wenbo, ex) -# l, l2, l3 = size(f_org) -# f = Array{Float32, 3}(undef, l, l2, l3) -# # phase 1 -# flags = Array{Bool, 2}(undef, l2, l3) -# @floop for i in CartesianIndices(@view(f[1,:,:])) -# @inbounds flags[i] = _transform1!(@view(f[:, i]), @view(f_org[:, i]), l) -# end -# d1, d2, d3, d4 = 0,0,0,0 -# @sync begin -# Threads.@spawn d1 = _set_bound_3D_1!(flags, l2, l3) -# Threads.@spawn d2 = _set_bound_3D_2!(flags, l2, l3) -# Threads.@spawn d3 = _set_bound_3D_3!(flags, l2, l3) -# Threads.@spawn d4 = _set_bound_3D_4!(flags, l2, l3) -# end -# # phase 2 -# @floop for i in CartesianIndices(@view(f[:,1,d1:d2])) -# @inbounds _transform2_EN_DE!(@view(f[i[1], :, i[2]+d1-1]), l2, d3, d4) -# end -# # phase 3 -# @floop for i in CartesianIndices(@view(f[:,:,1])) -# @inbounds _transform2_EN_DE!(@view(f[i, :]), l3, d1, d2) -# end -# return f -# end - -# # ╔═╡ Cell order: -# # ╠═19f1c4b6-23c4-11ed-02f2-fb3e9263a1a1 -# # ╠═69d06c40-9861-41d5-b1c3-cc7b7ccd1d48 -# # ╟─8e63a0f7-9c14-4817-9053-712d5d306a90 -# # ╠═26ee61d8-10ee-411a-9d60-0d2c0b8a6833 -# # ╟─86168cdf-7f07-42bf-81ee-6fae7d68cebd -# # ╟─fa21c417-6b0e-48a0-8993-f13c995141a6 -# # ╟─0ea3985d-8361-4511-8e28-07418e2f2539 -# # ╟─9db7eb7e-e47d-4e8d-81c0-f597eae51c04 -# # ╠═167c008e-5a5f-4ba1-b1ff-2ae137b10c98 -# # ╟─cf740dd8-79bb-4dd8-b40c-7efcf7844256 -# # ╟─16991d8b-ec84-49d0-90a9-15a78f1668bb -# # ╟─e7dbc916-c5cb-4f86-8ea1-adbcb0bdf8ea -# # ╟─32a4bf03-98f8-4ed9-9c12-f45c09b0b0dd -# # ╟─89fed2a6-b09e-47b1-a020-efed76ba57de -# # ╟─edd255fa-e1bc-45f0-8b3a-92be5084dc23 -# # ╟─a3fd1e1c-4cbb-4310-b6be-a4e61d43e8a5 -# # ╠═423df2ac-b9a2-4d59-b5fc-8de0e8cc6691 -# # ╟─dd8014b7-3960-4a2e-878c-c86bbc5e7303 -# # ╟─43f3a316-82f2-4f30-b5aa-497455f24e86 -# # ╟─3253554d-4725-41f7-b086-a02137491d8f -# # ╟─05fdaf94-2ff6-4084-b8a5-5a70908f22d1 -# # ╟─baf3942d-b627-47aa-84dc-7352b5d1b0f6 -# # ╠═b2328983-1c71-49b8-9b43-39bb3febf54b -# # ╟─58e1cdff-59b8-44d9-a1b7-ecc14b09556c -# # ╟─d663cf13-4a3a-4667-8971-ddb5c455d85c -# # ╟─0f0675ad-899d-4808-9757-deaae19a58a5 -# # ╠═7fecbf6c-59b0-4465-a7c3-c5217b3980c0 -# # ╟─37cccaee-053d-4f9c-81ef-58b274ec25b8 -# # ╠═f1977b4e-1834-449a-a8c9-f984a55eeca4 -# # ╟─948a0099-bc78-4707-9fa1-ad5dc59c34a5 -# # ╠═84555ba9-ac32-4409-81e4-1e21d02aa1a1 -# # ╟─8da39536-8765-40fe-a158-335c905e99e6 -# # ╠═1062d2aa-902a-42e2-98d2-e560fc63e7ae -# # ╟─c41c40b2-e23a-4ddd-a4ae-62b37e399f5c -# # ╟─ad52080b-7d59-459d-829d-2a77ddf12c5f -# # ╟─b5963be3-7794-4ae0-9330-6177a82605ef -# # ╟─927f25f9-1687-415f-b5bb-8a8f40afdd0f -# # ╟─2a1c7734-805e-4971-9e07-a39c840457f0 -# # ╟─716e061a-dec8-4515-b2ce-f893ca23f99e -# # ╟─aaf5a46a-67c7-457b-bc83-d1c2163583b8 -# # ╟─25b46272-9f45-45f1-bf81-128a4bcf041f -# # ╠═58441e91-b837-496c-b1db-5dd428a6eba7 -# # ╟─01719cd4-f69e-47f5-9d84-36229fc3e73c -# # ╟─24527d9b-1fa2-443d-ad4c-76a53b1ba4c2 -# # ╟─36bee155-1c27-40be-a956-30ef54ab14ef -# # ╟─22c9dd53-6ae6-45f9-8a44-c3777aefef5c -# # ╟─678c8a54-0b50-4419-8984-e0f0507e9b48 -# # ╟─a0dc7da8-54dc-43d6-a501-49ae35951563 -# # ╟─e4872d2f-1931-4019-993f-14c318362be6 -# # ╟─8d4ea8ae-1fd6-4448-9852-4beb552425a7 -# # ╟─1d497ec9-12fb-4289-b2f2-2e51cbf042e5 -# # ╟─83ded49e-77e3-49da-8c77-ac7375670b3d -# # ╠═f8a18f6e-8d35-43a3-a9a8-ae2f4abfe803 -# # ╟─882322db-dd8e-415d-a5d4-b6cc68761f07 -# # ╠═14358a91-52aa-4f39-9d75-884ca53a7ce8 -# # ╟─42a77639-403a-42a1-8d69-fc6bdbc9c613 -# # ╟─5c10f6c3-1755-4cb8-a9fd-923447291998 -# # ╟─ea1da50b-22b5-4323-b0d4-142e717c7e40 -# # ╟─ebee3240-63cf-4323-9755-a135834208c8 -# # ╟─fccb36b9-ee1b-411f-aded-147a88b23872 -# # ╠═88806a34-a025-40b2-810d-b3320a137543 -# # ╟─91e09975-e7df-4d05-9e77-dbd6c35430f0 -# # ╠═da6e01c4-5ef9-4628-a77f-4b43a05aad36 diff --git a/test/borgefors.jl b/test/borgefors.jl deleted file mode 100644 index 63a0eb1..0000000 --- a/test/borgefors.jl +++ /dev/null @@ -1,110 +0,0 @@ -### A Pluto.jl notebook ### -# v0.19.22 - -using Markdown -using InteractiveUtils - -# ╔═╡ a91769e4-a43b-41d2-8525-1daa923e8949 -# ╠═╡ show_logs = false -begin - using Pkg - Pkg.activate("..") - using Revise - using PlutoUI - using Test - using CUDA - using DistanceTransforms -end - -# ╔═╡ d8d774e1-882f-491d-b383-a7b2c314cdc9 -TableOfContents() - -# ╔═╡ 5cadc26e-698f-4cbf-8bf5-09b83dbd9447 -md""" -# `Borgefors` -""" - -# ╔═╡ 38754b7d-d2e7-4e44-a150-7efab14d585b -md""" -## Regular -""" - -# ╔═╡ 0378331e-7e8d-4543-9f38-9af51da24314 -md""" -### 2D -""" - -# ╔═╡ 2e8f1750-7fc0-4d21-aa25-d00bc67bc048 -@testset "Borgefors 2D" begin - x = [ - 1 1 0 0 - 0 1 1 0 - 0 1 0 1 - 0 1 0 0 - ] - dt = zeros(Float32, size(x)) - tfm = Borgefors() - answer = [ - 0 0 3 4 - 3 0 0 3 - 3 0 3 0 - 3 0 3 3 - ] - @test transform(x, dt, tfm) == answer -end; - -# ╔═╡ b268d818-90b5-4382-a330-b8bc9e18b914 -@testset "Borgefors 2D" begin - x = [ - 1 1 0 0 - 0 1 0 0 - 0 1 0 0 - 0 1 0 0 - ] - dt = zeros(Float32, size(x)) - tfm = Borgefors() - answer = [ - 0 0 3 6 - 3 0 3 6 - 3 0 3 6 - 3 0 3 6 - ] - @test transform(x, dt, tfm) == answer -end; - -# ╔═╡ 6c78fadf-7cab-445f-b77e-4803dd06a887 -md""" -### 3D -""" - -# ╔═╡ dde0dc70-4422-4698-92bd-803347c04cda -@testset "Borgefors 3D" begin - x1 = [ - 1 1 0 0 - 0 1 0 0 - 0 1 0 0 - 0 1 0 0 - ] - x = cat(x1, x1; dims=3) - dt = zeros(Float32, size(x)) - tfm = Borgefors() - a1 = [ - 0 0 3 6 - 3 0 3 6 - 3 0 3 6 - 3 0 3 6 - ] - answer = cat(a1, a1; dims=3) - @test transform(x, dt, tfm) == answer -end; - -# ╔═╡ Cell order: -# ╠═a91769e4-a43b-41d2-8525-1daa923e8949 -# ╠═d8d774e1-882f-491d-b383-a7b2c314cdc9 -# ╟─5cadc26e-698f-4cbf-8bf5-09b83dbd9447 -# ╟─38754b7d-d2e7-4e44-a150-7efab14d585b -# ╟─0378331e-7e8d-4543-9f38-9af51da24314 -# ╠═2e8f1750-7fc0-4d21-aa25-d00bc67bc048 -# ╠═b268d818-90b5-4382-a330-b8bc9e18b914 -# ╟─6c78fadf-7cab-445f-b77e-4803dd06a887 -# ╠═dde0dc70-4422-4698-92bd-803347c04cda diff --git a/test/felzenszwalb.jl b/test/felzenszwalb.jl index 3ae7b3a..f3d8470 100644 --- a/test/felzenszwalb.jl +++ b/test/felzenszwalb.jl @@ -310,229 +310,3 @@ if CUDA.has_cuda_gpu() else @warn "CUDA unavailable, not testing GPU support" end - -@testset "Felzenszwalb 2D FoldsThreads " begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = DepthFirstEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer - - img = rand([0, 1], 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = DepthFirstEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer - - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = NonThreadedEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer - - img = rand([0, 1], 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = NonThreadedEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer - - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = WorkStealingEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer - - img = rand([0, 1], 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = WorkStealingEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer -end - -@testset "Felzenszwalb 3D FoldsThreads" begin - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = cat(container2..., dims=3) - output, v, z = zeros(size(vol_inv)), ones(Int32, size(vol_inv)), ones(size(vol_inv) .+ 1) - tfm = Felzenszwalb() - ex = DepthFirstEx() - test = transform(boolean_indicator(vol_inv), tfm, ex; output=output, v=v, z=z) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == answer - - img = rand([0, 1], 10, 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = WorkStealingEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer - - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = cat(container2..., dims=3) - output, v, z = zeros(size(vol_inv)), ones(Int32, size(vol_inv)), ones(size(vol_inv) .+ 1) - tfm = Felzenszwalb() - ex = NonThreadedEx() - test = transform(boolean_indicator(vol_inv), tfm, ex; output=output, v=v, z=z) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == answer - - img = rand([0, 1], 10, 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = NonThreadedEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer - - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = cat(container2..., dims=3) - output, v, z = zeros(size(vol_inv)), ones(Int32, size(vol_inv)), ones(size(vol_inv) .+ 1) - tfm = Felzenszwalb() - ex = WorkStealingEx() - test = transform(boolean_indicator(vol_inv), tfm, ex; output=output, v=v, z=z) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == answer - - img = rand([0, 1], 10, 10, 10) - output, v, z = zeros(size(img)), ones(Int32, size(img)), ones(size(img) .+ 1) - tfm = Felzenszwalb() - ex = WorkStealingEx() - test = transform(boolean_indicator(img), tfm, ex; output=output, v=v, z=z) - answer = transform(boolean_indicator(img), tfm) - @test test == answer -end diff --git a/test/maurer.jl b/test/maurer.jl index ed565d9..865b6ed 100644 --- a/test/maurer.jl +++ b/test/maurer.jl @@ -11,8 +11,6 @@ @test test == answer end; - - @testset "Maurer 2D" begin x = [ 1 1 0 0 diff --git a/test/runtests.jl b/test/runtests.jl index 33f51d8..fc3e39c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,5 @@ using DistanceTransforms using CUDA using Test -# include("borgefors.jl") include("maurer.jl") -# include("felzenszwalb.jl") -# include("wenbo.jl") +include("felzenszwalb.jl") diff --git a/test/utils.jl b/test/utils.jl index dcbb7db..d2be094 100644 --- a/test/utils.jl +++ b/test/utils.jl @@ -1,34 +1,6 @@ -### A Pluto.jl notebook ### -# v0.19.11 - -using Markdown -using InteractiveUtils - -# ╔═╡ dcdd2c68-3ec4-11ed-2e84-77926655aa11 -# ╠═╡ show_logs = false -begin - using Pkg - Pkg.activate("..") - using Revise - using PlutoUI - using Test - using CUDA - using DistanceTransforms - using LoopVectorization -end - -# ╔═╡ 6ca83ba8-2e67-4b8f-9ed9-c903a867dc75 -TableOfContents() - -# ╔═╡ b3c5c757-2237-41d8-bf2e-48da4878aeca @testset "boolean_indicator" begin f = rand([0, 1], 100, 100) f_bool = Bool.(f) @test boolean_indicator(f) == boolean_indicator(f_bool) end - -# ╔═╡ Cell order: -# ╠═dcdd2c68-3ec4-11ed-2e84-77926655aa11 -# ╠═6ca83ba8-2e67-4b8f-9ed9-c903a867dc75 -# ╠═b3c5c757-2237-41d8-bf2e-48da4878aeca diff --git a/test/wenbo.jl b/test/wenbo.jl deleted file mode 100644 index c478dae..0000000 --- a/test/wenbo.jl +++ /dev/null @@ -1,532 +0,0 @@ -### A Pluto.jl notebook ### -# v0.19.14 - -using Markdown -using InteractiveUtils - -# ╔═╡ 38a67f7e-3b1a-4a6c-9916-91eab4ad4d63 -# ╠═╡ show_logs = false -begin - using Pkg - Pkg.activate("..") - using Revise - using PlutoUI - using Test - using CUDA - using DistanceTransforms - using FoldsThreads -end - -# ╔═╡ 3b8595ae-b215-4e3b-b615-ff460793f028 -TableOfContents() - -# ╔═╡ 4a043231-7888-4408-a663-4541e8606245 -md""" -# `Wenbo` -""" - -# ╔═╡ edc7480a-11ec-4952-8984-af97d3967639 -md""" -## Single-Thread -""" - -# ╔═╡ ab715087-a707-485b-9463-8d17fe0bcaab -md""" -### 1D -""" - -# ╔═╡ f860bf51-4c1f-4b82-a67d-d5294733345f -@testset "wenbo 1D" begin - f = [1, 1, 0, 0, 0, 1, 1] - tfm = Wenbo() - test = transform(f, tfm) - answer = [0.0, 0.0, 1.0, 4.0, 1.0, 0.0, 0.0] - @test test == answer -end; - -# ╔═╡ f6d1f13b-2b81-4253-ad80-38dd6c11eb93 -@testset "wenbo 1D" begin - f = [0, 0, 0, 1] - tfm = Wenbo() - test = transform(f, tfm) - answer = [9.0, 4.0, 1.0, 0.0] - @test test == answer -end; - -# ╔═╡ 77970fcb-e584-4222-af3c-5b8482bab391 -@testset "wenbo 1D" begin - f = [1, 0, 0, 0] - tfm = Wenbo() - test = transform(f, tfm) - answer = [0, 1, 4, 9] - @test test == answer -end; - -# ╔═╡ eac8edcd-ee45-4824-a3b7-cd0535260cb6 -md""" -### 2D -""" - -# ╔═╡ eb456533-684f-45e7-9591-7cebf493f63c -@testset "Wenbo 2D" begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - test = transform(img, tfm) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer -end; - -# ╔═╡ 350a21d9-552f-4d0a-a586-a8932fc4e245 -@testset "wenbo 2D" begin - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - tfm = Wenbo() - test = transform(img, tfm) - answer = [ - 18.0 13.0 10.0 9.0 9.0 9.0 10.0 13.0 18.0 25.0 34.0 - 13.0 8.0 5.0 4.0 4.0 4.0 5.0 8.0 13.0 20.0 25.0 - 8.0 5.0 2.0 1.0 1.0 1.0 2.0 5.0 10.0 13.0 18.0 - 5.0 2.0 1.0 0.0 0.0 0.0 1.0 4.0 5.0 8.0 13.0 - 4.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0 2.0 5.0 10.0 - 4.0 1.0 0.0 1.0 1.0 0.0 0.0 0.0 1.0 4.0 9.0 - 4.0 1.0 0.0 1.0 2.0 1.0 1.0 0.0 1.0 4.0 9.0 - 4.0 1.0 0.0 1.0 1.0 1.0 1.0 0.0 1.0 4.0 9.0 - 5.0 2.0 1.0 0.0 0.0 0.0 0.0 1.0 2.0 5.0 10.0 - 8.0 5.0 2.0 1.0 1.0 1.0 1.0 2.0 5.0 8.0 13.0 - 13.0 8.0 5.0 4.0 4.0 4.0 4.0 5.0 8.0 13.0 18.0 - ] - @test test == answer -end; - -# ╔═╡ e05ea048-d7bd-48a1-b943-2dc9b9ba5e02 -md""" -### 3D -""" - -# ╔═╡ b1d3b0d0-5103-4fdf-8d55-16babca9ee21 -@testset "wenbo 3D" begin - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = cat(container2..., dims=3) - tfm = Wenbo() - test = transform(vol_inv, tfm) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == answer -end; - -# ╔═╡ 8fb44a16-a4cb-4f4c-9a16-f85cacf9e81f -md""" -## Multi-Threaded -""" - -# ╔═╡ cdcd1cda-be51-4a2a-a69d-381338fd5bd9 -md""" -### 2D -""" - -# ╔═╡ ea81cc9e-2ee9-4d62-9288-c081ef9ef0c4 -@testset "wenbo 2D multi-threaded" begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - nthreads = Threads.nthreads() - test = transform(img, tfm, nthreads) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer -end; - -# ╔═╡ 58c3aaee-be8c-42a9-a3f7-35aafc77a308 -@testset "wenbo 2D multi-threaded" begin - img = rand([0, 1], 10, 10) - tfm = Wenbo() - nthreads = Threads.nthreads() - test = transform(img, tfm, nthreads) - answer = transform(img, tfm) - @test test == answer -end; - -# ╔═╡ 89bf91b7-2a29-48ed-8c0c-b6e46fa5de4e -md""" -### 3D -""" - -# ╔═╡ bdef08b3-f15c-4769-ba7d-c3dc4f9a0006 -@testset "wenbo 3D multi-threaded" begin - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = cat(container2..., dims=3) - tfm = Wenbo() - nthreads = Threads.nthreads() - test = transform(vol_inv, tfm, nthreads) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == answer -end; - -# ╔═╡ 51117c0a-5f23-4b5d-ab76-81d25cd73a27 -@testset "wenbo 3D multi-threaded" begin - img = rand([0, 1], 10, 10, 10) - tfm = Wenbo() - nthreads = Threads.nthreads() - test = transform(img, tfm, nthreads) - answer = transform(img, tfm) - @test test == answer -end; - -# ╔═╡ 91899f57-48cc-49e4-b100-116f2326d126 -md""" -## GPU -""" - -# ╔═╡ 6293532a-198d-49a2-b450-3ab7c7be3227 -md""" -### 2D -""" - -# ╔═╡ edc19bce-db97-4a0d-a4a9-11e9241434e9 -if CUDA.has_cuda_gpu() - ks = DistanceTransforms.get_GPU_kernels(Wenbo()) - @testset "wenbo 2D GPU" begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - test = transform(CuArray(Float32.(img)), tfm, ks) - answer = CuArray([ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ]) - @test test == answer - end -else - @warn "CUDA unavailable, not testing GPU support" -end; - -# ╔═╡ 9d3e6bab-d8a5-42d3-862b-135f10887562 -if CUDA.has_cuda_gpu() - @testset "wenbo 2D GPU" begin - img = rand([0, 1], 10, 10) - img2 = copy(img) - tfm = Wenbo() - test = transform(CUDA.CuArray(Float32.(img)), tfm, ks) - answer = transform(img2, tfm) - @test test == CuArray(answer) - end -else - @warn "CUDA unavailable, not testing GPU support" - -end; - -# ╔═╡ 35ff78e2-b1d7-4792-8145-ced70a6ff233 -md""" -### 3D -""" - -# ╔═╡ f5159fb2-30bc-4828-bb21-d9ad7343fe85 -if CUDA.has_cuda_gpu() - @testset "wenbo 3D GPU" begin - img = [ - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 1 1 1 0 0 0 0 0 - 0 0 1 0 0 1 0 0 0 0 0 - 0 0 1 0 0 1 1 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 1 0 0 0 0 1 0 0 0 - 0 0 0 1 1 1 1 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - 0 0 0 0 0 0 0 0 0 0 0 - ] - img_inv = @. ifelse(img == 0, 1, 0) - vol = cat(img, img_inv, dims=3) - container2 = [] - for i in 1:10 - push!(container2, vol) - end - vol_inv = CuArray(Float32.(cat(container2..., dims=3))) - tfm = Wenbo() - test = transform(vol_inv, tfm, ks) - a1 = img_inv - a2 = img - ans = cat(a1, a2, dims=3) - container_a = [] - for i in 1:10 - push!(container_a, ans) - end - answer = cat(container_a..., dims=3) - @test test == CuArray(answer) - end -else - @warn "CUDA unavailable, not testing GPU support" -end; - -# ╔═╡ 4fa62723-c3e2-4afd-911b-e3f2285df74d -if CUDA.has_cuda_gpu() - @testset "Wenbo 3D GPU" begin - img = rand([0, 1], 10, 10, 10) - img2 = copy(img) - tfm = Wenbo() - test = transform(CUDA.CuArray(Float32.(img)), tfm, ks) - answer = transform(img2, tfm) - @test test == CuArray(answer) - end -else - @warn "CUDA unavailable, not testing GPU support" - -end; - -# ╔═╡ 9755e49a-699d-4ebf-ab28-958007d1a0ab -md""" -## Various Multi-Threading -""" - -# ╔═╡ 278053f3-de28-4090-add3-c08257aff74f -md""" -### 2D -""" - -# ╔═╡ f87ded07-5767-4a4c-8d00-d9fa5d6914bc -@testset "wenbo 2D FoldsThreads " begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - ex = DepthFirstEx() - test = transform(img, tfm, ex) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer -end; - -# ╔═╡ c52fd17a-ad54-4317-96ac-a6c7b0da4f99 -@testset "wenbo 2D FoldsThreads " begin - img = rand([0, 1], 10, 10) - tfm = Wenbo() - ex = DepthFirstEx() - test = transform(img, tfm, ex) - answer = transform(img, tfm) - @test test == answer -end; - -# ╔═╡ 4a17f216-e186-4352-8c18-5fdb345add80 -@testset "wenbo 2D FoldsThreads " begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - ex = NonThreadedEx() - test = transform(img, tfm, ex) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer -end; - -# ╔═╡ b6d801fa-2097-43e7-887e-b5dad19bc3f8 -@testset "wenbo 2D FoldsThreads " begin - img = rand([0, 1], 10, 10) - tfm = Wenbo() - ex = NonThreadedEx() - test = transform(img, tfm, ex) - answer = transform(img, tfm) - @test test == answer -end; - -# ╔═╡ 07d8dd61-39ff-40e6-886c-410ae651dc39 -@testset "wenbo 2D FoldsThreads " begin - img = [ - 0 1 1 1 0 0 0 1 1 - 1 1 1 1 1 0 0 0 1 - 1 0 0 0 1 0 0 1 1 - 1 0 0 0 1 0 1 1 0 - 1 0 0 0 1 1 0 1 0 - 1 1 1 1 1 0 0 1 0 - 0 1 1 1 0 0 0 0 1 - ] - tfm = Wenbo() - ex = WorkStealingEx() - test = transform(img, tfm, ex) - answer = [ - 1.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 0.0 - 0.0 0.0 0.0 0.0 0.0 1.0 2.0 1.0 0.0 - 0.0 1.0 1.0 1.0 0.0 1.0 1.0 0.0 0.0 - 0.0 1.0 4.0 1.0 0.0 1.0 0.0 0.0 1.0 - 0.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 - 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 1.0 - 1.0 0.0 0.0 0.0 1.0 2.0 2.0 1.0 0.0 - ] - @test test == answer -end; - -# ╔═╡ eccdfa48-2c8d-45a3-81b0-55325020f429 -@testset "wenbo FoldsThreads" begin - img = rand([0, 1], 10, 10) - tfm = Wenbo() - ex = WorkStealingEx() - test = transform(img, tfm, ex) - answer = transform(img, tfm) - @test test == answer -end; - -# ╔═╡ Cell order: -# ╠═38a67f7e-3b1a-4a6c-9916-91eab4ad4d63 -# ╠═3b8595ae-b215-4e3b-b615-ff460793f028 -# ╟─4a043231-7888-4408-a663-4541e8606245 -# ╠═edc7480a-11ec-4952-8984-af97d3967639 -# ╟─ab715087-a707-485b-9463-8d17fe0bcaab -# ╠═f860bf51-4c1f-4b82-a67d-d5294733345f -# ╠═f6d1f13b-2b81-4253-ad80-38dd6c11eb93 -# ╠═77970fcb-e584-4222-af3c-5b8482bab391 -# ╟─eac8edcd-ee45-4824-a3b7-cd0535260cb6 -# ╠═eb456533-684f-45e7-9591-7cebf493f63c -# ╠═350a21d9-552f-4d0a-a586-a8932fc4e245 -# ╟─e05ea048-d7bd-48a1-b943-2dc9b9ba5e02 -# ╠═b1d3b0d0-5103-4fdf-8d55-16babca9ee21 -# ╟─8fb44a16-a4cb-4f4c-9a16-f85cacf9e81f -# ╟─cdcd1cda-be51-4a2a-a69d-381338fd5bd9 -# ╠═ea81cc9e-2ee9-4d62-9288-c081ef9ef0c4 -# ╠═58c3aaee-be8c-42a9-a3f7-35aafc77a308 -# ╟─89bf91b7-2a29-48ed-8c0c-b6e46fa5de4e -# ╠═bdef08b3-f15c-4769-ba7d-c3dc4f9a0006 -# ╠═51117c0a-5f23-4b5d-ab76-81d25cd73a27 -# ╟─91899f57-48cc-49e4-b100-116f2326d126 -# ╟─6293532a-198d-49a2-b450-3ab7c7be3227 -# ╠═edc19bce-db97-4a0d-a4a9-11e9241434e9 -# ╠═9d3e6bab-d8a5-42d3-862b-135f10887562 -# ╟─35ff78e2-b1d7-4792-8145-ced70a6ff233 -# ╠═f5159fb2-30bc-4828-bb21-d9ad7343fe85 -# ╠═4fa62723-c3e2-4afd-911b-e3f2285df74d -# ╟─9755e49a-699d-4ebf-ab28-958007d1a0ab -# ╟─278053f3-de28-4090-add3-c08257aff74f -# ╠═f87ded07-5767-4a4c-8d00-d9fa5d6914bc -# ╠═c52fd17a-ad54-4317-96ac-a6c7b0da4f99 -# ╠═4a17f216-e186-4352-8c18-5fdb345add80 -# ╠═b6d801fa-2097-43e7-887e-b5dad19bc3f8 -# ╠═07d8dd61-39ff-40e6-886c-410ae651dc39 -# ╠═eccdfa48-2c8d-45a3-81b0-55325020f429