同态滤波器输出不正确

时间:2019-06-08 14:13:16

标签: matlab image-processing filtering homomorphic-filter

我有一个要运行同态滤镜的TIFF格式图像。

此处不支持TIFF格式, 我上传了 here

我的代码:

clc
clear
%
img= imread('pet.tif');
img = im2double(img);
[p,q] = size(img);
m = 2*p;
n = 2*q;
img2 = log(img);
img3 = zeros(m,n);
img3(1:p,1:q)=img2;
for i=1:m
    for j=1:n
        img3(i,j) = img3(i,j)*((-1)^(i+j));
    end
end


F = fft2(img3);

Landa_H=3;
Landa_L=0.4;
c = 5;
D0=20;
[H_H]=Homomorphic(m,n,D0,Landa_H,Landa_L,c);


Y = ifft2(H_H.*F);


for i=1:m
    for j=1:n
        Y(i,j) = Y(i,j)*((-1)^(i+j));

    end
end
img_filter =exp(Y(1:p,1:q));


%
figure(1);
subplot(2,2,1);
imshow(img);
title('Orginal image');
subplot(2,2,2);
imshow(F);
title('DFT image');
subplot(2,2,3);
imshow(H_H);
title('Homomorphic Filter');
subplot(2,2,4);
imshow(img_filter);
title('Filtered image with Homomorphic');

 figure(2);
 imshow(H_H.*F);

我的同态函数在这里:

  function [ H ] = Homomorphic( m,n,D0,Landa_H,Landa_L,c)
    H = zeros(m,n);
    for i=1:m
        for j=1:n
            x=[m/2,n/2; i,j];
            D=pdist(x,'euclidean');
            H(i,j)=((Landa_H - Landa_L)*(1-(exp(-c*((D^2)/(D0^2))))))+Landa_L;
        end
    end
end

这是我得到的结果:

enter image description here

我不知道我在哪里错了,因为我没有得到正确的答案。谁能给我任何想法?

我不知道如何运行,但没有做任何更改,这就是我得到的错误:

Subscripted assignment dimension mismatch.
Error in Main (line 11)
img3(1:p,1:q)=img2;

0 个答案:

没有答案