pmneila/PyMaxflow

3D grid support (take 2)

Opened this issue · 5 comments

mxhf commented

Hi,

I am trying to create a 3D grid like

nodes = g.add_nodes( (c.shape[0],c.shape[1],c.shape[2]) )
(c is a 3D numpy array)

But am getting
TypeError: an integer is required

Any suggestions?

Max

Hi @mxhf,

add_nodes expects a single integer and creates as many nodes as indicated by that integer. I think you might be looking for add_grid_nodes, which takes a tuple of integers:

nodes = g.add_grid_nodes( (c.shape[0], c.shape[1], c.shape[2]) )

Also note that if c is a 3D array, you can simply write:

nodes = g.add_grid_nodes(c.shape)

Regards!

mxhf commented

Hi @mxhf,

Have you looked at the layout_example3D.py? It builds a 3D graph and then connects nodes with a specific pattern (that of course can be adapted to your needs). Is this what you want?

mxhf commented

You could use numba to speed-up your Python loops. Usually, I get 10-100x speed-up.

https://numba.pydata.org/