-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
region_adjacency_graph(), merge_hierarchical() and selective search #1736
Conversation
function to describe the graph's noded, edges and calculate the edge weights. Modified __init__.py to include region_adjacency_graph() Modified rag_mean_colour() to call region_adjacency_graph(). Provide the same functionality as the original. API signature of rag_mean_colour() is unchanged. Added flag to merge_hierarchical() to indicate the each step of the hierarchical merge is to be returned. merge_hierarchical() now returns a list of intermediate merge steps. Added a example application which uses the list of merge steps output from the modified hierarchical_merge() to propose regions that may contain an object.
skimage/future/graph/rag.py
Outdated
@@ -263,6 +266,125 @@ def rag_mean_color(image, labels, connectivity=2, mode='distance', | |||
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.11.5274 | |||
|
|||
""" | |||
|
|||
|
|||
def define_graph(graph,labels,image, extra_arguments=[], |
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.
Why does this method have a generic name ? It is doing something very specific, ie, defining a color similarity based RAG.
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.
The scope of the function is local to rag_mean_color()
. Are you suggesting to call it define_color_based_similarity()
?
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.
Oh I see, but nested functions are generally bad for performance. Cause even though the function is doing something specific, it has to be instantiated every time you made a call to the parent function. What I would do is put this outside with a name like define_mean_color_rag
or something similar.
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.
Ok. Can move to file/module level and give it a more descriptive name.
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.
Stylistic question. Since define_mean_color_rag
is not part of the public interface, essentially a "private" function used by rag_mean_color
, should it be called _define_mean_color_rag
, that is, have a leading underscore?
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.
should it be called _define_mean_color_rag, that is, have a leading underscore?
yes. =)
@michaelborck Thank you for your efforts. It is really exciting for us to see someone using and further enhancing our contributions. Could you attach the output image from the example so that all of us can see ? |
@vighneshbirodkar As requested, output image from |
to file/module level. Updated description of selective search example. Added new example demonstrating how to construct a RAG using `region_adjacency_graph` and a user defined callback to describe the nodes and calculate the edge weights. The example duplicates the "RAG Threshold" example from scikit-image gallery.
@@ -0,0 +1,151 @@ | |||
""" | |||
================ | |||
Selective Search |
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.
In this example I use the rag_mean_color()
and the callbacks from the RAG Merging example in the gallery. I did this thinking familiarity with the other RAG examples in the gallery and to keep the example code short. Instead, would it be better to use region_adjacency_graph()
, so will need another callback? Similar to the original paper on Selective Search (referenced in the example) should I use other similarity measures, say based on colour, texture, fill and size? These will make the example longer, but potentially more useful to others, and will also need some supporting functions like histogram_intersection
to calculate the weights. Thoughts?
@jni @vighneshbirodkar @michaelborck What's the status of this PR? |
Hey, @michaelborck @vighneshbirodkar @sciunto @jni @soupault If you change in rag.py in the line 324 from:
to:
(check the describe_func argument) And in graph_merge.py in the line 146 from:
to:
Conflicts should disappear. |
Overview
For my use case, I needed to sample an image to provide a list of regions that may contain an object. One strategy is to use an over-segmented image, hierarchical merging and a similarity measure to produce a list of proposals. I required the ability to generate a RAG with node descriptions and edge weights that differed from the default
rag_mean_color()
. To achieve this I created theregion_adjacency_graph()
method and modifiedmerge_heirachical()
. Provided two examples. The first example is a simplified version of my use case,Selected Search
. Picture of output below. The second example is how to construct a RAG usingregion_adjacency_graph
and a user specified callback. The second example example duplicates the functionality of "RAG Thresholding" from the scikit-image gallery.Replaces PR #1723
Description of Changes
Added method
region_adjacency_graph()
which allows a user defined function to describe the graph's nodes, edges and calculate the edge weights.Modified
__init__.py
to includeregion_adjacency_graph()
Modified
rag_mean_color()
to callregion_adjacency_graph()
. Provides the same functionality as the original by using a callback defined locally within the method (i.e. not file/module scope). The API signature ofrag_mean_colour()
is unchanged.Added flag to
merge_hierarchical()
to indicate the each step of the hierarchical merge is to be returned.merge_hierarchical()
now returns a list of intermediate merge steps. The list contains only regions merged, as opposed to a previous verison which contain complete lable maps.Added a example application which uses the list of merge steps output from the modified hierarchical_merge() to propose regions that may contain an object. The goal of the example application is a list of regions to be used by a machine learning process. To visualise some of these regions the example code plots the last 10 bounding boxes detected. Below is an exampleof the image produced by
plot_selective_search.py