为什么我们在matlab中对图像进行数值运算之前将灰度级转换为double?

Why we convert gray levels into double before using numeric operations on image in matlab?

为什么在matlab中对图像进行数值运算前要先将灰度转为double? 有必要这样做吗?

因为像uint8这样的整数类型在MATLAB中有saturated arithmetic,再加上浮点数类型在做某些运算时精度更高。

此外,将 uint8 向上转换为 double 比向另一个方向向下转换更安全。


举个例子,假设您想通过将图像提高到 2 的幂来更改图像的动态范围:

img = imread('peppers.png');
subplot(121), imshow(im2double(img).^2), title('double')
subplot(122), imshow(img.^2), title('uint8')

您可以看到 uint8 图像如何在 255 时饱和了大多数值。

更重要的是,使用分数指数会引发整数类型的错误:

>> img.^(1.1);
Error using  .^ 
Integers can only be raised to positive integral powers.