BiomedSciAI/histocartography

Question on the expected behavior for RAGGraphBuilder

snibbor opened this issue · 0 comments

Hello,

Thank you for your work, this package has been very useful and I enjoy learning from your source code.

I was preparing a dataset using the RAGGraphBuilder and noticed that all my tissue graphs had edges that connected all the "background" or 0 instance map valued nodes in the graph.

Original RAG graph:

before_RAG_fix

I noticed in the adjacency graph that the nth row and column correspond to the 0 instance map node, and that you can remove these edges by modifying the _build_topology method to:
for instance_id in np.arange(1, len(instance_ids) + 1):
mask = (instance_map == instance_id).astype(np.uint8)
dilation = cv2.dilate(mask, kernel, iterations=1)
boundary = dilation - mask
idx = pd.unique(instance_map[boundary.astype(bool)])
instance_id -= 1 # because instance_map id starts from 1
idx -= 1 # because instance_map id starts from 1
idx = idx[idx >= 0] # remove background idx and prevents "end" node -1 from making edges
adjacency[instance_id, idx] = 1

Modified RAG graph:

after_RAG_fix

I am new to learning about GNNs and am not familiar with the pros or cons of having the graph connected this way originally or disconnected. I would think that having a connected graph with the "background" nodes connected by edges would allow the GNN to perform message passing through those edges, so the original method may be desirable.

More importantly, I was wondering if these edges between the 0 instance map nodes was the expected behavior for the method.

Thank you again!
Jack