Reputation: 2674
I am using the imread function in Octave to load an image:
image = imread ("data/images/image1.jpg")(:);
This is apparently loading the image as a matrix of integers with values 0-255.
I want to load it as matrix of doubles with values 0.0-1.0. I can convert it like this.
doubleImage = double(image) / 255.0;
However, converting it is pretty slow, especially for a lot of images. Is there any way to load the image directly as a matrix of doubles?
Upvotes: 0
Views: 2352
Reputation: 13091
No, there is no way to directly read it as doubles. It doesn't make sense anyway, because the image is an integer in the file, so integers will always have to be read first. If a conversion into another type is to be done, it makes sense that it does done separated. Or maybe, use a file format that stores images in double floating point precision.
However, there is a better way to do what you are doing to convert into a double.
pkg load image;
img = imread ("image1.jpg");
img = im2double (img);
Using im2double
won't make it faster (the operation it performs is the same as yours) but it will save you if in the future the image that is read is uint16
, and even if the image already is of class double.
Also, I don't see how the conversion to double is slow. This a really fast operation.
Upvotes: 1