Clear Filters
Clear Filters

new to image processing and would like some guidance for adding noise to image with sine wave and remove the noise by band reject and notch filter.

12 views (last 30 days)
%Adding sine wave noise to image and then using band reject filter and notch filter to remove it. I’m getting error message. Anybody has idea what needs to be corrected?
%Getting the following error message "error message Error in imageprocessing (line 22) tbr=tf.*br;"
clc;
close all;
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
im = imread('cameraman.tif');
noiseIm = imnoise(im, 'gaussian', 0.1); % adding the sine waves to the noise the image
subplot(2,3,1),
imshow(noiseIm);
en = 127 ;
[x,y] = meshgrid(1:256,1:256 );
s = 1+sin(x+y/1.5 );
grayImage = im;
imshow(grayImage) % use a valid range,
ep = (double(en)/128+s)/4;
% applying bandreject filter to remove noise
z=sqrt((x-129).^2+(y-129).^2);
z(156,170)
z(102,88)
br=(z < 47 | z > 51);
tbr=tf.*br;
subplot(2,3,2),
imshow(tbr);
%applying notch filter to remove noise
tf(156,:)=0;
tf(102,:)=0;
tf(:,170)=0;
tf(:,88)=0;
subplot(2,3,3),
imshow(tf);

Answers (1)

yanqi liu
yanqi liu on 18 Oct 2021
clc; clear all; close all;
C = [0 64;0 128;32 32;64 0;128 0;-32 32];
im = imread('cameraman.tif');
[r,R,S] = imnoise3(size(im,1),size(im,2),C);
im2 = mat2gray(im) + mat2gray(r);
figure;
subplot(1,2,1);imshow(im,[ ]);title('image');
subplot(1,2,2);imshow(mat2gray(im2),[ ]);title('image+sin');
function [r, R, S] = imnoise3(M, N, C, A, B)
% Process input parameters.
[K, n] = size(C);
if nargin == 3
A(1:K) = 1.0;
B(1:K, 1:2) = 0;
elseif nargin == 4
B(1:K, 1:2) = 0;
end
% Generate R.
R = zeros(M, N);
for j = 1:K
u1 = M/2 + 1 + C(j, 1); v1 = N/2 + 1 + C(j, 2);
R(u1, v1) = i * (A(j)/2) * exp(i*2*pi*C(j, 1) * B(j, 1)/M);
% Complex conjugate.
u2 = M/2 + 1 - C(j, 1); v2 = N/2 + 1 - C(j, 2);
R(u2, v2) = -i * (A(j)/2) * exp(i*2*pi*C(j, 2) * B(j, 2)/N);
end
% Compute spectrum and spatial sinusoidal pattern.
S = abs(R);
r = real(ifft2(ifftshift(R)));
r = r(1:M,1:N);
end
  1 Comment
Amad Kadir
Amad Kadir on 18 Oct 2021
Can you guide how I can incorperate the band reject and notch filter to remove the noise?
% applying bandreject filter to remove noise
z=sqrt((x-129).^2+(y-129).^2);
z(156,170)
z(102,88)
br=(z < 47 | z > 51);
tbr=tf.*br;
subplot(2,3,2),
imshow(tbr);
%applying notch filter to remove noise
tf(156,:)=0;
tf(102,:)=0;
tf(:,170)=0;
tf(:,88)=0;
subplot(2,3,3),
imshow(tf);

Sign in to comment.

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!