wki*_*ing 3 matlab type-conversion
我想将真彩色图像转换为双精度,据我所知有两种方法可以做到这一点:
double(rgb_img);im2double(rgb_img);哪一种更有效率?
谢谢!
他们都是不同的。
im2double0-1如果数据类型为uint8或,则转换图像的范围uint16。如果数据类型是singleor logical,则im2double调用double(并且不缩放图像范围)。对于double数据类型,它只是保持不变(精度和图像范围都没有变化)。
如果您已经有双精度图像,则不应调用im2double,它不会重新缩放您的数据。您可以键入edit im2double并查看代码。如果您只想转换为双精度(不更改图像范围),那么您应该调用double. 否则调用im2double但请确保您的数据不是single,double或logical类型。
例子:
img=imread('cameraman.tif'); %datatype is uint8
img1=double(img); %just converts to double precision, image range between 0-255
img2=im2double(img); %converts to double precision and scales image range between 0-1
img=double(imread('cameraman.tif')); %even single datatype will give the same results
img1=double(img); %redundant since image is already double, image range 0-255
img2=im2double(img); %redundant since image is already double, image range 0-255
Run Code Online (Sandbox Code Playgroud)