gpt4 book ai didi

image - Matlab im2double 规范化不一致?

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:39 25 4
gpt4 key购买 nike

你能解释一下 matlab im2double 函数的不一致行为吗?
基本上,这个函数作为输入给出了一个 int 矩阵 A,它规范化了 0...1 范围内的值:

例子:

I1 = reshape(uint8(linspace(1,255,9)),[3 3])
I2 = im2double(I1)

I1 =

1 96 192
33 128 223
65 160 255


I2 =

0.0039 0.3765 0.7529
0.1294 0.5020 0.8745
0.2549 0.6275 1.0000

但是现在如果我提供一个double矩阵:

I1 =

0.1000 0.2000
1.5000 2.2000

im2double 的结果是相同的矩阵 I1(因此没有任何归一化)。我能理解这种不一致的行为吗?

最佳答案

输入 help im2double .前几行是

IM2DOUBLE takes an image as input, and returns an image of class double. If the input image is of class double, the output image is identical to it. If the input image is not double, IM2DOUBLE returns the equivalent image of class double, rescaling or offsetting the data as necessary.

所以行为是有意的。的确,当打开im2double.m在编辑器中,您会看到

function d = im2double(img, typestr)
...
if isa(img, 'double')
d = img;
...

end

它是否直观,好吧,这是值得商榷的:)

无论如何,这种行为是有充分理由的。输入类型为 int8你知道天花板是多少(255)。使用该信息,您可以重新缩放输出 ( values/255 )。类似于 int16 ( values/65535 ) 等。

然而,当你得到一个 double ,您不再有现实的上限。对于大多数double值,values/realmax << realmin ,所以重新缩放没有什么意义。

你可以争辩说 255将是一个很好的默认缩放比例,警告说如果 16 位数据是预期的,你应该给出一个额外的参数。但是好吧......这变得丑陋并且使功能不必要地复杂化。我个人可以理解 Mathworks 在此类事件中保留原件的决定。

关于image - Matlab im2double 规范化不一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14442085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com