Skip to content

Commit eec4d64

Browse files
authored
Add basic tests (#4)
Also improves `linkpair` to display in the same window.
1 parent 05edd1e commit eec4d64

File tree

6 files changed

+62
-21
lines changed

6 files changed

+62
-21
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ jobs:
2424
matrix:
2525
version:
2626
- '1.10'
27-
- '1.6'
28-
- 'pre'
27+
- '1'
2928
os:
3029
- ubuntu-latest
3130
arch:
3231
- x64
32+
include:
33+
- os: ubuntu-latest
34+
prefix: xvfb-run
3335
steps:
3436
- uses: actions/checkout@v4
3537
- uses: julia-actions/setup-julia@v2
@@ -39,6 +41,8 @@ jobs:
3941
- uses: julia-actions/cache@v2
4042
- uses: julia-actions/julia-buildpkg@v1
4143
- uses: julia-actions/julia-runtest@v1
44+
with:
45+
prefix: ${{ matrix.prefix }}
4246
- uses: julia-actions/julia-processcoverage@v1
4347
- uses: codecov/codecov-action@v5
4448
with:

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
name = "CounterMarking"
22
uuid = "454fbcff-fa78-4492-9c80-2cfc3f2a4b52"
33
authors = ["Tim Holy <[email protected]> and contributors"]
4-
version = "1.0.0-DEV"
4+
version = "1.0.0"
55

66
[deps]
77
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
88
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
9+
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
910
ImageMorphology = "787d08f9-d448-5407-9aad-5290dd7ab264"
1011
ImageSegmentation = "80713f31-8817-5129-9cf8-209ff8fb23e1"
1112
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -19,13 +20,15 @@ CounterMarkingImageViewExt = "ImageView"
1920
[compat]
2021
FileIO = "1"
2122
ImageCore = "0.10"
23+
ImageIO = "0.6"
2224
ImageMorphology = "0.4"
2325
ImageSegmentation = "1.9"
2426
ImageView = "0.12"
2527
julia = "1.10"
2628

2729
[extras]
30+
ImageView = "86fae568-95e7-573e-a6b2-d8a6b900c9ef"
2831
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2932

3033
[targets]
31-
test = ["Test"]
34+
test = ["ImageView", "Test"]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CounterMarking
22

33
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://HolyLab.github.io/CounterMarking.jl/stable/)
4-
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://HolyLab.github.io/CounterMarking.jl/dev/)
54
[![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)
65
[![Coverage](https://codecov.io/gh/HolyLab/CounterMarking.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/HolyLab/CounterMarking.jl)
6+
7+
Utilities for analyzing images from mouse territorial countermarking experiments.

ext/CounterMarkingImageViewExt.jl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ using ImageSegmentation
66
using ImageView
77
using Random
88

9-
function colorize(seg, segidxs::AbstractSet{Int}, color::Colorant)
10-
label = seg.image_indexmap
11-
img = similar(label, promote_type(typeof(color), valtype(seg.segment_means)))
12-
fill!(img, zero(eltype(img)))
13-
for idx in eachindex(label)
14-
label[idx] segidxs || continue
15-
img[idx] = color
16-
end
17-
return img
18-
end
9+
# function colorize(seg, segidxs::AbstractSet{Int}, color::Colorant)
10+
# label = seg.image_indexmap
11+
# img = similar(label, promote_type(typeof(color), valtype(seg.segment_means)))
12+
# fill!(img, zero(eltype(img)))
13+
# for idx in eachindex(label)
14+
# label[idx] ∈ segidxs || continue
15+
# img[idx] = color
16+
# end
17+
# return img
18+
# end
1919

2020
function linkpair(img, imgc)
21-
gd = imshow(img)
22-
zr = gd["roi"]["zoomregion"]
23-
slicedata = gd["roi"]["slicedata"]
24-
gdc = imshow(imgc, nothing, zr, slicedata)
25-
return (gd, gdc)
21+
zr, slicedata = roi(img)
22+
gd = imshow_gui((800, 800), (2,1); slicedata=slicedata)
23+
imshow(gd["frame"][1,1], gd["canvas"][1,1], img, nothing, zr, slicedata)
24+
imshow(gd["frame"][2,1], gd["canvas"][2,1], imgc, nothing, zr, slicedata)
25+
return gd
2626
end
2727

2828
# For visualization
@@ -34,4 +34,7 @@ end
3434
CounterMarking.randshow(seg; kwargs...) = imshow(map(i->get_random_color(i), labels_map(seg)); kwargs...)
3535
CounterMarking.meanshow(seg; kwargs...) = imshow(map(i->segment_mean(seg, i), labels_map(seg)); kwargs...)
3636

37+
CounterMarking.randshow(img, seg; kwargs...) = linkpair(img, map(i->get_random_color(i), labels_map(seg)); kwargs...)
38+
CounterMarking.meanshow(img, seg; kwargs...) = linkpair(img, map(i->segment_mean(seg, i), labels_map(seg)); kwargs...)
39+
3740
end

test/runtests.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
11
using CounterMarking
2+
using FileIO
23
using Test
34

45
@testset "CounterMarking.jl" begin
5-
# Write your tests here.
6+
testdir = "testimages"
7+
img = load(joinpath(testdir, "Picture.png"))
8+
seg = segment_image(img)
9+
# Without ImageView loaded, we can't visualize it, but we get a helpful error
10+
if !isdefined(@__MODULE__, :ImageView)
11+
@test_throws "using ImageView" randshow(seg)
12+
@test_throws "using ImageView" meanshow(seg)
13+
end
14+
@eval using ImageView
15+
dct = meanshow(seg)
16+
@test haskey(dct, "gui")
17+
dct = randshow(seg)
18+
@test haskey(dct, "gui")
19+
dct = randshow(img, seg)
20+
@test haskey(dct, "window")
21+
dct = meanshow(img, seg)
22+
@test haskey(dct, "window")
23+
ImageView.closeall()
24+
25+
spotdict, stimulus = spots(seg)
26+
_, stimspot = stimulus
27+
@test stimspot.npixels > 1000
28+
@test stimspot.centroid[1] < size(img, 1) ÷ 2
29+
@test stimspot.centroid[2] > size(img, 2) ÷ 2
30+
31+
stdspotdict, stdstimulus = upperleft(spotdict, stimulus, size(img))
32+
_, stimspot = stdstimulus
33+
@test stimspot.npixels > 1000
34+
@test stimspot.centroid[1] < size(img, 1) ÷ 2
35+
@test stimspot.centroid[2] < size(img, 2) ÷ 2
636
end

test/testimages/Picture.png

2.62 MB
Loading

0 commit comments

Comments
 (0)