-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added normalized graph cut #8
Conversation
Since adjacency matrix for grid connectivity based graphs are sparse, the paper used Lanczos solver. For small matrices |
I assume you're using the One other general comment: since this is purely graph-theoretical, have you considered whether this part of the algorithm should live in a different repository? I'm not at all opposed to having it here, but if it's of use outside of image processing perhaps it would be better in a graphs-oriented package? |
As far I know, the normalized graph-cut problem and the algorithm were first introduced in the context of image segmentation. If this algorithm is more generally used, I agree that this should be in a graph-oriented package. |
From reading the algorithm, to me it looks generally useful. Perhaps @sbromberger could comment? |
This looks very interesting. @tejus-gupta - We'd have to adapt it a bit to be generally applicable to LightGraphs, but if you're up for the discussion, please feel free to file a WIP PR at https://github.com/JuliaGraphs/LightGraphs.jl and we can start the review. One thing to start: we should not assume that |
cc @jpfairbanks to weigh in here since this is squarely in one of his (many) areas of expertise. |
end | ||
|
||
#get eigenvector corresponding to second smallest eigenvalue | ||
v = eigvecs(full(D-W), full(D))[:, 2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could replace this with
\lambda, vs = eigs(CombinatorialLaplacian(g), nev=2, which=:SM)
v = v[:,2]
min_cost = cost | ||
best_thres = t | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can optimize this to use matrix permutation and one matrix vector product to calculate all nv(g)
possible cuts at once. But this one works well enough for large ncuts
.
I interpret the above discussion as saying that the core graph algorithm should live in LightGraphs, and the image-related preparation/postprocessing can go here. Please link any LightGraphs PR to this issue. |
@timholy Yes, normalized graph cut is a generic graph algorithm that can go in lightgraphs. The parts that are image specific would be calculating the edge set and weights from the pixel values. We would not want an algorithm in lightgraphs that took an image as the input. But once you have extracted a graph (with or without weights), then LG can take over. Turning the segments back into sets of pixel locations or whatever you want to do with them should live in this package. |
I am sorry for the delayed reply. I will open the pull request right away. |
Is this entirely superseded by sbromberger/LightGraphs.jl#736, or is there an image-specific component here? |
I didn't include the code for constructing a region adjacency graph from an image and so this is entirely replaced by sbromberger/LightGraphs.jl#736. I think we should add a generic function to create a region adjacency graph from an image and advice the user to use graph clustering methods available in other packages. |
Thanks. I'll close this, and we can implement those good ideas in separate PRs. |
Segments graph using recursive two-way normalized graph cut as described in this paper - Normalized Cuts and Image Segmentation