-
Notifications
You must be signed in to change notification settings - Fork 201
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
There was a problem merging two.NIIs into one #2076
Comments
BY the way, why don't the same sequences match up? ` for i in range(20):
|
SimpleITK 2.3.1 |
Hello @tanjia123456, It is very hard to follow your code (long and not straightforward), please provide a minimal working example illustrating the problem you are having combining what looks to be two binary segmentation images. Below are two options for combining two binary segmentations, depending on your needs.
Finally, for questions, please post on the ITK discourse. The issue tracker is primarily intended for bug reports. |
thanks for your code, it's work! |
Hi, @zivy import nibabel as nib def crop_save(nii_file):
for i in range(1,10): |
Hello @tanjia123456, You are mixing and matching nibabel and SimpleITK for operations that likely exist in both toolkits. Highly recommend that you use one toolkit and familiarize yourself with all its functionality. For SimpleITK, possibly skim the SimpleITK notebooks or go over the SimpleITK tutorial. With respect to automated cropping, the following code will do it when added to the code above:
|
Hello, I have a dicom sequence, use 3D slicer to load the dicom folder, and then mark labels on it using segmentation, but now I have two mask1 and mask2, how do I merge them into one? Am I using the following code correctly?
`
import numpy as np
import os
import SimpleITK as sitk
import random
from scipy import ndimage
from os.path import join
Rseg = sitk.ReadImage("R-mark-label.nii", sitk.sitkInt8)
Rseg_array = sitk.GetArrayFromImage(Rseg)
Lseg = sitk.ReadImage("L-mark-label.nii", sitk.sitkInt8)
Lseg_array = sitk.GetArrayFromImage(Lseg)
print(" Rseg = ", Rseg_array.shape, "Lseg = ", Lseg_array.shape)
unique_elements = np.unique(Rseg_array, return_counts=False)
print("Rseg 类别数=", unique_elements, "Rseg=0:", np.sum(Rseg_array == 0), "Rseg=1:", np.sum(Rseg_array == 1), "Rseg=2:",np.sum(Rseg_array == 2))
unique_elements = np.unique(Lseg_array, return_counts=False)
print("Lseg 类别数=", unique_elements, "Lseg=0:", np.sum(Lseg_array == 0), "Rseg=1:", np.sum(Lseg_array == 1), "Rseg=2:",np.sum(Lseg_array == 2))
merge_seg = np.add(Rseg_array, Lseg_array)
unique_elements = np.unique(merge_seg, return_counts=False)
print("merge_seg 类别数=", unique_elements, "merge_seg=0:", np.sum(merge_seg == 0), "merge_seg=1:", np.sum(merge_seg == 1), "merge_seg=2:",np.sum(merge_seg == 2))
out = sitk.GetImageFromArray(merge_seg)
sitk.WriteImage(out, 'seg-12.nii')
`
The text was updated successfully, but these errors were encountered: