python中uint8函数_函数“im2uint8”(在MATLAB中)和“bytescale”(在Python中)之间的区别...

我想把DICOM图像从int16转换成uint8。我在Python中使用Z_axis = bytescale(img)完成了这项工作,但这与在MATLAB中使用im2uint8得到的结果不同。在MATLAB中,使用im2uint8转换成uint8后的DICOM图像的最小值和最大值分别为(124,136)。但是在Python中,使用bytescale进行转换后,这些值是(0255)。在

Python代码:for person in range(0, len(dirs1)):

if not os.path.exists(os.path.join(directory, dirs1[person])):

Pathnew = os.path.join(directory, dirs1[person])

os.makedirs(Pathnew)

for root, dirs, files in os.walk(os.path.join(path, dirs1[person])):

dcmfiles = [_ for _ in files if _.endswith('.dcm')]

for dcmfile in dcmfiles:

dcm_image = pydicom.read_file(os.path.join(root, dcmfile))

img = dcm_image.pixel_array

Z_axis = bytescale(img)

minVal = Z_axis.min()

maxVal = Z_axis.max()

Matlab代码:

^{pr2}$

显示时图像看起来是相等的,但数值不是。那么,bytescale和{}函数是否相等?如果不是,我想要像Python中的im2uint8这样的结果。我应该选择什么样的功能(尤其是DICOM图像)?在

例如,在MATLAB中读取DICOM文件后:img = dicomread([galleryPath Files2(j).name]);

img = [ -1024, -1024, 16;

-1024, 8, 11;

17, 5, 8];

但在Python中,阅读后的相同图像是:dcm_image = pydicom.read_file(os.path.join(root, dcmfile))

img = dcm_image.pixel_array

img = array([[ -1024, -1024, 27],

[ -1024, 27, 26],

[ 24, 26, 23]])

我不知道为什么在MATLAB和Python中它们是不同的。在MATLAB中应用im2uint8后,输出为:Z_axis = im2uint8(img)

Z_axis =

3×3 uint8 matrix

124 124 128

124 128 128

128 128 128

在Python中应用bytescale后,输出是:bytescale(img)

Z_axis =

array([[0, 0, 83],

[0, 83, 83],

[83, 83, 83]], dtype=uint8)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值