Removing moire pattern from an image

81 views (last 30 days)
Johann Castro
Johann Castro on 4 May 2019
Commented: Walter Roberson on 23 Jul 2021
Hi Guys,
I trying to remove The moiré pattern from an image using filters in frequency domain, specifically, NOTCH REJECT HIGH PASS FILTER,
But when I try to plot the filtered image, a black image appears,
Here is the code that i use to do that, Someone can help me please??
clc;clear all;
I=imread('img2.PNG');
I=im2double(I);
I=rgb2gray(I);
h=size(I,1);%ALTO (Y)
w=size(I,2);%ANCHO (X)
P=2*h;
Q=2*w;
I1=fft2(I,P,Q);% FFT NÃO CENTRALIZADA
Ia=abs(I1);
I2=fftshift(I1);%FFT CENTRALIZADA
I3=log(1+abs(I2));
f_max=max(I3(:));
I4=I3/f_max;%SPECTRUM IN FREQUENCY DOMAIN OF THE ORIGINAL IMAGE
[x,y]=meshgrid(-floor(Q/2):floor(Q-1)/2, -floor(P/2):floor(P-1)/2);
Do=15;n=5;fc=30; %
a1=x-110/2; b1=y-145/2;
a2=x-110/2; b2=y+145/2;
a3=x+110/2; b3=y+145/2;
a4=x+110/2; b4=y-145/2;
D1=sqrt(a1.^2+b1.^2);
D2=sqrt(a2.^2+b2.^2);
D3=sqrt(a3.^2+b3.^2
D4=sqrt(a4.^2+b4.^2);
B1=1./(1.+(Do.*(D1.^(-1))).^(2*n));
B2=1./(1.+(Do./D2).^(2*n));
B3=1./(1.+(Do./D3).^(2*n));
B4=1./(1.+(Do./D4).^(2*n));
I5=I4.*B1.*B2.*B3.*B4;
I6=abs(ifft2(I5));
I7=abs(I6);maxi=max(I6(:));
I8=im2uint8(I6/maxi);
%=========================================================================%
%=============================PLOT========================================%
%=========================================================================%
figure
subplot(1,2,1),imhist(I),title('Histograma Img. Original')
subplot(1,2,2),imhist(histeq(I)),title('Histograma Equalizado')
figure
subplot(2,3,1),imshow(I),title('Imagem Original')
subplot(2,3,2),imshow(I1),title('FFT nao centralizada')
subplot(2,3,3),imshow(I2),title('FFT centralizada')
subplot(2,3,4),imshow(I4),title('Spectrum')
subplot(2,3,5),imshow(I5),title('Notch Reject')
subplot(2,3,6),imshow(I8),title('Imagem filtrada')

Answers (1)

Walter Roberson
Walter Roberson on 23 Jul 2021
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/210517/MatlabThing.png';
I = imread(filename);
I=im2double(I);
I=rgb2gray(I);
h=size(I,1);%ALTO (Y)
w=size(I,2);%ANCHO (X)
P=2*h;
Q=2*w;
I1=fft2(I,P,Q);% FFT NÃO CENTRALIZADA
I2=fftshift(I1);%FFT CENTRALIZADA
I3=log(1+abs(I2));
f_max=max(I3(:));
I4=I3/f_max;%SPECTRUM IN FREQUENCY DOMAIN OF THE ORIGINAL IMAGE
[x,y]=meshgrid(-floor(Q/2):floor(Q-1)/2, -floor(P/2):floor(P-1)/2);
Do=15;n=5;fc=30; %
a1=x-110/2; b1=y-145/2;
a2=x-110/2; b2=y+145/2;
a3=x+110/2; b3=y+145/2;
a4=x+110/2; b4=y-145/2;
D1=sqrt(a1.^2+b1.^2);
D2=sqrt(a2.^2+b2.^2);
D3=sqrt(a3.^2+b3.^2);
D4=sqrt(a4.^2+b4.^2);
B1=1./(1.+(Do.*(D1.^(-1))).^(2*n));
B2=1./(1.+(Do./D2).^(2*n));
B3=1./(1.+(Do./D3).^(2*n));
B4=1./(1.+(Do./D4).^(2*n));
I5=I4.*B1.*B2.*B3.*B4;
I6=abs(ifft2(I5));
maxi=max(I6(:));
[min(I6(:)), max(I6(:)), min(maxi), max(maxi)]
ans = 1×4
0.0000 0.2581 0.2581 0.2581
I8=im2uint8(I6/maxi);
whos I8; min(I8(:)), max(I8(:)), nnz(I8)
Name Size Bytes Class Attributes I8 948x652 618096 uint8
ans = uint8 0
ans = uint8 255
ans = 920
%=========================================================================%
%=============================PLOT========================================%
%=========================================================================%
figure
subplot(1,2,1),imhist(I),title('Histograma Img. Original')
subplot(1,2,2),imhist(histeq(I)),title('Histograma Equalizado')
figure
subplot(2,3,1),imshow(I),title('Imagem Original')
subplot(2,3,2),imshow(real(I1)),title('FFT nao centralizada')
subplot(2,3,3),imshow(real(I2)),title('FFT centralizada')
subplot(2,3,4),imshow(I4),title('Spectrum')
subplot(2,3,5),imshow(I5),title('Notch Reject')
subplot(2,3,6),imshow(I8),title('Imagem filtrada')
figure;
imshow(~I8)
This tells us that after the filtering, the only places that are non-zero are some near the corner, and difficult to see.
Notice that you did not fftshift() back after the notch filter.

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!