我有一个形状为(512,512,299)的Nifti图像(未标记),我想对这个3D图像执行无监督分割。然而,图像包含床区,这是我的集群制造麻烦。我尝试过聚类,结果是一个形状为**(512,512)**的聚类图像
djmepvbi1#
试试这个:
import numpy as np# Load the Nifti imagenifti_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 slicedef 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 imagefor slice_idx in range(data.shape[2]): data[:, :, slice_idx] = remove_bed_area(data[:, :, slice_idx])# Create a new Nifti image with the modified datamodified_img = nib.Nifti1Image(data, img.affine)# Save the modified Nifti image to a new filemodified_file = 'modified_image.nii.gz'nib.save(modified_img, modified_file)
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)
goqiplq22#
也许尝试
import nibabel as nib;img = nib.load ( "withbed.nii.gz" );data = img.get_fdata();removed_bed_area = data [ :200, 4:111, : ];removed_bed_img = nib.Nifti1Image( removed_bed_area, img.affine );nib.save( removed_bed_img, "removed_bed.nii.gz" );
import nibabel as nib;
img = nib.load ( "withbed.nii.gz" );
data = img.get_fdata();
removed_bed_area = data [ :200, 4:111, : ];
removed_bed_img = nib.Nifti1Image( removed_bed_area, img.affine );
nib.save( removed_bed_img, "removed_bed.nii.gz" );
请注意,这基本上与@BradleyDuncanJunior的答案相同(我的例子中的区域几乎肯定是不正确的,所以我给了他一个赞成票。
2条答案
按热度按时间djmepvbi1#
试试这个:
goqiplq22#
也许尝试
请注意,这基本上与@BradleyDuncanJunior的答案相同(我的例子中的区域几乎肯定是不正确的,所以我给了他一个赞成票。