Skip to content

Instantly share code, notes, and snippets.

@Gnimuc
Created June 3, 2016 08:59
Show Gist options
  • Save Gnimuc/04cd06a7ff242ecd49af0471c3822880 to your computer and use it in GitHub Desktop.
Save Gnimuc/04cd06a7ff242ecd49af0471c3822880 to your computer and use it in GitHub Desktop.
[NRIRHOPM] Topology Preservation Dilemma
function topology(s1::Tuple{Int64,Int64}, s2::Tuple{Int64,Int64}, s3::Tuple{Int64,Int64}, a::Tuple{Int64,Int64}, b::Tuple{Int64,Int64}, c::Tuple{Int64,Int64})
ks1 = (s1[1]+a[1], s1[2]+a[2])
ks2 = (s2[1]+b[1], s2[2]+b[2])
ks3 = (s3[1]+c[1], s3[2]+c[2])
dφ1 = ks2[1] - ks1[1]
dr1 = s2[1] - s1[1]
dφ2 = ks2[2] - ks3[2]
dr2 = s2[2] - s3[2]
dφ3 = ks2[2] - ks1[2]
# dr3 = dr1
dφ4 = ks2[1] - ks3[1]
# dr4 = dr2
v = (dφ1/dr1 * dφ2/dr2) - (dφ3/dr1 * dφ4/dr2)
return v::Float64
end
deformers = [[(i,j) for i in -1:1, j in -1:1]...]
imageDims = (4,4)
pixelRange = CartesianRange(imageDims)
pixelFirst, pixelEnd = first(pixelRange), last(pixelRange)
for ii in pixelRange
if ii.I == (2,2)
i = sub2ind(imageDims, ii.I...)
neighbors = CartesianRange(max(pixelFirst, ii-pixelFirst), min(pixelEnd, ii+pixelFirst))
for jj in neighbors
if jj != ii && (jj.I == (2,1) || jj.I == (1,2))
j = sub2ind(imageDims, jj.I...)
treyFirst, treyEnd = first(neighbors), last(neighbors)
treyNeighbors = CartesianRange(max(treyFirst, jj-pixelFirst), min(treyEnd, jj+pixelFirst))
for kk in treyNeighbors
if kk != ii && kk != jj && (kk.I == (2,1) || kk.I == (1,2))
k = sub2ind(imageDims, kk.I...)
for a = 1:3, b = 1:3, c = 1:3
potential = topology(ii.I, jj.I, kk.I, deformers[a], deformers[b], deformers[c])
@show jj.I, b, kk.I, c
@show potential
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment