remove periodical like lines from the image

Hi people,
I have a question to you. I have this kind of picture:
You see kind of horizontal lines through the image. I'd like to remove them. What do you think can I do?
The mat file of matrix is attached here.
Thank you very much.

2 Comments

What have you tried so far? A convolution might do the trick already.
I tried this thread:https://www.mathworks.com/matlabcentral/answers/471074-remove-periodic-noise-pattern-from-image. Unfortunately it didnt help me much. Can you please give me some example and explain why convolution?
Thank you.

Sign in to comment.

 Accepted Answer

I actually suspect the bands are actual data and the circles are not, but without the context that is hard to tell.
S=load('matrix2see');
im=S.picture;
subplot(1,2,1)
imshow(im,[])
minmax=[min(im(:)) max(im(:))];
%create a column vector to use as a convolution kernel
kernel=ones(15,1);kernel=kernel/sum(kernel(:));
im2=conv2(im,kernel,'same');
subplot(1,2,2)
imshow(im2,minmax)
As you can see, that blurs the image a fair bit. What might perhaps work better is to subtract the mean of each row. This will only work if the bands are perfectly alligned to the grid.
figure
im3=im-mean(im,2);
imshow(im3,[])
You can fine-tune this second method by using a moving average instead of averaging the entire image.

6 Comments

Dear Rik,
Thank you very much. How did you conclude that average will help here? Anyway it looks much better.
You mean this function movmean? How do I know what window should I take?
Than you very much.
Glad to be of help. If my suggestions helped you solve the issue, please consider marking the answer as accepte.
I'm not aware of any choosing mechnanism that helps determining an appropriate strategy. So I'm afraid I don't have a better answer than intuition.
When it comes to your question about the window size: I would suggest choosing a window at least twice the size of the largest circle you expect. That way you will probably not harm the intensity of the circles, while still getting relatively good results for imperfectly alligned stripes.
Other than that: just experiment to find something that works. There is nothing special about the kernel size of 15 that I picked for the convolution method, other than that I thought it looked better than the results with 8. If you experiment enough you will find you develop an intuition about what things might work.
Or instead of a moving average, a median filter might work.
S = load('matrix2see.mat');
inpict = S.picture;
% normalize the input image
inpict = mat2gray(inpict);
% filter the image with a wide median filter
fpict = medfilt2(inpict,[1 100],'symmetric');
% subtract and clamp to discard the noise
% rescale to standard image data range
outpict = mat2gray(max(inpict - fpict,0));
% show the result
imshow(outpict)
Either way seems to also emphasize the ringing or whatever those artifacts are.
@DGM, I presumed that since the striping was considered artifacts, the circles would be the desired data.
Exactly, I want to remove the striping.
Just want to share the result I got from movmean(image,50,2)
im4=im-movmean(im,50,2);
Thank you for your suggestion, Rik. :)

Sign in to comment.

More Answers (2)

We really need to know what gave rise to the lines. For example are you using a line scan camera and the lighting is flickering?
What I'd do is to take the mean of the image horizontally and divide the image by the mean. That would compensate for the case where the row of the image is good, it's just the wrong brightness.
S = load('matrix2see')
S = struct with fields:
picture: [203×256 double]
grayImage = S.picture;
% imwrite(mat2gray(grayImage), 'dimani4.png')
[rows, columns, numberOfColorChannels] = size(grayImage)
rows = 203
columns = 256
numberOfColorChannels = 1
subplot(1,2,1)
imshow(grayImage,[])
title('Original Image')
rowMeans = mean(grayImage, 2);
repairedImage = grayImage ./ repmat(rowMeans, [1, columns]);
subplot(1,2,2)
imshow(repairedImage,[])
title('Repaired Image')
It looks like the rows means are not perfect, either because the lighting changes as the scan goes across, or the presence of particles in there affects the mean, changing it from it's true value. If you could get the means from a totally blank shot, it would help, but that assumes the pattern of lines stays fixed from one shot to the next.

4 Comments

Hi Image Analyst,
Thank you for your answer. This picture is just an AFM scan of some sample. This lines actually the lines when the probe goes in X line during the scan.
This is some artifact which doesnt reflect the sample's features.
Actually as I told already to Rik I tried to use your example when you remove the periodic noise from cameraman picture periodic noise removement but it didnt help me much because I didnt see any spikes in the fourier picture.
Thanks.
Yes, that wouldn't. That's because it's a Fourier filtering (in the spectral domain) which looks for spikes in the spectrum. Spikes in the spectrum indicate a lot of energy in periodic frequencies. You can see from your noisy lines that it is anything but periodic, so the energy from your noise would not be concentrated into spikes. So no spikes and no periodic noise removal.
If you could answer my questions, it might help devise a denoising algorithm. Mainly, do the lines appear in the same location for every image? And if so, can you make a blank scan with no sample in place?
Dimani4
Dimani4 on 29 Dec 2022
Edited: Dimani4 on 29 Dec 2022
Thank you for your answer.
No, unfortunately the lines are not appear in the same location for every image.I cannot do the scan without sample because the tip during the scan should be in contact with the sample (AFM- Atomic Force Uscope), So these lines happened because the scan was performed in noisy environment (people were chatting during the scan).
As usual with these files people using WSxM program to remove noises from the picture and analyse pictures and so on. So Subtract Line Filter in WSxm looks similar as the movmean function of Matlab to this particular picture. Look at the attached figures.
I added .stp file in .zip which can be opened in WSxm program.
If you're happy with the result, that's fine. The moving mean will blur the image more than a moving median. But maybe the blur is not important for what you need to do with the image. If it's really important you can rescan the sample and tell everyone not to talk.

Sign in to comment.

Hi Dimani,
An alternative way is fit 1st or 2nd order polynomials to each line:
img =picture;
polyx = 1; %change to 2 for 2nd order polynomial
xl = 1:size(img,2);
for i =1:size(img,1)
y1 = img(i,:);
x1 = xl;
[p,~,mu] = polyfit(x1,y1,polyx);
result(i,:) = img(i,:) - polyval(p,1:size(img,2),[],mu);
end
imagesc(result)
This can then be refined with thresholding to exclude high or low regions, this example using the otsu method to auto threshold:
min_max(2) = multithresh(result,1);
min_max(1) = -inf;
imgt = (result<=min_max(2)).*(result>=min_max(1));
imgt(imgt==0) = NaN;
xl = 1:size(result,2);
for i =1:size(result,1)
pos = imgt(i,:)>0;
if sum(pos)>polyx+5
y1 = result(i,pos);
x1 = xl(pos);
[p,~,mu] = polyfit(x1,y1,2);
result2(i,:) = result(i,:) - polyval(p,1:size(result,2),[],mu);
else
result2(i,pos) = result(i,pos);
end
end
imagesc(result2)
The full codes for plane and line leveling are avalible in a GUI and as source code (see filter_img_v2)

Products

Release

R2016b

Asked:

on 27 Dec 2022

Answered:

on 9 Oct 2024

Community Treasure Hunt

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

Start Hunting!