diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a46f46d..fffa0b6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -24,12 +24,14 @@ jobs: matrix: version: - '1.10' - - '1.6' - - 'pre' + - '1' os: - ubuntu-latest arch: - x64 + include: + - os: ubuntu-latest + prefix: xvfb-run steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 @@ -39,6 +41,8 @@ jobs: - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 + with: + prefix: ${{ matrix.prefix }} - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v5 with: diff --git a/Project.toml b/Project.toml index 770474c..8bd2933 100644 --- a/Project.toml +++ b/Project.toml @@ -1,11 +1,12 @@ name = "CounterMarking" uuid = "454fbcff-fa78-4492-9c80-2cfc3f2a4b52" authors = ["Tim Holy and contributors"] -version = "1.0.0-DEV" +version = "1.0.0" [deps] FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" +ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" ImageMorphology = "787d08f9-d448-5407-9aad-5290dd7ab264" ImageSegmentation = "80713f31-8817-5129-9cf8-209ff8fb23e1" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -19,13 +20,15 @@ CounterMarkingImageViewExt = "ImageView" [compat] FileIO = "1" ImageCore = "0.10" +ImageIO = "0.6" ImageMorphology = "0.4" ImageSegmentation = "1.9" ImageView = "0.12" julia = "1.10" [extras] +ImageView = "86fae568-95e7-573e-a6b2-d8a6b900c9ef" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["ImageView", "Test"] diff --git a/README.md b/README.md index 1013814..c435d3e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # CounterMarking [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://HolyLab.github.io/CounterMarking.jl/stable/) -[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://HolyLab.github.io/CounterMarking.jl/dev/) [![Build Status](https://github.com/HolyLab/CounterMarking.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/HolyLab/CounterMarking.jl/actions/workflows/CI.yml?query=branch%3Amain) [![Coverage](https://codecov.io/gh/HolyLab/CounterMarking.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/HolyLab/CounterMarking.jl) + +Utilities for analyzing images from mouse territorial countermarking experiments. diff --git a/ext/CounterMarkingImageViewExt.jl b/ext/CounterMarkingImageViewExt.jl index dec45d4..844ce3e 100644 --- a/ext/CounterMarkingImageViewExt.jl +++ b/ext/CounterMarkingImageViewExt.jl @@ -6,23 +6,23 @@ using ImageSegmentation using ImageView using Random -function colorize(seg, segidxs::AbstractSet{Int}, color::Colorant) - label = seg.image_indexmap - img = similar(label, promote_type(typeof(color), valtype(seg.segment_means))) - fill!(img, zero(eltype(img))) - for idx in eachindex(label) - label[idx] ∈ segidxs || continue - img[idx] = color - end - return img -end +# function colorize(seg, segidxs::AbstractSet{Int}, color::Colorant) +# label = seg.image_indexmap +# img = similar(label, promote_type(typeof(color), valtype(seg.segment_means))) +# fill!(img, zero(eltype(img))) +# for idx in eachindex(label) +# label[idx] ∈ segidxs || continue +# img[idx] = color +# end +# return img +# end function linkpair(img, imgc) - gd = imshow(img) - zr = gd["roi"]["zoomregion"] - slicedata = gd["roi"]["slicedata"] - gdc = imshow(imgc, nothing, zr, slicedata) - return (gd, gdc) + zr, slicedata = roi(img) + gd = imshow_gui((800, 800), (2,1); slicedata=slicedata) + imshow(gd["frame"][1,1], gd["canvas"][1,1], img, nothing, zr, slicedata) + imshow(gd["frame"][2,1], gd["canvas"][2,1], imgc, nothing, zr, slicedata) + return gd end # For visualization @@ -34,4 +34,7 @@ end CounterMarking.randshow(seg; kwargs...) = imshow(map(i->get_random_color(i), labels_map(seg)); kwargs...) CounterMarking.meanshow(seg; kwargs...) = imshow(map(i->segment_mean(seg, i), labels_map(seg)); kwargs...) +CounterMarking.randshow(img, seg; kwargs...) = linkpair(img, map(i->get_random_color(i), labels_map(seg)); kwargs...) +CounterMarking.meanshow(img, seg; kwargs...) = linkpair(img, map(i->segment_mean(seg, i), labels_map(seg)); kwargs...) + end diff --git a/test/runtests.jl b/test/runtests.jl index b917d62..0f864ae 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,36 @@ using CounterMarking +using FileIO using Test @testset "CounterMarking.jl" begin - # Write your tests here. + testdir = "testimages" + img = load(joinpath(testdir, "Picture.png")) + seg = segment_image(img) + # Without ImageView loaded, we can't visualize it, but we get a helpful error + if !isdefined(@__MODULE__, :ImageView) + @test_throws "using ImageView" randshow(seg) + @test_throws "using ImageView" meanshow(seg) + end + @eval using ImageView + dct = meanshow(seg) + @test haskey(dct, "gui") + dct = randshow(seg) + @test haskey(dct, "gui") + dct = randshow(img, seg) + @test haskey(dct, "window") + dct = meanshow(img, seg) + @test haskey(dct, "window") + ImageView.closeall() + + spotdict, stimulus = spots(seg) + _, stimspot = stimulus + @test stimspot.npixels > 1000 + @test stimspot.centroid[1] < size(img, 1) ÷ 2 + @test stimspot.centroid[2] > size(img, 2) ÷ 2 + + stdspotdict, stdstimulus = upperleft(spotdict, stimulus, size(img)) + _, stimspot = stdstimulus + @test stimspot.npixels > 1000 + @test stimspot.centroid[1] < size(img, 1) ÷ 2 + @test stimspot.centroid[2] < size(img, 2) ÷ 2 end diff --git a/test/testimages/Picture.png b/test/testimages/Picture.png new file mode 100644 index 0000000..c142b8d Binary files /dev/null and b/test/testimages/Picture.png differ