阿里天池-全球数据智能大赛

里面的数据解析

https://tianchi.aliyun.com/forum/issueDetail?spm=5176.12282029.0.0.1549467d4xr1bT&postId=62363

用NotePad++或其他的软件打开seriseuid对应的mhd文件,比如628766,需要去训练集chestCT_round1_train_part2\train_part2找到628766.mdh文件,然后打开,如图一:

图一:

阿里天池-全球数据智能大赛_第1张图片

Offset是原点,coorZ的偏移量为5(也就是5mm,80%是,有些不是),根据原点按5偏移就可以确定是第几张,DimSize中的60为分片数量。

计算属于第几张图方法如下:

图二 : 

阿里天池-全球数据智能大赛_第2张图片

(原点)516.8831-(628766最后一个)321.8831 = 195,195/5=39,所以它属于第39张。

图二蓝框标出的是以coorX =18.414 ,coorY =-15.380,coorZ = -321.883,为中心;daimeterX =7.519 ,daimeterY =8.886 ,daimeterZ =5 ,为长,宽,高的立方体,这个立方图就是我们检测的目标。

还有一个他写的代码

https://tianchi.aliyun.com/forum/postDetail?spm=5176.12282027.0.0.3a46379caoN56B&postId=62774

#coding=utf-8
import numpy as np
import time
import glob
import SimpleITK as sitk
from skimage import morphology, measure, segmentation
import h5py
import pickle
import skimage
import matplotlib.pyplot as plt
import csv
import os
import skimage.io as io
import pandas as pd
import matplotlib.patches as patches


def isflip(self):
    #根据TransformMatrix来判断矩阵图像是否翻转
    with open(self.path) as f:
        contents = f.readlines()
        line = [k for k in contents if k.startswith('TransformMatrix')][0]
        transform = np.array(line.split(' = ')[1].split(' ')).astype('float')
        transform = np.round(transform)
        if np.any(transform != np.array([1, 0, 0, 0, 1, 0, 0, 0, 1])):
            isflip = True
        else:
            isflip = False

        return isflip


def world_To_Voxel_Coord(worldCoord, origin, spacing):
    #世界坐标系转到图像中的坐标
    stretched_Voxel_Coord = np.absolute(worldCoord - origin)
    voxel_Coord = stretched_Voxel_Coord/spacing
    return voxel_Coord


def voxel_To_WorldCoord(voxelCoord, origin, spacing):
    #世界坐标系转到图像中的坐标系
    streched_Vocel_Coord = voxelCoord*spacing
    worldCoord = streched_Vocel_Coord + origin
    return worldCoord


def get_image_spacing_origin(path):
    itk_img = sitk.ReadImage(path)
    image = sitk.GetArrayFromImage(itk_img)
    spacing = np.array(itk_img.GetSpacing())
    origin = np.array(itk_img.GetOrigin())

    return itk_img, image, spacing, origin

if __name__ == "__main__":
    #train_part1
    path = glob.glob("../tianchi_data/raw_data/train_part1/*.mhd")
    id = []
    annotations = np.array(pd.read_csv('../tianchi_data/chestCT_round1_annotation.csv',))
    for p in path:
        print(p)
        id.append(os.path.basename(p).split(".")[0])
        itk_img, image, spacing, origin = get_image_spacing_origin(p)
        name = os.path.basename(p).split(".")[0]

        #从全部annotation中获取到当前annotation的注释
        current_annotation = np.copy(annotations[annotations[:, 0] == int(name)])
        print(current_annotation)
        for c in current_annotation:
            pos = world_To_Voxel_Coord(c[1:4], origin=origin, spacing=spacing)
            diameterX = c[4]/spacing[0]
            diameterY = c[5]/spacing[1]
            # 获取切片对应的索引
            idx = int(np.absolute(c[3] - origin[-1])/spacing[-1])

            ## 显示每一个切片
            fig, ax = plt.subplots()
            # ax.imshow(image[idx], cmap="gray")
            ax.imshow(image[idx])
            cir = patches.Ellipse(xy=(pos[0], pos[1]), width=diameterX,height=diameterY, fill=None)
            ax.add_patch(cir)
            plt.show()
​

我将里面数据的显示改为彩色的了。

找一些来显示一下

阿里天池-全球数据智能大赛_第3张图片

阿里天池-全球数据智能大赛_第4张图片

阿里天池-全球数据智能大赛_第5张图片

阿里天池-全球数据智能大赛_第6张图片

阿里天池-全球数据智能大赛_第7张图片

你可能感兴趣的:(阿里天池-全球数据智能大赛)