Skip to content

Commit

Permalink
add test for complex coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
mboberg committed Jun 16, 2021
1 parent 75fb12b commit 8523bad
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Coloring.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export ColoringParams, colorize, blend, reorderColor, existing_cmaps, cmap,
overlay, linearDoge
overlay, linearDoge, complexColoring

struct ColoringParams
cmin::Float64
Expand Down Expand Up @@ -157,7 +157,10 @@ function complexColoring(amp, phase; colormap=ColorSchemes.phase, normalizeG::Bo
# normalize amplitude
I = amp./amax
clamp01!(I) # using desaturation colormap: make sure to map intensity between 0 and 1
rawImage = I.*get(colormap,phase,(-π,Float64(π)))
rawImage = similar(I,RGBA{N0f8})
for n=1:length(I)
rawImage[n] = I[n]*get(colormap,phase[n],(-π,Float64(π)))
end
return convert.(RGBA{N0f8},rawImage)
end

Expand Down
25 changes: 20 additions & 5 deletions test/Coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,25 @@ OC = colorize(I, [ColoringParams(0,1,"gray"), ColoringParams(0,1,"red"),],
[0.0,0.0], [1.0,1.0])

exportImage("img/coloring6.png", OC)
#@testImg("coloring6.png")




@testImg("coloring6.png")


## Complex coloring

# create 2D colorbar
hues = range(0,2π,length=50)
saturations = 0:0.05:1.0
HS = vec(tuple.(hues, saturations'))
D = kron(saturations,(exp.(im*hues))')
# complex coloring
Y = complexColoring(abs.(D), angle.(D))
exportImage("img/coloring7.png", Y)
@testImg("coloring7.png")

# normalizeGray
colormap = ImageUtils.ColorSchemes.phase
@test ImageUtils.normalizeGray(colormap[1]) == RGB{Float64}(0.8979049716100672,0.6795060499249219,0.28645928277939586)
@test @test_logs (:warn,"Normalization of gray value failed, g ≈ 0.056 is used. Use g >= 0.056 for a consistent normalization.") ImageUtils.normalizeGray(colormap[1],0.05) == RGB{Float64}(0.18396207457891003,0.0,0.0)
@test @test_logs (:warn,"Normalization of gray value failed, g ≈ 0.925 is used. Use g <= 0.925 for a consistent normalization.") ImageUtils.normalizeGray(colormap[1],0.95) == RGB{Float64}(1.0,0.9603124734843839,0.5548057892335283)

end
Binary file added test/correct/coloring7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8523bad

Please sign in to comment.