PMEAL / porespy

A set of tools for characterizing and analying 3D images of porous materials
https://porespy.org
MIT License
300 stars 98 forks source link

Raising index error when extracting PNM using porespy #325

Closed xu-kai-xu closed 3 years ago

xu-kai-xu commented 3 years ago

Hi, I just start to extract a PNM from CT images (.raw format). During the processing, python raised the error IndexError: too many indices for array. The detailed traceback is

---------------------------------------
Beginning SNOW Algorithm
Converting supplied image (im) to boolean
Peforming Distance Transform
Applying Gaussian blur with sigma = 0.4
Initial number of peaks:  272
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Maximum number of iterations reached, consider running again with a larger value of max_iters
Peaks after trimming saddle points:  118
Peaks after trimming nearby peaks:  118
------------------------------------------------------------
Extracting pore and throat information from image
100%|██████████████████████████████████████████| 123/123 [00:01<00:00, 88.41it/s]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-bb2ef72a9879> in <module>
      2                               voxel_size=1,
      3                               boundary_faces=['top', 'bottom','left', 'right', 'front', 'back'],
----> 4                               marching_cubes_area=False)

E:\program_files\anaconda\lib\site-packages\porespy\networks\__snow__.py in snow(im, voxel_size, boundary_faces, marching_cubes_area)
     77     # -------------------------------------------------------------------------
     78     # Extract void and throat information from image
---> 79     net = regions_to_network(im=regions, dt=dt, voxel_size=voxel_size)
     80     # -------------------------------------------------------------------------
     81     # Extract marching cube surface area and interfacial area of regions

E:\program_files\anaconda\lib\site-packages\porespy\networks\__getnet__.py in regions_to_network(im, dt, voxel_size)
    132     net['throat.equivalent_diameter'] = (np.array(t_area) * (voxel_size**2))**0.5
    133     P12 = net['throat.conns']
--> 134     PT1 = np.sqrt(np.sum(((p_coords[P12[:, 0]]-t_coords) * voxel_size)**2, axis=1))
    135     PT2 = np.sqrt(np.sum(((p_coords[P12[:, 1]]-t_coords) * voxel_size)**2, axis=1))
    136     net['throat.total_length'] = PT1 + PT2

IndexError: too many indices for array
----------------------------------------------- 

The CT images are sort of discrete. image I am not sure what the problem is. Thanks for your help.

jgostick commented 3 years ago

Hmmm, that is a tricky one. It's odd that it all runs fine for several steps before breaking.

Firstly, are you extracting the network of the blue blobs, or the void space around them? A network of the blue blobs won't be of much use since they all totally disconnected....you won't be able to run any simulations on that network. Also, the flatness of the blobs will be a problem for the network abstraction.

Regarding your error above, my hunch is that your image is somehow in the wrong format, and the code handles it sort of by accident. What is the shape of the image you input into snow? Can you run the following:

print(im.shape)
print(im.dtype)
print(im.min(), im.max()
xu-kai-xu commented 3 years ago

@jgostick, thank you, jeff. I want to extract pnm from the blue voxels. Surely they are disconnected. Actually, the blue voxels are more like fractures. But because the poor resolution of the CT, some tiny pores or fractures can not be shown. So, my plan is to extract the major fractures as pores, then add some artificial connectivities to the pores. I also use the classical watershed method to process the images, just found it didn't work. I guess the problem is the poor connectivity. When I change the interest region to the void space, SNOW works well. So I think the file format is right. I use .raw format file, which is output with Avizo. The shape information is as follows:

''' print(im.shape) print(im.dtype) print(im.min(), im.max() (178, 178, 284) uint8 0 1 '''

jgostick commented 3 years ago

Hi @xu-kai-xu ... everthing seems ok, and if your image works on the opposite phase then as you say the format must be ok. Instead of running ps.networks.snow, have you tried running each of the steps separately, as outlined here?

xu-kai-xu commented 3 years ago

thanks, I will try and update the progress.