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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ccd2rgb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ function composecolors(
if length(images) == 3 && isnothing(cmap)
cmap = ["red", "green", "blue"]
end
if length(cmap) < length(images)
if _cmap_len(cmap) < length(images)
error("Please provide a color channel for each image")
end
if _cmap_len(cmap) > length(images)
error("Please provide an image for each color channel")
end

# Use imview to render each channel to RGBA
images_rendered = broadcast(images, cmap, clims, stretch, contrast, bias) do image, cmap, clims, stretch, contrast, bias
Expand All @@ -77,4 +80,5 @@ function composecolors(
end
return combined
end
_cmap_len(cmap) = isnothing(cmap) ? 0 : length(cmap)
export composechannels
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,16 @@ end

# include("plots.jl")
# include("ccd2rgb.jl")
# TODO: Put this into ccd2rgb.jl later?
@testset "ccd2rgb" begin
img1, img2, img3 = eachslice(rand(3, 4, 3); dims=3)
img4 = rand(3, 5)
@test_throws ErrorException("At least one image is required.") composecolors([], ["red", "blue", "green"])
@test_throws ErrorException("Images must have the same dimensions to compose them.") composecolors([img1, img2, img4], ["red", "blue", "green"])
@test_throws ErrorException("Please provide a color channel for each image") composecolors([img1, img2, img3], ["red", "blue"])
@test_throws ErrorException("Please provide a color channel for each image") composecolors([img1, img2], ["red"])
@test_throws ErrorException("Please provide a color channel for each image") composecolors([img1, img2])
@test_throws ErrorException("Please provide an image for each color channel") composecolors([img1, img2, img3], ["red", "blue", "green", "maroon"])
@test_throws ErrorException("Please provide an image for each color channel") composecolors([img1, img2], ["red", "blue", "green"])
@test_throws ErrorException("Please provide an image for each color channel") composecolors([img1], ["red", "blue"])
end
Loading