how can i have image c and d ?
5 views (last 30 days)
Show older comments
i try this but it doesnt result exact images
figure; imshow(log(1+S),[]); title('Spectrum');
% Define the center of the notch reject filter
[M, N] = size(I);
cx = M/2; cy = N/2;
% Define the radius and width of the notch reject filter
r = 30; % radius
w = 10; % width
% Compute the Butterworth notch reject filter
n = 4; % order
B = zeros(M,N);
for i = 1:M
for j = 1:N
d = sqrt((i-cx)^2 + (j-cy)^2);
if d >= r-w/2 && d <= r+w/2
B(i,j) = 1 / (1 + (d/r)^(2*n));
else
B(i,j) = 1;
end
end
end
% Apply the notch reject filter to the Fourier transform of the image
F_filtered = F_shifted .* B;
S_filtered = abs(F_filtered);
figure; imshow(log(1+S_filtered),[]); title('Filtered Spectrum');
% Compute the inverse Fourier transform of the filtered image
I_filtered = real(ifft2(ifftshift(F_filtered)));
figure; imshow(I_filtered,[]); title('Filtered Image')

1 Comment
Image Analyst
on 16 May 2023
If you have any more questions, then attach your data (the "S" variable) and code to read it in with the paperclip icon after you read this:
Answers (1)
Abhishek
on 26 Jun 2025
It appears you are attempting to implement selective filtering using a Butterworth notch filter but are obtaining incorrect results.
The issue lies in the code for the filter which does not implement a notch filter. This can be confirmed by plotting the filter in image form.
I = imread('moire.png');
% Define the center of the notch reject filter
[M, N] = size(I);
cx = M/2; cy = N/2;
% Define the radius and width of the notch reject filter
r = 30; % radius
w = 10; % width
% Compute the Butterworth notch reject filter
n = 4; % order
B = zeros(M,N);
for i = 1:M
for j = 1:N
d = sqrt((i-cx)^2 + (j-cy)^2);
if d >= r-w/2 && d <= r+w/2
B(i,j) = 1 / (1 + (d/r)^(2*n));
else
B(i,j) = 1;
end
end
end
% Filter in image form
figure; imshow(B, []); title('Filter')
The correct implementation of Butterworth notch filter is shown below:
I = imread('moire.png');
% Define the center of the notch reject filter
[M, N] = size(I);
cx = M/2; cy = N/2;
% Define the radius and width of the notch reject filter
r = 15; % radius
% Compute the Butterworth notch reject filter
n = 4; % order
B = ones(M,N);
notch_centers = [-42.5, 25; 42.5, 25; -85, 25; 85, 25];
for i = 1:M
for j = 1:N
H = 1;
for k = 1:size(notch_centers,1)
% u-coordinate of the k-th notch center
u_k = notch_centers(k,1);
% v-coordinate of the k-th notch center
v_k = notch_centers(k,2);
% Distance to (u_k, v_k)
Dk = sqrt((i - cx - u_k)^2 + (j - cy - v_k)^2);
% Distance to symmetric notch (-u_k, -v_k)
Dk_neg = sqrt((i - cx + u_k)^2 + (j - cy + v_k)^2);
% Butterworth response for both notches
H = H * 1/(1 + (r/Dk)^(2*n)) * 1/(1 + (r/Dk_neg)^(2*n));
end
B(i, j) = H;
end
end
% Filter in image form
figure; imshow(B, []); title('Filter')
Visualizing the filter in image form confirms that it is a notch filer. Here, the notch centers are specified manually for demonstration but can be also calculated automatically using thresholding technique. With the correct filter in place, proceeding with remaining steps should yield the correct results.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
