作者kevio (成仔)
标题Re: [其他] 影像弱化的频域问题
时间Mon Dec 5 11:34:55 2016
我改了一下code 如下
用你的档案 Hr4ogpo.png
重点应该是
1. 没用 ifftshift -->造成fft2/ifft2转换错误
2. H中有NaN数值,这个我就没帮你算了 直接指定为1
至於fftshow子函数应该不需要吧,你程式中已经做转换了
另外 我不知道H需不需要做fftshift @@~ 我总觉得不应该做
以上
------------------------------------------------------------
clear
clc
close all
image_rgb = imread('Hr4ogpo.png'); % read the image
image_gray = rgb2gray(image_rgb); % transform RGB image into grayscale
%imshow (image_gray);
%fp = motion(image_gray); %degradation
f=image_gray;
imshow(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(-i*c);
H = fftshift( H ); %这边请你自己决定要不要这行
H(isnan(H)) = 1; % NaN数值造成转换错误
F = fftshift(fft2(f));
Fp = H.*F;
fp = real(ifft2(ifftshift(Fp)));
fp = im2uint8( mat2gray(fp) );
figure
imshow(fp); % 转换後
※ 引述《sherry470 (sherry)》之铭言:
: 最近在学习用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), 来自: 140.116.253.173
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1480908897.A.278.html
※ 编辑: kevio (140.116.253.173), 12/05/2016 11:42:45
1F:→ kevio: c=0.001时 H=1 , 所以NaN应当指定为1 12/05 11:43