Skip to content

Instantly share code, notes, and snippets.

@meggart
Created November 25, 2014 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meggart/20503e86e18ad21c9bbd to your computer and use it in GitHub Desktop.
Save meggart/20503e86e18ad21c9bbd to your computer and use it in GitHub Desktop.
Use label_components with non-Array output
type Naive_Sparse_3{T} <: AbstractArray{T,3}
size::(Int,Int,Int)
vals::Dict{Int,T}
end
function getindex(A::Naive_Sparse_3,i::Int)
A.vals[i]
end
function getindex(A::Naive_Sparse_3,i1::Int,i2::Int,i3::Int)
i=((i3-1)*A.size[1]+(i2-1))*A.size[2]+i1
getindex(A,i)
end
function setindex!(A::Naive_Sparse_3,x,i::Int)
A.vals[i]=x
end
function setindex!(A::Naive_Sparse_3,x,i1::Int,i2::Int,i3::Int)
i=((i3-1)*A.size[1]+(i2-1))*A.size[2]+i1
setindex!(A,x,i)
end
Base.size(A::Naive_Sparse_3)=A.size
label_components2(A, connectivity = 1:ndims(A), bkg = 0) = label_components!(Naive_Sparse_3(size(A),Dict{Int,Int}()), A, connectivity, bkg)
using Images
x=rand(100,100,1000);
x2=x.>0.95;
label_components(x2);
label_components2(x2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment