作者sherry470 (sherry)
看板MATLAB
标题[其他] 影像弱化的频域问题
时间Mon Dec 5 02:54:28 2016
最近在学习用MATLAB处理影像
在做影像弱化的时候遇到一些问题想请教大家
我想把一个影像读入後做FFT转换,在频域和degradation function相乘
再把相乘後的影像做反FFT转换,得到一个比较模糊的影像
degration function:
http://i.imgur.com/I8a2LUP.png
以下是我的主程式:
clear
clc
close all
image_rgb = imread('original.png'); % read the image
image_gray = rgb2gray(image_rgb); % transform RGB image into grayscale
fp = motion(image_gray); %degradation
figure,fftshow(fp, 'abs'); % show the image
title('After');
函数motion就是做影像处理的部分:
function fp = motion(f)
% (M,N) -- Size of the image
[M,N] = size(f);
[V,U] = meshgrid(1:N, 1:M);
%trans the (M/2, N/2) to the origin(0,0)
U = U - floor( M/2 );
V = V - floor( N/2 );
c = pi*(0.2*U+0.1*V);
H = (1./c).*sin(c).*exp(-1j*c);
H = fftshift( H );
F = fftshift(fft2(f));
Fp = H.*F;
fp = real(ifft2(Fp));
fp = im2uint8( mat2gray(fp) );
函数fftshow则是参照手边书籍中提供的方式显示DFT转换结果:
function fftshow(f, type)
if nargin<2,
type='log';
end
if (type=='log')
fl = log(1+abs(f));
fm = max(fl(:));
imshow(im2uint8(fl/fm))
elseif (type=='abs')
fa = abs(f);
fm = max(fa(:));
imshow(fa/fm)
else
error('TYPE must be abs or log.');
end;
原图是这样
http://i.imgur.com/Hr4ogpo.png
频域处理相乘後的DFT是这样
http://i.imgur.com/ZYydO35.png
可是经过反FFT转换以後变成一张全黑的图
看起来像是反傅立叶转换时出了问题
试了好久都没办法成功
请问是哪里写的怪怪的吗QQ
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.204.44.70
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1480877670.A.9DA.html
1F:→ kevio: NaN应当指定为1 我信中写错了 12/05 11:44