Skip to content

Commit

Permalink
remove ability to crop floes without bounding boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
hollandjg committed Nov 4, 2024
1 parent aaef1e0 commit 180c8bf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 119 deletions.
32 changes: 0 additions & 32 deletions src/regionprops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,39 +271,7 @@ function cropfloe(floesimg::Matrix{I}, min_row::J, min_col::J, max_row::J, max_c
return floe_area
end

"""
cropfloe(floesimg, label)
Crops the floe from `floesimg` with the label `label`, adding a one pixel border of zeros and converting to a BitMatrix.
"""
function cropfloe(floesimg::Matrix{I}, label::I) where {I<:Integer}
#= Remove any pixels not corresponding to that numbered floe
(each segment has a different integer) =#
floe_area = floesimg .== label
@debug "mask: $floe_area"

# Crop the floe to the size of the floe.
nonzero = x -> x > 0
rows = 2
cols = 1
row_sums = count(floe_area, dims=rows)
col_sums = count(floe_area, dims=cols)
@debug "row_sums: $row_sums, col_sums: $col_sums"

min_row = findfirst(nonzero, row_sums)[cols]
min_col = findfirst(nonzero, col_sums)[rows]
max_row = findlast(nonzero, row_sums)[cols]
max_col = findlast(nonzero, col_sums)[rows]
@debug "($min_row, $min_col), ($max_row, $max_col)"

floe_area_cropped = floe_area[min_row:max_row, min_col:max_col]
@debug "floe_area_cropped: $floe_area_cropped"

floe_area_padded = parent(padarray(floe_area_cropped, Fill(0, (1, 1))))
@debug "floe_area_padded: $floe_area_padded"

return BitMatrix(floe_area_padded)
end


"""
Expand Down
87 changes: 0 additions & 87 deletions test/test-regionprops-labeled.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,52 +123,6 @@
@test cropfloe(img1, props_without_label, 4) == cropfloe(img1, props_without_label, 5)



@info "testing props with only label"
props_only_label = DataFrame(label=1:5)

@test cropfloe(img1, props_only_label, 1) == [
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
]

@test cropfloe(img1, props_only_label, 2) == [
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
]

@test cropfloe(img1, props_only_label, 3) == [
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 0 0
0 0 0 0 0 0
]

@test cropfloe(img1, props_only_label, 4) == [
0 0 0 0 0 0 0
0 1 1 1 1 0 0
0 1 0 0 0 0 0
0 1 0 0 0 0 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
]

@test cropfloe(img1, props_only_label, 5) == [
0 0 0 0 0 0
0 0 0 0 1 0
0 1 1 1 1 0
0 1 1 0 0 0
0 0 0 0 0 0
]


@info "testing values with label"
# cropfloe
@test cropfloe(img1, 1, 1, 4, 4, 1) == [
Expand Down Expand Up @@ -213,45 +167,4 @@
0 0 0 0 0 0 0
]

@test cropfloe(img1, 1) == [
0 0 0 0
0 1 1 0
0 1 1 0
0 0 0 0
]

@test cropfloe(img1, 2) == [
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 0 1 1 0
0 0 0 0 0
]

@test cropfloe(img1, 3) == [
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 0 0
0 0 0 0 0 0
]

@test cropfloe(img1, 4) == [
0 0 0 0 0 0 0
0 1 1 1 1 0 0
0 1 0 0 0 0 0
0 1 0 0 0 0 0
0 1 1 1 1 1 0
0 0 0 0 0 0 0
]

@test cropfloe(img1, 5) == [
0 0 0 0 0 0
0 0 0 0 1 0
0 1 1 1 1 0
0 1 1 0 0 0
0 0 0 0 0 0
]

end

0 comments on commit 180c8bf

Please sign in to comment.