MRI脑图像处理-归一化:python,自适应归一化

 数据的标准化,归一化方法
数据的标准化(normalization)是将数据按比例缩放,使之落入一个小的特定区间。在某些比较和评价的指标处理中经常会用到,去除数据的单位限制,将其转化为无量纲的纯数值,便于不同单位或量级的指标能够进行比较和加权。

 MRI脑图像处理-归一化:python,自适应归一化_第1张图片
像素值在0-10000之间,通过归一化到 [-1,1] 之间。


import os
import SimpleITK as sitk
def adaptive_normal(image_path, outpath):
    """
    normalize image, rescaled to [-1, 1], without background voxels in statistic analysis
    :param image_path: image path, nii.gz
    :param outpath: .nii.gz, 归一化后的文件保存路径
    :return: 归一化后的 nii.gz 文件绝对路径
    """

    min_p = 0.001 
    max_p = 0.999 # quantile prefer 98~99
    
    image = sitk.ReadImage(image_path)
    image_array = sitk.GetArrayFromImage(image)
    imgArray = np.float32(image_array)

    imgPixel = imgArray[imgArray >= 0]
    imgPixel.sort()
    index = int(round(len(imgPixel) - 1) * min_p + 0.5)
    if index < 0:
        index = 0
    if index > (len(imgPixel) - 1):
        index = len(imgPixel) - 1
    value_min = imgPixel[index]

    index = int(round(len(imgPixel) - 1) * max_p + 0.5)
    if index < 0:
        index = 0
    if index > (len(imgPixel) - 1):
        index = len(imgPixel) - 1
    value_max = imgPixel[index]

    mean = (value_max + value_min) / 2.0
    stddev = (value_max - value_min) / 2.0

    imgArray = (imgArray - mean) / stddev
    imgArray[imgArray < -1] = -1.0
    imgArray[imgArray > 1] = 1.0

    img = sitk.GetImageFromArray(imgArray, isVector=False)
    sitk.WriteImage(img, outpath)
    return os.path.abspath(outpath)


Reference:
https://blog.csdn.net/gefeng1209/article/details/90414604?utm_medium=distribute.pc_relevant.none-task-blog-opensearch-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-opensearch-2.channel_param

https://blog.csdn.net/zwqjoy/article/details/81182102?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-5.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-5.channel_param

https://github.com/Wddzht/DataPreprocessing

https://blog.csdn.net/u013524655/article/details/40918959?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522160005348519725247433072%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=160005348519725247433072&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v3~pc_rank_v2-2-40918959.first_rank_ecpm_v3_pc_rank_v2&utm_term=%E6%9E%81%E5%B7%AE&spm=1018.2118.3001.4187

Game Over~~~

你可能感兴趣的:(python,机器学习,人工智能)