utils.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:aapm_thoracic_challenge 作者: xf4j 项目源码 文件源码
def read_testing_inputs(file, roi, im_size, output_path=None):
    f_h5 = h5py.File(file, 'r')
    if roi == -1:
        images = np.asarray(f_h5['resized_images'], dtype=np.float32)
        read_info = {}
        read_info['shape'] = np.asarray(f_h5['images'], dtype=np.float32).shape
    else:
        images = np.asarray(f_h5['images'], dtype=np.float32)
        output = h5py.File(os.path.join(output_path, 'All_' + os.path.basename(file)), 'r')
        predictions = np.asarray(output['predictions'], dtype=np.float32)
        output.close()
        # Select the roi
        roi_labels = (predictions == roi + 1).astype(np.float32)
        nz = np.nonzero(roi_labels)
        extract = []
        for c in range(3):
            start = np.amin(nz[c])
            end = np.amax(nz[c])
            r = end - start
            extract.append((np.maximum(int(np.rint(start - r * 0.1)), 0),
                            np.minimum(int(np.rint(end + r * 0.1)), images.shape[c])))

        extract_images = images[extract[0][0] : extract[0][1], extract[1][0] : extract[1][1], extract[2][0] : extract[2][1]]
        read_info = {}
        read_info['shape'] = images.shape
        read_info['extract_shape'] = extract_images.shape
        read_info['extract'] = extract

        images = resize(extract_images, im_size, mode='constant')

    f_h5.close()
    return images, read_info
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号