Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using cc3d with multiple channels? #57

Closed
sneh-debug opened this issue Nov 9, 2020 · 11 comments
Closed

Using cc3d with multiple channels? #57

sneh-debug opened this issue Nov 9, 2020 · 11 comments
Labels
question Further information is requested

Comments

@sneh-debug
Copy link

hello,
I am using 3D images ,so for that how can i apply connected component library?

@william-silversmith
Copy link
Contributor

william-silversmith commented Nov 9, 2020 via email

@william-silversmith william-silversmith added the question Further information is requested label Nov 9, 2020
@william-silversmith william-silversmith changed the title can it be use for multiple channels? Using cc3d with multiple channels? Nov 9, 2020
@sneh-debug
Copy link
Author

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

@william-silversmith
Copy link
Contributor

william-silversmith commented Nov 11, 2020

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.

@sneh-debug
Copy link
Author

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?

@sneh-debug
Copy link
Author

sneh-debug commented Nov 11, 2020

@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

@william-silversmith
Copy link
Contributor

william-silversmith commented Nov 11, 2020

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') 

@sneh-debug
Copy link
Author

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.

@william-silversmith
Copy link
Contributor

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).

@sneh-debug
Copy link
Author

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

@william-silversmith
Copy link
Contributor

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.

@william-silversmith
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants