在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 5308|回复: 5

用MATLAB实现频域平滑滤波以及图像去噪代码 求解

[复制链接]
发表于 2011-6-21 10:31:03 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
本帖最后由 eecsseudl 于 2013-4-29 09:59 编辑

MATLAB实现频域平滑滤波以及图像去噪代码运行出错(急等)
下面的代码是我在网上搜的,运行以后提示出错,请各位帮忙看看。
% the SF filter is unselective to orientation (doughnut-shaped in the SF
% domain).
[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[X map] = imread(filename, fmt); % read image
L = double(X); % transform to double
%%%%%%%%%%%%% need to add (-1)x+y to L
% calculate the number of points for FFT (power of 2)
fftsize = 2 .^ ceil(log2(size(L)));
% 2d fft
Y = fft2(X, fftsize(1), fftsize (2));
Y = fftshift(Y);
% obtain frequency (cycles/pixel)
f0 = floor([m n] / 2) + 1;
fy = ((m: -1: 1) - f0(1) + 1) / m;
fx = ((1: n) - f0(2)) / n;
[mfx mfy] = meshgrid(fx, fy);
% calculate radius
SF = sqrt(mfx .^ 2 + mfy .^ 2);
% SF-bandpass and orientation-unselective filter
filt = SF > k0;
A_filtered = filt .* A; % SF filtering
L_filtered = real(ifft2(ifftshift(A_filtered))); % IFFT
L_filtered = L_filtered(1: size(L, 1), 1: size(L, 2));
%%%%%%%%%%need to add (-1)x + y to L_filtered
% show
figure(1);
clf reset;
colormap gray;
% plot image
subplot(2, 2, 1);
imagesc(L);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('original image');
xlabel('x');
ylabel('y');
imwrite(L, fullfile(FilePath, 'original image.bmp'), 'bmp') ;
% plot amplitude
A = abs(A);
A = log10(A);
% spectral amplitude
subplot(2, 2, 2);
imagesc(fx, fy, A);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('amplitude spectrum');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(A, fullfile(FilePath, 'amplitude spectrum.bmp'), 'bmp') ;
% filter in the SF domain
subplot(2, 2, 3);
imagesc(fx, fy, filt);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('filter in the SF domain');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(filt, fullfile(FilePath, 'filter in SF.bmp'), 'bmp') ;

% filtered image
subplot(2, 2, 4);
imagesc(L_filtered);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('filtered image');
xlabel('x');
ylabel('y');
imwrite(filtered, fullfile(FilePath, 'filtered image.bmp'), 'bmp');

%%%%%%%%%%%%%%%%%median filter%%%%%%%%%%%%%%%%
[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[LNoise map] = imread(filename, fmt); % read image
L = medfilt2(LNoise, [3 3]); % remove the noise with 3*3 block
figure ;
imshow(LNoise) ;
title('image before fitlering') ;
figure
imshow(L)
title('filtered image') ;
imwrite(FilePath, 'filtered image.bmp', bmp)


提示错误:??? Undefined function or variable 'fmt'.
??? Undefined function or variable "m".








发表于 2011-6-22 19:40:19 | 显示全部楼层
The text string FMT specifies the format of the file by its standard     file extension. For example, specify 'gif' for Graphics Interchange Format files. To see a list of supported formats, with their file  extensions, use the IMFORMATS function. If IMREAD cannot find a file  named FILENAME, it looks for a file named FILENAME.FMT.

FMT,应该使用你图片的格式替换!
 楼主| 发表于 2011-6-23 10:38:36 | 显示全部楼层
我改过了,可是还是不行。。。。。。
发表于 2011-6-27 14:44:50 | 显示全部楼层
把[X map] = imread(filename, FMT);换成[X map] = imread(filename, 'bmp');
并且读入图像找BMP格式的图像
 楼主| 发表于 2011-6-28 17:33:38 | 显示全部楼层
回复 4# renyidian


     [FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[X map] = imread(filename, fmt); % read image
L = double(X); % transform to double
%%%%%%%%%%%%% need to add (-1)x+y to L
% calculate the number of points for FFT (power of 2)
fftsize = 2 .^ ceil(log2(size(L)));
% 2d fft
Y = fft2(X, fftsize(1), fftsize (2));
Y = fftshift(Y);
% obtain frequency (cycles/pixel)
f0 = floor([m n] / 2) + 1;
fy = ((m: -1: 1) - f0(1) + 1) / m;
fx = ((1: n) - f0(2)) / n;
[mfx mfy] = meshgrid(fx, fy);
% calculate radius
SF = sqrt(mfx .^ 2 + mfy .^ 2);
% SF-bandpass and orientation-unselective filter
filt = SF > k0;
A_filtered = filt .* A; % SF filtering
L_filtered = real(ifft2(ifftshift(A_filtered))); % IFFT
L_filtered = L_filtered(1: size(L, 1), 1: size(L, 2));
%%%%%%%%%%need to add (-1)x + y to L_filtered
% show
figure(1);
clf reset;
colormap gray;
% plot image
subplot(2, 2, 1);
imagesc(L);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('original image');
xlabel('x');
ylabel('y');
imwrite(L, fullfile(FilePath, 'original image.bmp'), 'bmp') ;
% plot amplitude
A = abs(A);
A = log10(A);
% spectral amplitude
subplot(2, 2, 2);
imagesc(fx, fy, A);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('amplitude spectrum');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(A, fullfile(FilePath, 'amplitude spectrum.bmp'), 'bmp') ;
% filter in the SF domain
subplot(2, 2, 3);
imagesc(fx, fy, filt);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('filter in the SF domain');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(filt, fullfile(FilePath, 'filter in SF.bmp'), 'bmp') ;
% filtered image
subplot(2, 2, 4);
imagesc(L_filtered);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('filtered image');
xlabel('x');
ylabel('y');
imwrite(filtered, fullfile(FilePath, 'filtered image.bmp'), 'bmp');
%%%%%%%%%%%%%%%%%median filter%%%%%%%%%%%%%%%%
[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[LNoise map] = imread(filename, fmt); % read image
L = medfilt2(LNoise, [3 3]); % remove the noise with 3*3 block
figure ;
imshow(LNoise) ;
title('image before fitlering') ;
figure
imshow(L)
title('filtered image') ;
imwrite(FilePath, 'filtered image.bmp', bmp)
??? Undefined function or variable 'fmt'.

>> [FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[X map] = imread(filename, 'bmp'); % read image
L = double(X); % transform to double
%%%%%%%%%%%%% need to add (-1)x+y to L
% calculate the number of points for FFT (power of 2)
fftsize = 2 .^ ceil(log2(size(L)));
% 2d fft
Y = fft2(X, fftsize(1), fftsize (2));
Y = fftshift(Y);
% obtain frequency (cycles/pixel)
f0 = floor([m n] / 2) + 1;
fy = ((m: -1: 1) - f0(1) + 1) / m;
fx = ((1: n) - f0(2)) / n;
[mfx mfy] = meshgrid(fx, fy);
% calculate radius
SF = sqrt(mfx .^ 2 + mfy .^ 2);
% SF-bandpass and orientation-unselective filter
filt = SF > k0;
A_filtered = filt .* A; % SF filtering
L_filtered = real(ifft2(ifftshift(A_filtered))); % IFFT
L_filtered = L_filtered(1: size(L, 1), 1: size(L, 2));
%%%%%%%%%%need to add (-1)x + y to L_filtered
% show
figure(1);
clf reset;
colormap gray;
% plot image
subplot(2, 2, 1);
imagesc(L);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('original image');
xlabel('x');
ylabel('y');
imwrite(L, fullfile(FilePath, 'original image.bmp'), 'bmp') ;
% plot amplitude
A = abs(A);
A = log10(A);
% spectral amplitude
subplot(2, 2, 2);
imagesc(fx, fy, A);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('amplitude spectrum');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(A, fullfile(FilePath, 'amplitude spectrum.bmp'), 'bmp') ;
% filter in the SF domain
subplot(2, 2, 3);
imagesc(fx, fy, filt);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('filter in the SF domain');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
imwrite(filt, fullfile(FilePath, 'filter in SF.bmp'), 'bmp') ;
% filtered image
subplot(2, 2, 4);
imagesc(L_filtered);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('filtered image');
xlabel('x');
ylabel('y');
imwrite(filtered, fullfile(FilePath, 'filtered image.bmp'), 'bmp');
%%%%%%%%%%%%%%%%%median filter%%%%%%%%%%%%%%%%
[FileName,PathName,FilterIndex] = uigetfile ;
filename = fullfile(PathName, FileName) ;
[LNoise map] = imread(filename, fmt); % read image
L = medfilt2(LNoise, [3 3]); % remove the noise with 3*3 block
figure ;
imshow(LNoise) ;
title('image before fitlering') ;
figure
imshow(L)
title('filtered image') ;
imwrite(FilePath, 'filtered image.bmp', bmp)
??? Undefined function or variable 'm'.
发表于 2011-7-11 22:49:33 | 显示全部楼层
学习,谢谢!!!!!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-12-21 06:21 , Processed in 0.020894 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表