Giter VIP home page Giter VIP logo

Comments (11)

william-silversmith avatar william-silversmith commented on June 18, 2024

from connected-components-3d.

sneh-debug avatar sneh-debug commented on June 18, 2024

hello @william-silversmith ,i want to apply cc3d on segmentation result image containing multiple class and the dimensions of result image is 128128128

from connected-components-3d.

william-silversmith avatar william-silversmith commented on June 18, 2024

Here's what I suspect you want to do:

# Let multichannel be the segmentation image.

output = np.zeros(multichannel.shape, dtype=np.uint32)
for i in range(multichannel.shape[3]):
   output[:,:,:,i] = cc3d.connected_components(multichannel[:,:,:,i])

If instead by multichannel, you don't mean mean a 4D image and instead mean simply an image with multiple label types (i.e. label 1 might be adjacent to label 2), just use cc3d normally, that's what it was designed for.

from connected-components-3d.

sneh-debug avatar sneh-debug commented on June 18, 2024

Here's what I suspect you want to do:

# Let multichannel be the segmentation image.

output = np.zeros(multichannel.shape, dtype=np.uint32)
for i in range(multichannel.shape[3]):
   output[:,:,:,i] = cc3d.connected_components(multichannel[:,:,:,i])

If instead by multichannel, you don't mean mean a 4D image and instead mean simply an image with multiple label types (i.e. label 1 might be adjacent to label 2), just use cc3d normally, that's what it was designed for.

Thanks
Capture
this is 3d image showing all 3 axis, i want to apply cc3d on it. How will i pass the image to it? i have to convert it into array?

from connected-components-3d.

sneh-debug avatar sneh-debug commented on June 18, 2024

@william-silversmith

output_dir='./'
PNii  = nibabel.load('./prediction/BraTS20_Training_368/prediction.nii.gz')
P  = PNii.get_fdata()
print(P.shape)
#multichannel='./prediction/BraTS20_Training_368/prediction.nii.gz'
output = np.zeros(P.shape, dtype=np.uint32)
for i in range(P.shape[2]):
   output[:,:,i] = cc3d.connected_components(output[:,:,i])
print(output.shape)
output=sitk.GetImageFromArray(output)
  #get the save path
sitk.WriteImage(output,output_dir + 'new.nii.gz') 

This is my code for apply cc3d and saving it into 3d image with .nii.gz format but the output image is blank image? Please tell me what mistake i am doing here.
Thanks

from connected-components-3d.

william-silversmith avatar william-silversmith commented on June 18, 2024

Hi sneh, it looks like you are passing a blank output to cc3d. However, the way you're doing it you'll run connected components on each 2D slice, which may not be what you want. The following will probably produce 3D connected components if P is a numpy array.

output_dir='./'
PNii  = nibabel.load('./prediction/BraTS20_Training_368/prediction.nii.gz')
P  = PNii.get_fdata() 
output = cc3d.connected_components(P)
output=sitk.GetImageFromArray(output)
sitk.WriteImage(output,output_dir + 'new.nii.gz') 

from connected-components-3d.

sneh-debug avatar sneh-debug commented on June 18, 2024

Hi sneh, it looks like you are passing a blank output to cc3d. However, the way you're doing it you'll run connected components on each 2D slice, which may not be what you want. The following will probably produce 3D connected components if P is a numpy array.

output_dir='./'
PNii  = nibabel.load('./prediction/BraTS20_Training_368/prediction.nii.gz')
P  = PNii.get_fdata() 
output = cc3d.connected_components(P)
output=sitk.GetImageFromArray(output)
sitk.WriteImage(output,output_dir + 'new.nii.gz') 

then it gives following error:
TypeError: Type float64 not currently supported.

from connected-components-3d.

william-silversmith avatar william-silversmith commented on June 18, 2024

If your data is floating point, it's not supported. You'll have to find a way to convert it to integer labels. This could be as easy as P.astype(np.uint64).

from connected-components-3d.

sneh-debug avatar sneh-debug commented on June 18, 2024

@william-silversmith it worked . thank you. can we increase the intensity value? The image obtained from cc3d is not clear, very difficult to visualize.

from connected-components-3d.

william-silversmith avatar william-silversmith commented on June 18, 2024

I'm glad it worked! To visualize more easily, try casting the output to a float before passing it to save_images. That functions re-normalizes floats to be more visible.

from connected-components-3d.

william-silversmith avatar william-silversmith commented on June 18, 2024

Closing this question due to inactivity. Please reopen if you still need help!

from connected-components-3d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.