seung-lab / connected-components-3d

Connected components on discrete and continuous multilabel 3D & 2D images. Handles 26, 18, and 6 connected variants; periodic boundaries (4, 8, & 6)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What is process?

RylanSchaeffer opened this issue · comments

The README.md file says to call the process function:


# You can extract individual components using numpy operators
# This approach is slow, but makes a mutable copy.
for segid in range(1, N+1):
  extracted_image = labels_out * (labels_out == segid)
  process(extracted_image)

# If a read-only image is ok, this approach is MUCH faster
# if the image has many contiguous regions. A random image 
# can be slower. binary=True yields binary images instead
# of numbered images.
for label, image in cc3d.each(labels_out, binary=False, in_place=True):
  process(image)

What is this process function? I can't find it in default python or in cc3d.

Hi Rylan,

process is just a stand in for anything you'd like to do with the image.

Closing due to inactivity. Please reopen if you need more help!

Can you say more on this please: "process is just a stand in for anything you'd like to do with the image."

I am completely new to your library but I have some experience in Python.

I am trying to create objects from rainfall netCDF files, but I want to begin learning something very basic.

Is there some sample code of something simple which I can follow to learn the library.

I have not been able to find more documentation or examples elsewhere but it is important for me to learn this for my research.

Hi! The first step is you will need to convert netCDF files into numpy arrays. I'm not familiar with netCDF but here's the first google result:

https://towardsdatascience.com/read-netcdf-data-with-python-901f7ff61648

After that you run cc3d to extract the connected components. If you have a 2D image, select connectivity 4 or 8. If you have a 3D image, 6, 18, or 26 connectivity.

import cc3d
import numpy as np
labels = ... # numpy array extracted from netCDF
connectivity = ... # pick a connectivity
cc_labels, N = cc3d.connected_components(labels, connectivity=connectivity, return_N=True)

Then if you want to collect some basic statistics on the image:

stats = cc3d.statistics(cc_labels)

If you want to process individual binary images:

for label, image in cc3d.each(cc_labels, binary=True):
  # whatever you want to do with image

I think a good starting point will be to have this 2D array based on a single timestep from the netCDF file.

I believe after this I can create a 3D array based on multiple timesteps from the netCDF file.

I am trying to identify rainfall as objects so I do not believe the binary classification is the better option.

I am at the beginning of my MSc research so I think I will be in touch as I progress.

Thank you for the information and your time.