Created
November 25, 2014 15:55
-
-
Save meggart/20503e86e18ad21c9bbd to your computer and use it in GitHub Desktop.
Use label_components with non-Array output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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