I’m working with a 3d “image” and am trying to figure out how to more efficiently map out uniquely joined areas (blood vessels in this case). I have 1’s and 2’s along with empty spaces that are 0’s. My current solution for creating a map of where these vessels are is to create an array where
[1 2 0 2
1 2 0 2
1 1 2 2
0 1 0 2] (but in 3D)
would become:
[1 2 0 3
1 2 0 3
1 1 3 3
0 1 0 3]
I use the np.nonzero(arr) to gather the x,y,z coords of all non-zero elements and then I go through and find all the neighboring ones that have the same value, while adding these elements to an array that is np.zeroeslike(arr). While iterating through this array, I would like to be able to remove items from the array created by np.nonzero as I encounter them in my “paint by number” solution (which I use because the software takes the paint by number solution as an input).
Right now, I just check to see if the value in the “visited” array is something other than zero, and if it is, then I just skip over that item. I would like to avoid some of this waiting time, as I’ve noticed that with more dense patient scans, my program takes a significantly longer time to run (2 minutes for a sparse image vs 30 for a dense one).