import numpy as np
# Load the Nifti image
nifti_file = 'your_image.nii.gz'
img = nib.load(nifti_file)
data = img.get_fdata()
# Define a function to remove the bed area from a single 2D slice
def remove_bed_area(slice_data):
# Implement your logic here to remove the bed area
# You might use thresholding, segmentation, or other techniques
# For example, you can threshold the slice to remove dark areas
threshold = 100 # Adjust this threshold as needed
slice_data[slice_data < threshold] = 0
return slice_data
# Process each slice in the 3D image
for slice_idx in range(data.shape[2]):
data[:, :, slice_idx] = remove_bed_area(data[:, :, slice_idx])
# Create a new Nifti image with the modified data
modified_img = nib.Nifti1Image(data, img.affine)
# Save the modified Nifti image to a new file
modified_file = 'modified_image.nii.gz'
nib.save(modified_img, modified_file)
2条答案
按热度按时间djmepvbi1#
试试这个:
goqiplq22#
也许尝试
请注意,这基本上与@BradleyDuncanJunior的答案相同(我的例子中的区域几乎肯定是不正确的,所以我给了他一个赞成票。