This snippet:
using ImageMorphology
a = reshape(collect(1:36), 6, 6)
labels = label_components(a .> 16, trues(3,3))
box = component_boxes(labels)[2]
returns a bounding box:
2-element Array{Tuple{Int64,Int64},1}:
(1, 3)
(6, 6)
I’m looking for a convenient notation to use box
for operations inside subarray delimited by it. Is there a shorter way to write this view:
v = @view a[box[1][1]:box[2][1], box[1][2]:box[2][2]]
Is there an easier way to convert index i
of subarray v
into an index j
of parent array a
than:
i = argmax(v)
j = i + CartesianIndex(box[1]) - CartesianIndex((1, 1))