Skip to content

Commit 79f72cb

Browse files
authored
Calculate spot/pixel distances from the stimulus (#14)
* added spot/pixel distance from stimulus calculation * return vector of distances
1 parent b9cc3b0 commit 79f72cb

File tree

3 files changed

+53
-12
lines changed

3 files changed

+53
-12
lines changed

src/CounterMarking.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ using Statistics
1717
export segment_image, stimulus_index, spots, Spot, upperleft
1818
export writexlsx, process_images, density_map
1919
export randshow, meanshow, gui
20+
export spot_distances, pixel_distances
2021

2122
include("segment.jl")
2223
include("xlxs.jl")
2324
include("gui.jl")
25+
include("distances.jl")
2426

2527
end

src/distances.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# pixel distance for each spot
2+
function spot_distances(spot_dict, stimulus)
3+
origin = stimulus[2].centroid
4+
dists = Float64[]
5+
for (i,s) in spot_dict
6+
push!(dists, sqrt(sum(abs2, s.centroid .- origin)))
7+
end
8+
return sort(dists)
9+
end
10+
11+
# pixel distance for each pixel belonging to a mark
12+
function pixel_distances(indexmap, stimulus)
13+
origin = stimulus[2].centroid
14+
dists = Float64[]
15+
for c in CartesianIndices(indexmap)
16+
if indexmap[c] != 0 && indexmap[c] != stimulus[1]
17+
push!(dists, sqrt(sum(abs2, Tuple(c) .- origin)))
18+
end
19+
end
20+
return sort(dists)
21+
end

src/segment.jl

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,43 @@ function spots(
121121
stimulus[] = key => Spot(val[3], (round(Int, val[1] / val[3]), round(Int, val[2] / val[3])))
122122
return false
123123
end
124-
val[3] <= max_size_frac * length(seg.image_indexmap) || return false
124+
return val[3] <= max_size_frac * length(seg.image_indexmap)
125125
# # is the centroid within the segment?
126126
# x, y = round(Int, val[1] / val[3]), round(Int, val[2] / val[3])
127127
# l = seg.image_indexmap[x, y]
128128
# @show l
129129
# l == key || return false
130130
# is the segment lighter than most of its neighbors?
131-
dcol, ncol = zero(valtype(seg.segment_means)), 0
132-
for (k, n) in nadj
133-
if key == k[1] || key == k[2]
134-
l1, l2 = k[1], k[2]
135-
if l1 == key
136-
l1, l2 = l2, l1
137-
end
138-
dcol += n * (segment_mean(seg, l1) - segment_mean(seg, l2))
139-
ncol += n
140-
end
131+
# dcol, ncol = zero(valtype(seg.segment_means)), 0
132+
# for (k, n) in nadj
133+
# if key == k[1] || key == k[2]
134+
# l1, l2 = k[1], k[2]
135+
# if l1 == key
136+
# l1, l2 = l2, l1
137+
# end
138+
# dcol += n * (segment_mean(seg, l1) - segment_mean(seg, l2))
139+
# ncol += n
140+
# end
141+
# end
142+
# return reducec(+, dcol) < 0
143+
end
144+
return Dict(l => Spot(val[3], (round(Int, val[1] / val[3]), round(Int, val[2] / val[3]))) for (l, val) in centroidsacc), stimulus[]
145+
end
146+
147+
function spots(
148+
indexmap::Matrix{Int},
149+
istim::Int;
150+
max_size_frac=0.1,
151+
kwargs...
152+
)
153+
centroidsacc, nadj = get_centroidsacc(indexmap)
154+
stimulus = Ref{Pair{Int,Spot}}()
155+
filter!(centroidsacc) do (key, val)
156+
if key == istim
157+
stimulus[] = key => Spot(val[3], (round(Int, val[1] / val[3]), round(Int, val[2] / val[3])))
158+
return false
141159
end
142-
return reducec(+, dcol) < 0
160+
return val[3] <= max_size_frac * length(indexmap)
143161
end
144162
return Dict(l => Spot(val[3], (round(Int, val[1] / val[3]), round(Int, val[2] / val[3]))) for (l, val) in centroidsacc), stimulus[]
145163
end

0 commit comments

Comments
 (0)