Type help im2double
. The first few lines are
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.
So the behavior is intended. Indeed, when opening im2double.m
in the editor, you'll see
function d = im2double(img, typestr)
...
if isa(img, 'double')
d = img;
...
end
Whether it is intuitive, well, that's debatable :)
Anyway, there's a good reason for this behavior. With inputs of type int8
you know what the ceiling is (255
). With that information you can re-scale the output (values/255
). Similar for int16 (values/65535
), etc.
However, when you're given a double
, you don't have a realistic ceiling anymore. For most double
values, values/realmax << realmin
, so there's little sense in re-scaling.
You could argue that 255
would be a good default to scale to, with a warning saying that if 16-bit data is intended, you should give an extra argument or so. But well...that gets ugly and makes the function needlessly complicated. I for one can understand Mathworks' decision to keep the original in such events.