Skip to content

Commit 305d75a

Browse files
committed
Add GUI test
Also fixes the doc build
1 parent f173ba2 commit 305d75a

File tree

5 files changed

+48
-26
lines changed

5 files changed

+48
-26
lines changed

.github/workflows/CI.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,19 @@ jobs:
6969
Pkg.develop(PackageSpec(path=pwd()))
7070
Pkg.instantiate()
7171
- uses: julia-actions/julia-buildpkg@v1
72+
with:
73+
prefix: xvfb-run
7274
- uses: julia-actions/julia-docdeploy@v1
75+
with:
76+
prefix: xvfb-run
7377
env:
7478
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7579
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
7680
- name: Run doctests
77-
shell: julia --project=docs --color=yes {0}
81+
shell: xvfb-run julia --project=docs --color=yes {0}
7882
run: |
7983
using Documenter: DocMeta, doctest
8084
using CounterMarking
8185
DocMeta.setdocmeta!(CounterMarking, :DocTestSetup, :(using CounterMarking); recursive=true)
8286
doctest(CounterMarking)
87+

docs/src/assets/Picture.png

2.62 MB
Binary file not shown.

docs/src/assets/Picture.png

2.53 MB
Loading

src/gui.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11

2-
function gui(outbase, files; colors=distinguishable_colors(15, [RGB(1, 1, 1)]; dropseed=true))
2+
function gui(
3+
outbase, files;
4+
colors=distinguishable_colors(15, [RGB(1, 1, 1)]; dropseed=true),
5+
btnclick = Condition(), # used for testing
6+
whichbutton = Ref{Symbol}(), # used for testing
7+
)
38
channelpct(x) = string(round(Int, x * 100)) * '%'
49

510
outbase, _ = splitext(outbase)
@@ -60,8 +65,6 @@ function gui(outbase, files; colors=distinguishable_colors(15, [RGB(1, 1, 1)]; d
6065
push!(cbs, cb)
6166
end
6267
# Add "Done & Next" and "Skip" buttons
63-
btnclick = Condition()
64-
whichbutton = Ref{Symbol}()
6568
donebtn = button("Done & Next")
6669
skipbtn = button("Skip")
6770
push!(guibx, donebtn)
@@ -129,6 +132,8 @@ function gui(outbase, files; colors=distinguishable_colors(15, [RGB(1, 1, 1)]; d
129132
end
130133
end
131134
destroy(win)
135+
notify(btnclick) # used in testing
136+
return
132137
end
133138
gui(outbase, glob::Glob.GlobMatch; kwargs...) = gui(outbase, Glob.glob(glob); kwargs...)
134139

src/segment.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function segment_image(
1414
)
1515
seg = unseeded_region_growing(img, threshold)
1616
if prune
17-
println("Pruning segments smaller than $min_size pixels")
17+
# println("Pruning segments smaller than $min_size pixels")
1818
seg = prune_segments(seg, label -> segment_pixel_count(seg, label) < min_size, (l1, l2) -> colordiff(segment_mean(seg, l1), segment_mean(seg, l2)))
1919
end
2020
return seg
@@ -34,18 +34,18 @@ function stimulus_index(seg::SegmentedImage, colorproj = RGB{Float32}(1, 1, -2))
3434
return i
3535
end
3636

37-
function contiguous(seg::SegmentedImage, img::AbstractMatrix{<:Color}; min_size::Int = 50)
38-
L = label_components(labels_map(seg)) # insist on contiguous regions
39-
newseg = SegmentedImage(img, L)
40-
newseg = prune_segments(newseg, label -> segment_pixel_count(newseg, label) < min_size, (l1, l2) -> colordiff(segment_mean(newseg, l1), segment_mean(newseg, l2)))
41-
mapping = Dict(k => Set{Int}() for k in segment_labels(seg))
42-
for (i, l) in pairs(seg.image_indexmap)
43-
push!(mapping[l], newseg.image_indexmap[i])
44-
end
45-
return mapping
46-
end
47-
contiguous(seg::SegmentedImage, img::AbstractMatrix{<:Colorant}; kwargs...) =
48-
contiguous(seg, color.(img); kwargs...)
37+
# function contiguous(seg::SegmentedImage, img::AbstractMatrix{<:Color}; min_size::Int = 50)
38+
# L = label_components(labels_map(seg)) # insist on contiguous regions
39+
# newseg = SegmentedImage(img, L)
40+
# newseg = prune_segments(newseg, label -> segment_pixel_count(newseg, label) < min_size, (l1, l2) -> colordiff(segment_mean(newseg, l1), segment_mean(newseg, l2)))
41+
# mapping = Dict(k => Set{Int}() for k in segment_labels(seg))
42+
# for (i, l) in pairs(seg.image_indexmap)
43+
# push!(mapping[l], newseg.image_indexmap[i])
44+
# end
45+
# return mapping
46+
# end
47+
# contiguous(seg::SegmentedImage, img::AbstractMatrix{<:Colorant}; kwargs...) =
48+
# contiguous(seg, color.(img); kwargs...)
4949

5050
struct Spot
5151
npixels::Int
@@ -75,7 +75,7 @@ function spots(
7575
label = seg.image_indexmap
7676
R = CartesianIndices(label)
7777
Ibegin, Iend = extrema(R)
78-
I1 = one(Ibegin)
78+
I1 = oneunit(Ibegin)
7979
centroidsacc = Dict{Int, Tuple{Int, Int, Int}}() # accumulator for centroids
8080
nadj = Dict{Tuple{Int, Int}, Int}() # number of times two segments are adjacent
8181
for idx in R
@@ -140,11 +140,11 @@ function upperleft(spotdict::AbstractDict{Int, Spot}, stimulus, imgsize)
140140
return Dict(k => flip(v) for (k, v) in spotdict), sidx => flip(ss)
141141
end
142142

143-
function colorize(seg::SegmentedImage, coloridx::AbstractDict, colors=distinguishable_colors(length(unique(values(coloridx)))))
144-
label = seg.image_indexmap
145-
img = similar(label, eltype(colors))
146-
for idx in eachindex(label)
147-
img[idx] = colors[coloridx[label[idx]]]
148-
end
149-
return img
150-
end
143+
# function colorize(seg::SegmentedImage, coloridx::AbstractDict, colors=distinguishable_colors(length(unique(values(coloridx)))))
144+
# label = seg.image_indexmap
145+
# img = similar(label, eltype(colors))
146+
# for idx in eachindex(label)
147+
# img[idx] = colors[coloridx[label[idx]]]
148+
# end
149+
# return img
150+
# end

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ using Test
4040
process_images(tmpfile, glob"*.png"; dirname=testdir)
4141
data = XLSX.readtable(tmpfile, "Picture")
4242
@test isa(data, XLSX.DataTable)
43+
44+
# Test the gui
45+
rm(tmpfile, force=true)
46+
btnclick = Condition()
47+
whichbutton = Ref{Symbol}()
48+
@async gui(tmpfile, [joinpath(testdir, "Picture.png")]; btnclick, whichbutton)
49+
sleep(5)
50+
whichbutton[] = :done
51+
notify(btnclick)
52+
wait(btnclick)
53+
@test isfile(tmpfile)
54+
@test isfile(splitext(tmpfile)[1] * ".jld2")
4355
end

0 commit comments

Comments
 (0)