Skip to content

Commit

Permalink
Add more color channel reduction presets (#6)
Browse files Browse the repository at this point in the history
* Add more color channel reduction presets

* Allow CI failure on nightly
  • Loading branch information
adrhill authored Feb 16, 2024
1 parent 3414bf7 commit 9045726
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
version:
- '1.6'
- '1'
- 'nightly'
os:
- ubuntu-latest
Expand All @@ -33,7 +34,9 @@ jobs:
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
continue-on-error: ${{ matrix.version == 'nightly' }}
- uses: julia-actions/julia-runtest@v1
continue-on-error: ${{ matrix.version == 'nightly' }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
Expand Down
10 changes: 9 additions & 1 deletion src/heatmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Visualize 4D arrays as heatmaps, assuming the WHCN convention for input array di
- `:sum`: sum up color channels
- `:norm`: compute 2-norm over the color channels
- `:maxabs`: compute `maximum(abs, x)` over the color channels
- `:sumabs`: compute `sum(abs, x)` over the color channels
- `:abssum`: compute `abs(sum(x))` over the color channels
Defaults to `:$DEFAULT_REDUCE`.
- `rangescale::Symbol`: Selects how the color channel reduced heatmap is normalized
before the color scheme is applied. Can be either `:extrema` or `:centered`.
Expand Down Expand Up @@ -85,8 +87,14 @@ function reduce_color_channel(val::AbstractArray, method::Symbol)
return reduce((c...) -> maximum(abs.(c)), val; dims=3, init=init)
elseif method == :norm
return reduce((c...) -> sqrt(sum(c .^ 2)), val; dims=3, init=init)
elseif method == :sumabs
return reduce((c...) -> sum(abs, c), val; dims=3, init=init)
elseif method == :abssum
return reduce((c...) -> abs(sum(c)), val; dims=3, init=init)
end
throw( # else
ArgumentError("`reduce` :$method not supported, should be :maxabs, :sum or :norm"),
ArgumentError(
"`reduce` :$method not supported, should be :maxabs, :sum, :norm, :sumabs, or :abssum",
),
)
end
1 change: 1 addition & 0 deletions test/references/abssum_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/abssum_centered_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/abssum_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/abssum_extrema_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/overlay_abssum_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/overlay_abssum_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
3 changes: 3 additions & 0 deletions test/references/overlay_rescale_abssum_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
▀▀▀▀▀▀
▀▀▀▀▀▀
▀▀▀▀▀▀
3 changes: 3 additions & 0 deletions test/references/overlay_rescale_abssum_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
▀▀▀▀▀▀
▀▀▀▀▀▀
▀▀▀▀▀▀
3 changes: 3 additions & 0 deletions test/references/overlay_rescale_sumabs_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
▀▀▀▀▀▀
▀▀▀▀▀▀
▀▀▀▀▀▀
3 changes: 3 additions & 0 deletions test/references/overlay_rescale_sumabs_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
▀▀▀▀▀▀
▀▀▀▀▀▀
▀▀▀▀▀▀
1 change: 1 addition & 0 deletions test/references/overlay_sumabs_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/overlay_sumabs_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/sumabs_centered.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/sumabs_centered_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/sumabs_extrema.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
1 change: 1 addition & 0 deletions test/references/sumabs_extrema_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
▀▀
2 changes: 1 addition & 1 deletion test/test_heatmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ batch = reshape(collect(Float32, 1:prod(shape)), shape)
img = [RGB(1, 0, 0) RGB(0, 1, 0); RGB(0, 0, 1) RGB(1, 1, 1)]
img2 = [RGB(x, y, 0) for x in 0:0.2:1, y in 0:0.2:1]

reducers = [:sum, :maxabs, :norm]
reducers = [:sum, :maxabs, :norm, :sumabs, :abssum]
rangescales = [:extrema, :centered]

@testset "Single input" begin
Expand Down

0 comments on commit 9045726

Please sign in to comment.