PyMaxflow icon indicating copy to clipboard operation
PyMaxflow copied to clipboard

3D grid support (take 2)

Open mxhf opened this issue 5 years ago • 5 comments

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

mxhf avatar Aug 23 '19 18:08 mxhf

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!

pmneila avatar Aug 23 '19 21:08 pmneila

OK, I clearly should have been able to figure this out myself. Many thanks!

Quick additional question though.

I'd like to be able to set the "structure" or costs according to neighboring pixel value differences (in a 3D pixel cube).

And idea on how to achieve this while pushing it to the c++ layer. Doing it a python loop takes foerever.

Max

On Fri, Aug 23, 2019 at 11:14 PM pmneila [email protected] wrote:

Closed #43 https://github.com/pmneila/PyMaxflow/issues/43.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pmneila/PyMaxflow/issues/43?email_source=notifications&email_token=AB2AZST6B6XUF3LASUCG62TQGBHLJA5CNFSM4IPCG4K2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTHKOVVQ#event-2580867798, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2AZSQ2BRK6RCU734EI6N3QGBHLJANCNFSM4IPCG4KQ .

--

Maximilian Fabricius

  • Max Planck Institute for Extraterrestrial Physics (MPE) Giessenbachstrasse, D-85748 Garching, Germany
  • University Observatory Munich / Wendelstein Observatory Scheinerstr. 1, D-81679 München, Germany eMail: [email protected] Phone: +49 89 30000 3779

mxhf avatar Aug 25 '19 09:08 mxhf

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?

pmneila avatar Aug 26 '19 12:08 pmneila

I have (now), yes I know the custom structure

ala

structure = np.array([[[0, 1, 0],
                        [1, 1, 1],
                        [0, 1, 0]],
                       [[0, 1, 0],
                        [1, 0, 1],
                        [0, 1, 0]],
                       [[0, 1, 0],
                        [1, 1, 1],
                        [0, 1, 0]]])

but I want to adjust the structure on a pixel by pixel basis. Essentially the interpixel edge capacity should be a function of the pixel value differences.

This is easy of course if I do it in python but slow.

Max

On Mon, Aug 26, 2019 at 2:49 PM pmneila [email protected] wrote:

Reopened #43 https://github.com/pmneila/PyMaxflow/issues/43.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pmneila/PyMaxflow/issues/43?email_source=notifications&email_token=AB2AZSVDD5TURBVT2M44SNTQGPGNLA5CNFSM4IPCG4K2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOTH7CQJA#event-2583570468, or mute the thread https://github.com/notifications/unsubscribe-auth/AB2AZSQLBX47O63GZGE7FHTQGPGNLANCNFSM4IPCG4KQ .

--

Maximilian Fabricius

  • Max Planck Institute for Extraterrestrial Physics (MPE) Giessenbachstrasse, D-85748 Garching, Germany
  • University Observatory Munich / Wendelstein Observatory Scheinerstr. 1, D-81679 München, Germany eMail: [email protected] Phone: +49 89 30000 3779

mxhf avatar Aug 26 '19 16:08 mxhf

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

https://numba.pydata.org/

nirmalsnair avatar Aug 13 '21 07:08 nirmalsnair