def __init__(self, series_uid):
        mhd_path = glob.glob(
            "data-unversioned/part2/luna/subset*/{}.mhd".format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        self.hu_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale
        # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0.

        self.series_uid = series_uid

        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_a = np.array(ct_mhd.GetDirection()).reshape(3, 3)

        candidateInfo_list = getCandidateInfoDict()[self.series_uid]

        self.positiveInfo_list = [
            candidate_tup for candidate_tup in candidateInfo_list
            if candidate_tup.isNodule_bool
        ]
        self.positive_mask = self.buildAnnotationMask(self.positiveInfo_list)
        self.positive_indexes = (self.positive_mask.sum(
            axis=(1, 2)).nonzero()[0].tolist())
    def __init__(self, series_uid):
        mhd_path = glob.glob("data-unversioned/part2/luna/subset*/{}.mhd"\
            .format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in
        # https://en.wikipedia.org/wiki/Hounsfield_scale HU are scaled
        # oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc
        # (water) being 0.
        # This gets rid of negative density stuff used to indicate
        # out-of-FOV
        ct_a[ct_a < -1000] = -1000

        # This nukes any weird hotspots and clamps bone down
        ct_a[ct_a > 1000] = 1000

        self.series_uid = series_uid
        self.hu_a = ct_a

        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_tup = tuple(int(round(x)) for x in
                                   ct_mhd.GetDirection())
Example #3
0
    def __init__(self, series_uid):
        mhd_path = glob.glob('data/luna/subset*/{}.mhd'.format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        ct_ary = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale
        # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0.
        # This converts HU to g/cc.
        ct_ary += 1000
        ct_ary /= 1000

        # This gets rid of negative density stuff used to indicate out-of-FOV
        ct_ary[ct_ary < 0] = 0

        # This nukes any weird hotspots and clamps bone down
        ct_ary[ct_ary > 2] = 2

        self.series_uid = series_uid
        self.ary = ct_ary

        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_tup = tuple(
            int(round(x)) for x in ct_mhd.GetDirection())
Example #4
0
    def __init__(self, series_uid, buildMasks_bool=True):
        mhd_path = glob.glob('data-unversioned/part2/luna/subset*/{}.mhd'.format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale
        # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0.
        # This gets rid of negative density stuff used to indicate out-of-FOV
        ct_a[ct_a < -1000] = -1000

        # This nukes any weird hotspots and clamps bone down
        ct_a[ct_a > 1000] = 1000

        self.series_uid = series_uid
        self.hu_a = ct_a

        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_tup = tuple(int(round(x)) for x in ct_mhd.GetDirection())

        noduleInfo_list = getNoduleInfoList()
        self.benignInfo_list = [ni_tup
                                for ni_tup in noduleInfo_list
                                    if not ni_tup.isMalignant_bool
                                        and ni_tup.series_uid == self.series_uid]
        self.benign_mask = self.buildAnnotationMask(self.benignInfo_list)[0]
        self.benign_indexes = sorted(set(self.benign_mask.nonzero()[0]))

        self.malignantInfo_list = [ni_tup
                                   for ni_tup in noduleInfo_list
                                        if ni_tup.isMalignant_bool
                                            and ni_tup.series_uid == self.series_uid]
        self.malignant_mask = self.buildAnnotationMask(self.malignantInfo_list)[0]
        self.malignant_indexes = sorted(set(self.malignant_mask.nonzero()[0]))
    def __init__(self, series_uid, buildMasks_bool=True):
        mhd_path = glob.glob(
            "data-unversioned/part2/luna/subset*/{}.mhd".format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in
        # https://en.wikipedia.org/wiki/Hounsfield_scale HU are scaled
        # oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc
        # (water) being 0.
        # This gets rid of negative density stuff used to indicate
        # out-of-FOV
        ct_a[ct_a < -1000] = -1000

        # This nukes any weird hotspots and clamps bone down
        ct_a[ct_a > 1000] = 1000

        self.series_uid = series_uid
        self.hu_a = ct_a

        # Origin: coordinates of the pixel/voxel with index (0,0,0) in
        # physical units (i.e. mm). Default is zero i.e. origin of
        # physical space.
        # Spacing: distance between adjacent pixels/voxels in each
        # dimension given in physical units. Default is one i.e.
        # (1 mm, 1 mm, 1 mm).
        # Direction Matrix: mapping/rotation between direction of the
        # pixel/voxel axes and physical directions. Default is identity
        # matrix. The matrix is passed as a 1D array in row-major form.
        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_tup = tuple(
            int(round(x)) for x in ct_mhd.GetDirection())

        noduleInfo_list = getNoduleInfoList()
        # List of benign nodules for a specific CT scan
        self.benignInfo_list = [
            ni_tup for ni_tup in noduleInfo_list if not ni_tup.isMalignant_bool
            and ni_tup.series_uid == self.series_uid
        ]
        self.benign_mask = self.buildAnnotationMask(self.benignInfo_list)[0]
        self.benign_indexes = sorted(set(self.benign_mask.nonzero()[0]))

        # List of malignant nodules for a specific CT scan
        self.malignantInfo_list = [
            ni_tup for ni_tup in noduleInfo_list
            if ni_tup.isMalignant_bool and ni_tup.series_uid == self.series_uid
        ]
        self.malignant_mask = self.buildAnnotationMask(
            self.malignantInfo_list)[0]
        self.malignant_indexes = sorted(set(self.malignant_mask.nonzero()[0]))
Example #6
0
	def __init__(self, series_uid):
		mhd_path = glob.glob('/content/drive/MyDrive/LUNA 16/Dataset/{}.mhd'.format(series_uid))[0]
		#sitk.ReadImage implicitly consumes the .raw file in addition to the passed in .mhd file.
		ct_mhd = sitk.ReadImage(mhd_path)
		#Creates a numpy array
		ct_array = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)
		#pixel clipping
		ct_array.clip(-1000, 1000, ct_array)

		self.series_uid = series_uid
		self.hu_array = ct_array

		self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
		self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
		self.direction_a = np.array(ct_mhd.GetDirection()).reshape(3, 3)
Example #7
0
    def __init__(self, series_uid):
        mhd_path = glob.glob(DATA_DIR + 'subset*/{}.mhd'.format(series_uid))[0]

        ct_mhd = sitk.ReadImage(mhd_path)
        ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)

        # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale
        # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0.
        # The lower bound gets rid of negative density stuff used to indicate out-of-FOV
        # The upper bound nukes any weird hotspots and clamps bone down
        ct_a.clip(-1000, 1000, ct_a)

        self.series_uid = series_uid
        self.hu_a = ct_a

        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())
        self.direction_a = np.array(ct_mhd.GetDirection()).reshape(3, 3)
Example #8
0
    def __init__(self, series_uid):
        mhd_path = glob.glob(
            'data-unversioned/part2/luna/subset*/{}.mhd'.format(series_uid)
        )[0]
        
        #加载ct图像,转化为numpy数组
        ct_mhd = sitk.ReadImage(mhd_path)#除了传入的.mhd文件之外,sitk.ReadImage 还会隐式使用.raw文件
        ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)#将读取出来的图像信息用像素值表示出来

        # CTs are natively expressed in https://en.wikipedia.org/wiki/Hounsfield_scale
        # HU are scaled oddly, with 0 g/cc (air, approximately) being -1000 and 1 g/cc (water) being 0.
        # The lower bound gets rid of negative density stuff used to indicate out-of-FOV
        # The upper bound nukes any weird hotspots and clamps bone down
        ct_a.clip(-1000, 1000, ct_a)#将ct_a数组中的元素值限定在(-1000, 1000)

        self.series_uid = series_uid
        self.hu_a = ct_a
        
        #对下面三个参数的详细解释 https://blog.csdn.net/qq_39071739/article/details/106487597?utm_medium=distribute.wap_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.wap_blog_relevant_pic2&depth_1-utm_source=distribute.wap_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.wap_blog_relevant_pic2  
        self.origin_xyz = XyzTuple(*ct_mhd.GetOrigin())#读取图像的原点信息
        self.vxSize_xyz = XyzTuple(*ct_mhd.GetSpacing())#图像各维度上像素之间的物理距离(单位一般为mm)
        self.direction_a = np.array(ct_mhd.GetDirection()).reshape(3, 3)#采用方向余弦矩阵,这里是指图像本身坐标系相对于世界坐标系(固定不动的)的角度余弦