what is the wrong in this code?

조회 수: 2 (최근 30일)
Ahmed Grera
Ahmed Grera 2017년 9월 5일
댓글: Ahmed Grera 2017년 9월 6일
clc
clear all
close all
lena = imread('eight.tif');
A = fftshift(fft2(lena));
S = imnoise(lena,'Gaussian',0,1);
size(S)
% define spatial filters
h_gauss= fspecial('gaussian', 15, 1.0);
% results after spatial filtering
lena_h_gauss = imfilter(S, h_gauss, 'replicate');
% fourier transformed filters
H_gauss = fftshift(fft2(lena_h_gauss));
size(H_gauss)
% filtering in frequency domain
Lena_H_gauss = S .* H_gauss;
lena_H_gauss = ifft2(ifftshift(Lena_H_gauss));
% print results
subplot(3,3,1); imshow(lena); title('Original Image');
subplot(3,3,2); imshow(lena_h_gauss); title('Gauss-Filtered Image');
subplot(3,3,3); imshow(real(log(Lena)), []); title('FT (Original Image)');
subplot(3,3,4); imshow(real(log(H_gauss)), []); title('FT (Gauss Filter)');
subplot(3,3,5); imshow(lena_H_gauss); title('Result FT Gauss');

채택된 답변

Image Analyst
Image Analyst 2017년 9월 5일
S is complex and imfilter() doesn't work on complex images. You might have to work on the real and imaginary images one at a time.

추가 답변 (1개)

John BG
John BG 2017년 9월 6일
편집: John BG 2017년 9월 6일
Hi Ahmed
1.
it may be that rather than real an imaginary parts, you may consider using the module, with abs
instead of
Lena_H_gauss = S .* H_gauss;
use
lena_H_gauss = S .* uint64(abs(H_gauss));
2.
there are
lena_h_gauss
and
Lena_h_gauss
probably only one should be used
3.
also, instead of
subplot(3,3,1); imshow(lena); title('Original Image');
subplot(3,3,2); imshow(lena_h_gauss); title('Gauss-Filtered Image');
subplot(3,3,3); imshow(real(log(Lena)), []); title('FT (Original Image)');
subplot(3,3,4); imshow(real(log(H_gauss)), []); title('FT (Gauss Filter)');
subplot(3,3,5); imshow(lena_H_gauss); title('Result FT Gauss');
use
subplot(3,3,1); imshow(lena); title('Original Image');
subplot(3,3,2); imshow(lena_h_gauss); title('Gauss-Filtered Image');
subplot(3,3,3); imshow(real(log(double(lena))), []); title('FT (Original Image)');
subplot(3,3,4); imshow(real(log(double(H_gauss))), []); title('FT (Gauss Filter)');
subplot(3,3,5); imshow(lena_H_gauss); title('Result FT Gauss');
.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
  댓글 수: 1
Ahmed Grera
Ahmed Grera 2017년 9월 6일
Hi Jhon
There is still an error going on
lena_H_gauss = S .* uint64(abs(H_gauss));

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by