Spectral Clustering, Image Segmentation and Eigenvectors

旧时模样 提交于 2019-12-03 04:53:22

I've just tried the algorithm in Mathematica, it works fine on your image, so there must be a subtle bug in your code.

This part:

V,D = np.linalg.eig(A)
V = np.real(V)
res = n_max(V,1) # take largest 
idx = res[0][1][0] 
a = np.real(D[idx]) # look at corresp eigv

looks strange: all linear algebra packages I know return the eigenvalues/eigenvectors sorted, so you'd just take the first eigenvector in the list. That's the one that corresponds to the highest eigenvalue. Try plotting the eigenvalues list to confirm that.

Also, where did you get the fixed threshold from? Have you tried normalizing the image to display it?

For what it's worth, the results I'm getting for the first 3 eigenvectors are:

This is the Mathematica code I use:

pixels = Flatten[image];
weights = Table[N[Exp[-(pixels[[i]] - pixels[[j]])^2]], {i, 1, 900}, {j, 1, 900}];
eigenVectors = Eigenvectors[weights];
ImageAdjust[Image[Partition[eigenVectors[[1]], 30]]]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!