Reputation: 1664
Is there an equivalent of MATLAB's pcnormals
in Julia?
I also would like to know if there is a way to read and write .ply
files in Julia?
Upvotes: 1
Views: 273
Reputation: 18217
From the description of pcnormals
here is an attempt to recreate it using Julia with the aid of the Distances and kNN packages:
using Distances
using kNN
function pcnormals(pcloud::Matrix,k::Int = 6)
n,d = size(pcloud)
S = pairwise(Euclidean(),pcloud')
NN = hcat([kNN.k_nearest_neighbors(k,i,S) for i=1:n]...)'
normals = hcat([normalize(pcloud[[i;NN[i,:]],:]\ones(k+1)) for i=1:n]...)'
return normals
end
N = 1000
D = 3
X = mapslices(normalize,randn(N,D),2)
normals = pcnormals(X)
println("mean inner product = $(mean(X[1:10,:]*normals[1:10,:]'))")
diag(X[1:10,:]*normals[1:10,:]')
The code after the definition is a mini-test which tries to look at points on the unit sphere and see if the normal of a point is close to itself (using inner-product as a similarity measure). The results looked convincing:
mean inner product = 0.18584539662300542
10-element Array{Float64,1}:
0.990708
0.999839
0.997276
0.999705
0.99959
0.999883
0.999052
0.998935
0.9951
0.999617
So, unless the quick look at pcnormals
manual page has mislead me, this may be a starting point for a Julia implementation. Note the use of pairwise
in the code which could be slow for big point clouds.
Upvotes: 2