Skip to content

Commit 1187528

Browse files
committed
fixed checkbox indexing
1 parent 7a1574b commit 1187528

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/gui.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ function gui(
4141
bkgmean = Float32(mean(bkgimg))
4242
seg = nothing
4343
threshold = 0.15
44-
44+
labels2idx = Dict{Int,Int}()
45+
idx2labels = Dict{Int,Int}()
4546
# Set up basic properties of the window
4647
winsize = round.(Int, 0.8 .* screen_size())
4748
win = GtkWindow("CounterMarking", winsize...)
@@ -121,10 +122,13 @@ function gui(
121122
seg = segment_image(rescaledimg; threshold = newvalue)
122123
nsegs = length(segment_labels(seg))
123124
nsegs > length(colors) && @warn "More than $(length(colors)) segments ($(nsegs)). Excluded ones will be displayed in white and will not be selectable"
124-
labels2idx = Dict{Int,Int}()
125+
empty!(labels2idx)
126+
empty!(idx2labels)
125127
for (i,l) in enumerate(sort(seg.segment_labels; rev=true, by=(l -> segment_pixel_count(seg,l))))
126-
idx = i > 15 ? 2 : i
128+
idx = i == 1 ? 2 : i == 2 ? 1 : i
129+
idx = i > 15 ? 1 : idx # show remaining segments in white
127130
push!(labels2idx, l=>idx)
131+
push!(idx2labels, idx=>l)
128132
end
129133
istim = labels2idx[stimulus_index(seg)]
130134
for (j, cb) in enumerate(cbs)
@@ -177,27 +181,29 @@ function gui(
177181
seg = segment_image(rescaledimg; threshold = threshold)
178182
nsegs = length(segment_labels(seg))
179183
nsegs > length(colors) && @warn "More than $(length(colors)) segments ($(nsegs)). Excluded ones will be displayed in white and will not be selectable"
180-
labels2idx = Dict{Int,Int}()
184+
empty!(labels2idx)
185+
empty!(idx2labels)
181186
for (i,l) in enumerate(sort(seg.segment_labels; rev=true, by=(l -> segment_pixel_count(seg,l))))
182187
idx = i == 1 ? 2 : i == 2 ? 1 : i
183-
idx = i > 15 ? 1 : idx
188+
idx = i > 15 ? 1 : idx # show remaining segments in white
184189
push!(labels2idx, l=>idx)
190+
push!(idx2labels, idx=>l)
185191
end
186192
istim = labels2idx[stimulus_index(seg)]
187193
for (j, cb) in enumerate(cbs)
188194
# set_gtk_property!(cb, "active", j <= nsegs)
189195
cb[] = (j == istim || j == preclick)
190196
end
191197
imshow(canvases[1, 1], img)
192-
imshow(canvases[2, 1], map(i->colors[labels2idx[i]], labels_map(seg)))
198+
imshow(canvases[2, 1], map(l->colors[labels2idx[l]], labels_map(seg)))
193199

194200
wait(btnclick)
195201
whichbutton[] == :skip && continue
196202

197203
keep = Int[]
198204
for (j, cb) in enumerate(cbs)
199205
if cb[]
200-
push!(keep, j)
206+
push!(keep, idx2labels[j])
201207
end
202208
end
203209
pixelskeep = map(i -> i keep, labels_map(seg))

0 commit comments

Comments
 (0)