• 大小: 1.71MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-04
  • 语言: Python
  • 标签: python  肺结节  分割  

资源简介

这是一个python的肺结节分割代码,是我最近修改过的代码,希望给初学者提供参考,为大家提供思路。欢迎大家下载参考。希望可以给大家帮助

资源截图

代码片段和文件信息

#-*-coding:utf-8-*-

import numpy as np
import os
import math


def padding_patch(nodule_arr label_arr cube_size_xy=64 cube_size_z=32):
    nodule_64_arr = np.ones((cube_size_z cube_size_xy cube_size_xy) dtype=np.float32)
    nodule_64_arr *= -1000.0
    label_64_arr = np.zeros((cube_size_z cube_size_xy cube_size_xy) dtype=np.float32)
    #nodule_arr = normalization(nodule_arr)

    origin_shape = nodule_arr.shape
    padding_z = (cube_size_z - origin_shape[0])/2
    padding_y = (cube_size_xy - origin_shape[1])/2
    padding_x = (cube_size_xy - origin_shape[2])/2

    edge_z_min = math.floor(padding_z)
    edge_z_max = edge_z_min + origin_shape[0]
    edge_y_min = math.floor(padding_y)
    edge_y_max = edge_y_min + origin_shape[1]
    edge_x_min = math.floor(padding_x)
    edge_x_max = edge_x_min + origin_shape[2]
    print([edge_z_min edge_z_max edge_y_min edge_y_max edge_x_min edge_x_max])

    nodule_64_arr[edge_z_min:edge_z_max edge_y_min:edge_y_max edge_x_min:edge_x_max] = nodule_arr
    label_64_arr[edge_z_min:edge_z_max edge_y_min:edge_y_max edge_x_min:edge_x_max] = label_arr

    return nodule_64_arr label_64_arr


def normalization(nodule_arr max_val = 600.0 min_val = -1000.0):
    nodule_arr = nodule_arr.astype(“float32“)
    nodule_arr = (nodule_arr - min_val) / (max_val - min_val)
    nodule_arr = np.clip(nodule_arr 0 1)

    return nodule_arr


if __name__ == ‘__main__‘:
    lidc_path = “E:/LIDC-IDRI/“
    origin_path = os.path.join(lidc_path “four_radiologist_samples/“)
    padding_path = os.path.join(lidc_path “lidc_padding_samples/“)
    origin_sample_path = os.path.join(origin_path “sample/“)
    origin_label_path = os.path.join(origin_path “label/“)
    padding_sample_path = os.path.join(padding_path “sample/“)
    padding_label_path = os.path.join(padding_path “label/“)

    nodule_list = os.listdir(origin_sample_path)
    for nodule_file in nodule_list:
        lidc_id = nodule_file.split(“_“)[0]
        nodule_id = nodule_file.split(“_“)[2]
        label_file = lidc_id + “_label_“ + nodule_id
        nodule_arr = np.load(os.path.join(origin_sample_path nodule_file))
        label_arr = np.load(os.path.join(origin_label_path label_file))
        label_arr = label_arr.astype(“float32“)
        if nodule_arr.shape[0] <=32 and max(nodule_arr.shape[1] nodule_arr.shape[2]) <= 64:
            nodule_64_arr label_64_arr = padding_patch(nodule_arr label_arr)
            assert nodule_64_arr.shape == label_64_arr.shape
            #print(nodule_64_arr.shape)
            np.save(os.path.join(padding_sample_path nodule_file) nodule_64_arr)
            np.save(os.path.join(padding_label_path label_file) label_64_arr)


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\
     文件          31  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\README.md
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\__pycache__\
     文件        1872  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\__pycache__\data_padding.cpython-36.pyc
     文件        7843  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\__pycache__\data_process.cpython-36.pyc
     文件         729  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\__pycache__\find_scans.cpython-36.pyc
     文件        1068  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\__pycache__\plot_nodule.cpython-36.pyc
     文件        2776  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\data_padding.py
     文件       11702  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\data_process.py
     文件         958  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\find_max_size.py
     文件         873  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\find_scans.py
     文件         954  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\padding_test.py
     文件        1160  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\plot_nodule.py
     文件        1440  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\result_process.py
     文件        1020  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\sample_3d_lidc.py
     文件        1027  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\dataset\seg_train_val.py
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\
     文件      524368  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\LIDC-IDRI-0001_label_0.npy
     文件      524368  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\LIDC-IDRI-0001_sample_0.npy
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\__pycache__\
     文件       10203  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\__pycache__\model.cpython-36.pyc
     文件        1148  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\__pycache__\utils.cpython-36.pyc
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\
     目录           0  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\
     文件         247  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\checkpoint
     文件        3063  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\unet3d-2380.index
     文件     2257298  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\unet3d-2380.meta
     文件        3063  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\unet3d-2385.index
     文件     2257298  2018-03-27 02:48  LIDC-IDRI-nodule-segmentation-master\model\checkpoint\unet3d_layer3_cross_entropy\filter_size_333_epoch_5_v1\unet3d-2385.meta
............此处省略32个文件信息

评论

共有 条评论