数字图像处理 tofloat函数说明

tofloat解决的问题

​ fft2会导致一定的问题,例如:f = ifft2(F)

​ fft2会将图像变成double类,因此反变换的过程有着一个陷阱:反变换后的图像类型可能和原来输入类型并不相同。

​ 例如:f如果是uint8类型,就是范围在[0,255]内的整数,fft2将其变换成为double类型,通过ifft2将其变换成为了范围为[0,255],但是变成了double类,这会导致一些问题。

​ 冈萨雷斯书籍中,使用tofloat函数解决这一问题,将输入的图像转化为[0,1]内的浮点数,通过revertclass这一参数将反变换中的图像变为和原图像相同的类型。

function [out,revertclass] = tofloat(in)
%   tofloat将输入转换为浮点型,使用fft2将会导致标定的问题。
%   revertclass将输出类型转化为和输入相同的类型
%   如果输入的图像不是single类型,tofloat将会将其转换为single类型
%
%   implement:将所有图像类型以及操作存储起来(cell),通过函数句柄,将
%   非double和single的函数进行转化,将其转化为single类型的函数(im2single)
%
%   revertclass 通过im2xx将其转化为输入的类型
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)));
%   class(in) return the type of the input image, then compare with
%   the first column in the table(cell).

if isempty(classIndex)
    error('Unsupported input image class');
end
%   determine whether to find

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

revertclass = table{classIndex,3};

元胞cell说明

元胞数组是一种包含名为元胞的索引数据容器的数据类型,其中的每个元胞都可以包含任意类型的数据。元胞数组通常包含文本列表、文本和数字的组合或者不同大小的数值数组。通过将索引括在圆括号 () 中可以引用元胞集。使用花括号 {} 进行索引来访问元胞的内容。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值