【问题标题】:How can I implement a Homomorphic filter in Matlab? [duplicate]如何在 Matlab 中实现同态滤波器? [复制]
【发布时间】:2017-07-21 23:37:09
【问题描述】:

我已从here 获取源代码并尝试对其进行修改以满足我的需要。但是,过滤器没有按预期工作。我无法在我的代码中找到问题。

我修改后的代码有什么问题?

预期输出

实际输出


源代码

ma​​in.m

clc
close all
clear all
d=10;
order=2;
im=double(imread('tun.png'));
subplot(121)
imshow(im./255);
[r, c]=size(im);
j = homofil(im,d,order);
imshow(j);

homofil.m

function output = homofil(I, d, n)
    I = double(I);

    H = butter_hp_kernel(I, d, n); 

    alphaL = .0999;
    aplhaH = 1.01;
    H = ((aplhaH-alphaL).*H)+alphaL;
    H = 1-H;

    im_l = log2(1+I);
    im_f = fft2(im_l);
    im_nf = H.*im_f;
    im_n = abs(ifft2(im_nf));
    output = exp(im_n);

butter_hp_kernel.m

function k = butter_hp_kernel(I, Dh, n) 
    Height = size(I,1); 
    Width = size(I,2); 

    [u, v] = meshgrid( ...
                    -floor(Width/2) :floor(Width-1)/2, ...
                    -floor(Height/2): floor(Height-1)/2 ...
                 ); 

    k = butter_hp_f(u, v, Dh, n);

function f = butter_hp_f(u, v, Dh, n)
    uv = u.^2+v.^2;
    Duv = sqrt(uv);
    frac = Dh./Duv;
    %denom = frac.^(2*n);
    A=0.414; denom = A.*(frac.^(2*n));    
    f = 1./(1.+denom);

输入图像

【问题讨论】:

  • 标记为良好的副本。它使用同态过滤来分割车牌字符。

标签: image matlab image-processing homomorphic-filter


【解决方案1】:

我有更详细的解释,stackoverflow 进入维护,我无法发布。所以这里是单行解释。

您的 j 范围错误:[1, 1.08] 所以它显示为白色。
执行imshow(j, []) 或将j 转换为mat2gray

【讨论】:

  • 我在这两件事上面临着持续的麻烦:(1)double uint8,(2)imshow(I, [])。我只是不明白什么时候需要。例如,巴特沃斯过滤器要求我将双精度转换为 uint8,但有些图像没有显示出来。现在,我被这个困住了。
  • uint8 图像采用 uint8 类型的值从 0 到 255。双精度图像采用双精度类型的值从 0 到 1。要将 uint8 图像正确转换为正确范围内的双精度图像,请使用 @987654326 @.
  • imshow 中的[] 仅使用矩阵的最小和最大范围作为黑白(即它缩放对比度以匹配该范围)。如果不给出范围,那么 imshow 会依赖类型(uint8 / double)来显示合适的范围。
  • 是的,我知道。但是,问题是,我不明白什么时候需要。
  • 我会尽可能使用双精度。如果一个函数明确要求 uint8 转换为那个,但在划分时要小心,因为你可能会得到四舍五入。但是,总的来说,只要您处理您期望图像的范围,通常两种形式都可以。
猜你喜欢
  • 1970-01-01
  • 2017-12-22
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 2017-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多