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)
GNU Lesser General Public License v3.0
356 stars 42 forks source link

What is process? #72

Closed RylanSchaeffer closed 12 months ago

RylanSchaeffer commented 3 years ago

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.

william-silversmith commented 3 years ago

Hi Rylan,

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

william-silversmith commented 2 years ago

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

OPersaud commented 1 year ago

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.

william-silversmith commented 1 year ago

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
OPersaud commented 1 year ago

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.

william-silversmith commented 1 year ago

Good luck with your research, don't hesitate to reach out!

On Sat, Nov 12, 2022, 12:09 PM OPersaud @.***> wrote:

Thank you for the information. 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.

— Reply to this email directly, view it on GitHub https://github.com/seung-lab/connected-components-3d/issues/72#issuecomment-1312529564, or unsubscribe https://github.com/notifications/unsubscribe-auth/AATGQSMVO6FUFUHYZY37IHTWH7FLVANCNFSM5C6P6TLA . You are receiving this because you modified the open/close state.Message ID: @.***>