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

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

 
像素值在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~~~

  • 5
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值