How can I get rid of the horizontal white lines?

How can I remove the horizontal white lines from an image like these without majorly editing the surroundings? Medfilt has been suggested, but it doesn't seem to be working. All code is appreciated. Thank you!

Answers (3)

You can try Fourier filtering. The white lines, if they're periodic, will show up as spikes in the spectrum which you can then zero out and inverse transform. Example attached (with demo image, not yours).

4 Comments

Hi! Thank you so much for always helping. However, when I try using my image, the result looks like the attached. What am I doing wrong?
You didn't adapt the code.
You don't need to start with a good image and create a bad one like I did. I have people running the demo who don't yet have a bad image so we must create one so they can use it. You already have a bad image to begin with. So just use that. Then next step after you call imread() is to call fft2().
I edited the code to get ride of the first part and changed the subplots, but the result is like this?
It doesn't look like thresholding is a good way to get the spikes. You might try zeroing out the very small, exact area where you see spikes on the Y axis of the spectrum, if you can see them. Otherwise you'll have to try some kind of ad hoc filter in the spatial domain, like summing your image horizontally (to get the vertical profile)
verticalProfile = mean(grayImage, 2);
and looking for peaks/spikes in the vertical profile..

Sign in to comment.

K-Nearest Neighbor Filtering does a decent job. You can play with the parameters, but here are some quick settings I tried.
For each pixel, find the 49 nearest neighbors. Of those 49, average the 25 pixels nearest in intensity to the selected pixel. Replace the value of the selected pixel with that mean.
This can be done fairly efficiently with colfilt(). The result isn't perfect, but it's not terrible, either. I attached the result for enf.jpg.
Good luck,
Eric

1 Comment

You could also try the median of the 25 pixels nearest in intensity to the selected pixel.
Neighborhood operations like this should help. The lines are 1D so looking at statistics over small, 2D regions will help beat down the noise associated with the 1D streaks.

Sign in to comment.

You can get the vertical profile, find the peaks and then replace those lines with the median filtered version. See attached test.m file.
Not perfect, but a fairly good improvement. Spend a day tweaking it and you might even get it better.

7 Comments

If you collapse the image horizontally, across columns, and get the average vertical intensity, that's what I call verticalProfile. What would you call it if you got the mean value of each row and put that into an array - a vector that had as many elements as you have rows in your image?
I thought the overall quality of the image increased. It got rid of most of the horizontal lines didn't it. Sure, some parts near the lines may not look as sharp as they would have if the lines hadn't been there, but that's the price you have to pay for improving the image. And pixels that are nowhere near any lines don't get altered so they're as sharp as originally.
Ohh I see. I'm still confused on how the you are determining the peaks/what you are replacing them with. Even when I set the peak threshold to 1, the resulting image is like the attached. Ah I'm confused! Sorry and thanks
I thought it was pretty well commented. What lines are you confused about? You didn't attach any image.
If you wanted the "fixed" pixels to be black instead of the median filtered value, you can do this:
% For each peak, replace original line with median filtered line.
outputImage(thisRow, :) = 0;
Obviously you'll then have black lines through the image instead of white lines or lines that look like the surrounding pixels. So I don't know why you'd want to do that.
I'm just confused about how the peaks are calculated; I want to make it so that other parts of the image that are not affected.
The peaks are calculated by taking the mean across the image to get the vertical profile. Then it finds the lower boundary of that profile and subtracts that smoother curve. Any peaks will have a higher value than lines without peaks and be detected by a thresholding. Any line above the threshold is determined to be a bad line with peaks and is replaced by the median filtered line.
Other lines are not affected, only lines with peaks are affected.
Why not put some energy towards making sure the noise lines don't appear in the first place. It's often easier to prevent the problem than to fix it once it's there.
Have you checked PubMed, or the Image Processing Literature for papers related to breathing and heartbeat correction?

Sign in to comment.

Asked:

on 13 Jul 2017

Commented:

on 25 Jul 2017

Community Treasure Hunt

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

Start Hunting!