Skip to content

Commit

Permalink
fix SuperPixel for ndims(color)!=ndims(position)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 committed Oct 10, 2019
1 parent 07511f7 commit 3f85b16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,16 @@ synthesize(img_sp, Average()) # each superpixel is averaged first
"""
struct SuperPixel{T<:Colorant, N, AT<:AbstractArray{T}}
color::AT
position::CartesianIndices{N}

function SuperPixel{T, N, AT}(
color::AT,
position::CartesianIndices{N}) where {
T<:Colorant, N,
AT<:AbstractArray{T}}
color = length(color) == length(position) ? color : color[position]
new(color, position)
end
position
end

SuperPixel(color::AT, position::CartesianIndices{N}) where {
T<:Colorant, N, AT<:AbstractArray{T}} =
SuperPixel{T, N, AT}(color, position)
function SuperPixel(
color::AbstractArray{T},
position::AbstractArray{CartesianIndex{N}}) where {T<:Colorant, N}

color = length(color) == length(position) ? color : color[position]
SuperPixel{T, N, typeof(color)}(color, position)
end

SuperPixel(color::AbstractArray{<:Colorant}, pos::Tuple) =
SuperPixel(color, CartesianIndices(pos))
Expand Down
1 change: 1 addition & 0 deletions test/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
pos = CartesianIndices(pos)
sp3 = SuperPixel(img, pos)
sp4 = SuperPixel(img[pos], pos)
@test_nowarn SuperPixel(img, pos[:])

@test eltype(sp1.color) <: Colorant # Number is promoted to Gray
@test size(sp1.color) == size(sp1.position)
Expand Down

0 comments on commit 3f85b16

Please sign in to comment.