diff --git a/src/regionprops.jl b/src/regionprops.jl index f0298d80..d5259e2e 100644 --- a/src/regionprops.jl +++ b/src/regionprops.jl @@ -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 """ diff --git a/test/test-regionprops-labeled.jl b/test/test-regionprops-labeled.jl index 381ba226..aefff915 100644 --- a/test/test-regionprops-labeled.jl +++ b/test/test-regionprops-labeled.jl @@ -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) == [ @@ -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