matlab中的 tofloat 函数

在学习matlab过程中,发现没有找到tofloat函数,于是自己在网上找到一个,测试可用:

function [out, revertclass]=tofloat(in)
%tofloat convert image to floating point

identity=@(x) x;
tosingle=@im2single;

table={'uint8', tosingle, @im2uint8
    'uint16', tosingle, @im2uint16
    'int16', tosingle, @im2int16
    'logical', tosingle, @logical
    'double', identity, identity
    'single', identity, identity};
classIndex=find(strcmp(class(in),table(:,1)));
if isempty(classIndex)
error('Unsupported inut image class.')
end

out=table{classIndex,2}(in);
revertclass=table{classIndex,3};

 


版权声明:本文为harry19902002原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。