【博文精选】基于FPGA的图像FFT滤波处理
1关于傅里叶变换
2基于Matlab的FFT滤波
我们重新把原图放到这里,和FFT滤波并IFFT以后的图像做比对,图像整体仍然保持不变,但是查看细节,可以发现处理后的图像明显锐了一些。
Matlab源码如下:
clc;clear `all;close all;
IMAGE_WIDTH = 640;
IMAGE_HIGHT = 480;
%load origin image
%I = imread('Lena_gray_niose.bmp');
I = imread('test.bmp');
I = rgb2gray(I);
%fclose(fid1);
%% output image data in hex file
raw_image = reshape(I, IMAGE_HIGHT, IMAGE_WIDTH);
raw_image = raw_image';
fid2 = fopen('image_in_hex.txt', 'wt');
fprintf(fid2, '%04x\n', raw_image);
fid2 = fclose(fid2);
%show origin image
figure,imshow(I);
title('Original image');
%1D fft base on every image line
II = zeros(IMAGE_HIGHT,1024);
J = zeros(IMAGE_HIGHT,1024);
for i = 1:IMAGE_HIGHT
for j = 1:IMAGE_WIDTH
II(i,j) = I(i,j);
end
J(i,:) = fft(II(i,:));%fft(I(i,:));
end
%show 1 linefft result
t1 = (0:IMAGE_WIDTH); % Time vector
line = ones(IMAGE_WIDTH) * 200;
figure;
plot(t1(1:IMAGE_WIDTH),abs(J(50,1:IMAGE_WIDTH)),t1(1:IMAGE_WIDTH),line(1:IMAGE_WIDTH))
title(['1 line image in the Frequency Domain'])
%show fft of origin image
figure,imshow(log(abs(J)),[]);
title('1D fft image base on every image line');
%colormap(jet(64)),colorbar;
%fftfiter
J(abs(J) < 300) = 0;
%J(abs(J) > 1000) = 1000;
%show fft of fft filter image
figure,imshow(log(abs(J)),[]);
title('1D fft image after filter');
%1D ifft base on every image line
K = zeros(IMAGE_HIGHT,1024);
for i = 1:IMAGE_HIGHT
K(i,:) = real(ifft(J(i,:)));
end
KK = zeros(IMAGE_HIGHT,IMAGE_WIDTH);
for i = 1:IMAGE_HIGHT
for j = 1:IMAGE_WIDTH
KK(i,j) = K(i,j);
end
end
%show ifft image
figure,imshow(KK,[])
title('1D ifft image');
3FPGA仿真
4 基于FPGA的图像平滑处理
always @(posedgeclk or negedgerst_n)
if(!rst_n) begin
o_image_filter_data_image<= 20'd0;
o_image_filter_data_real<= 20'd0;
end
/*else if(sqrt_fft[19:0] < 20'd300) begin //此处可以做必要的高频或低频滤波处理
o_image_filter_data_image<= 20'd0;
o_image_filter_data_real<= 20'd0;
end*/
else begin
o_image_filter_data_image<= r_image_fft_data_image[TOTAL_LATENCY-1];
o_image_filter_data_real<= r_image_fft_data_real[TOTAL_LATENCY-1];
end
image_ifft_controller.v模块将滤波处理后的FFT结果进行IFFT变换,图像转回时域值,供后续模块缓存DDR3并显示。
AT7_Xilinx开发板(USB3.0+LVDS)资料共享
腾讯链接:https://share.weiyun.com/5GQyKKc
百度网盘链接:https://pan.baidu.com/s/1M7PLzRs-yMJv7NFJE8GVAw 提取码:qr0t