skan icon indicating copy to clipboard operation
skan copied to clipboard

Network to raster array

Open jpgard opened this issue 4 years ago • 3 comments

Thanks for the awesome software!

Currently skan supports the generation of graphs from a pixel array. However, it doesn't go in the other direction -- i.e., we have a networkx graph which includes coordinates as an attribute of each node, and we want a rasterized array (either 2D or 3D) which represents it.

In the PeerJ paper Methods section ( https://peerj.com/articles/4312/ ) , the authors describe converting an SWC file into a volume using the Simple Neurite Tracer plugin for Fiji. However, this functionality doesn't seem to exist anymore (I also have data in SWC format, which is being converted to a networkx graph via custom Python).

Are there plans to support this? Or, do you have any suggestions on how to convert graphs, especially those contained in SWC files, to a 3D array?

jpgard avatar Jan 24 '20 01:01 jpgard

Ha, that’s a nice amount of detail in the methods section, pretty proud of myself even though it doesn’t work anymore! =P

Anyway, thank you for your kind words and for using the library!

I would be very interested to have support for reading swc in skan. Additionally, since skimage 0.16, we have 3D line drawing, see here:

https://scikit-image.org/docs/stable/api/skimage.draw.html#skimage.draw.line_nd

It should be reasonably straightforward to chain a bunch of these calls together to rasterise from coordinates.

Are you familiar with github pull requests? I’d be super happy to add this to the library if you made a PR. (And I’d also be happy to guide you through the process.) Otherwise, I can try to do this, but I’m not sure when I will have time.

Thanks!

jni avatar Jan 24 '20 22:01 jni

Oh, great. Yes, skimage.draw.line_nd() can make all of that work, nice. Agreed that this is straightforward with that function in the toolbox. From what I can tell, if the input graph is fully connected, the rasterized array from skimage.draw.line_nd() will also be fully connected, yes? (Each pixel/voxel will touch another pixel/voxel along at least one face?)

I can create a PR for the graph --> raster array. (Just to confirm: there is also not a skan function which does this in 2D either?).

Seems like SWC support would be best in a separate PR; if you would like to create a Github issue with some specs and assign to me, I can contribute that feature (we already have code to do this).

jpgard avatar Jan 24 '20 22:01 jpgard

@jpgard

From what I can tell, if the input graph is fully connected, the rasterized array from skimage.draw.line_nd() will also be fully connected, yes?

I think so! Having said that, there hasn't been too much real-world testing of that function, so we'll see whether any bugs are uncovered by your work! :grimacing:

(Just to confirm: there is also not a skan function which does this in 2D either?).

Correct. (At least, I don't remember adding one! :sweat_smile:)

if you would like to create a Github issue with some specs and assign to me,

Ok, will do so later today or tomorrow. The short version is to get from SWC to a Skeleton object, which should be easy enough since nx is already a dependency and provides a to_scipy_sparse_matrix function.

Thank you!

jni avatar Jan 27 '20 02:01 jni