Is there anyway to remove/fix the white line like you see in this image (it's about 1/3 down from the top):
https://imgur.com/a/iX5pksF
Ideally it would figure out the position of the line automatically as I have scanned pictures that have these lines in various locations.
I'm using ImageMagick 7.0.8-6 on a Mac (but I have access to other platforms if needed)
Remove/Fix white lines
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove/Fix white lines
You can apply a median filter, but it will blur the image a bit.
Or you can create a binary mask just where the line exists and use the mask to decide between the original and the median filtered version in the output. This will only mitigate the artifact.
User snibgo has an inpainting/hole filling technique that should be much better, but he is on Windows. Nevertheless, see his hole-filling sections at http://im.snibgo.com
Code: Select all
magick shed.jpg -statistic median 1x15 shed_med1x15.jpg
Code: Select all
magick shed.jpg \( -clone 0 -statistic median 1x15 \) \( -clone 0 -fill black -colorize 100 -fill white -draw "rectangle 0,659 %w,660" -alpha off \) -compose over -composite shed_result.jpg
User snibgo has an inpainting/hole filling technique that should be much better, but he is on Windows. Nevertheless, see his hole-filling sections at http://im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Remove/Fix white lines
What has caused the white line? Perhaps a fault in a film camera has scratched the film, in which case the white line will be in the same place, more or less, on all photos. This limits the area you need to search for the line.
Scaling this image to a single column, and searching for a light pixel with darker ones above and below, shows the line occurs at y=659, plus or minus 2.
I would make those lines transparent, then experiment to find the most effective infill technique. Some of the methods I show (such as filling holes with priority) need IM to be built with my process modules. Others (such as blur-fill) are Windows BAT scripts that could be converted to bash.
Scaling this image to a single column, and searching for a light pixel with darker ones above and below, shows the line occurs at y=659, plus or minus 2.
I would make those lines transparent, then experiment to find the most effective infill technique. Some of the methods I show (such as filling holes with priority) need IM to be built with my process modules. Others (such as blur-fill) are Windows BAT scripts that could be converted to bash.
snibgo's IM pages: im.snibgo.com
Re: Remove/Fix white lines
No the photos are fine it’s the scanner. I’m using the Epson FastPhoto FF-640. I’m having a bit of a love/hate relationship with it. When it works, it works great, but it has a tendency to get dust on the rollers which cause the white streaks. I could clean off the scanner more often but that defeats the whole purpose of batch scanning as I would have to clean it like after every 10 scans. I have thousands of family photos to scan so I'll like to at least get something done in a reasonable amount of time.
fmw42's example above with the mask works pretty well. I wrote a simple script that lets me adjust the position and thickness of the mask region and I’m still testing that out (typically the scanner will have something like a batch of 5-10 with the same lines. Then it’ll be fine for awhile then a new line somewhere else).
snibgo - I was looking at your site earlier and I haven’t had a chance to follow the instructions for compiling your process modules into the app yet, but I’ll probably give that a try.
Can you give me more info about how you “search[ed] for a light pixel with darker ones above and below”. Did you mean you did that programmatically or manually? That could be helpful for my script.
fmw42's example above with the mask works pretty well. I wrote a simple script that lets me adjust the position and thickness of the mask region and I’m still testing that out (typically the scanner will have something like a batch of 5-10 with the same lines. Then it’ll be fine for awhile then a new line somewhere else).
snibgo - I was looking at your site earlier and I haven’t had a chance to follow the instructions for compiling your process modules into the app yet, but I’ll probably give that a try.
Can you give me more info about how you “search[ed] for a light pixel with darker ones above and below”. Did you mean you did that programmatically or manually? That could be helpful for my script.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove/Fix white lines
I could be wrong, but I think it was a manual process to convert the area/line into transparency in the input image. If you know where the line is and how thick, you can create the mask like I did, but inverted so that the line is black and everything else is white. Then put that binary image into the alpha channel of your image, via
Then use his code.
Code: Select all
convert image mask -alpha off -compose copy_opacity -composite result
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Remove/Fix white lines
I scaled it to one column, then scaled that to 50 columns so I could see it, then used a GUI to find the location visually. (I used my own Swim, but Gimp could do the job.)
A v7 Windows BAT script to automatically find the white line is:
The output is:
Subtract one from the y because of the black border. So, according to this, it starts at y=657, and occupies 5 rows. For best overall results the threshold may need tweaking.
Each write merely creates an image we can look at, to check the work. It will be quicker if you don't write those, and don't scale to 50 pixels wide.
A v7 Windows BAT script to automatically find the white line is:
Code: Select all
%IMG7%magick udsf43P.jpg -scale "1x^!" -scale "50x^!" ^
-define convolve:scale="50%%^!" -bias 50%% ^
-write x0.png ^
-morphology Convolve Sobel:90 ^
-solarize 50%% -level 50,0%% ^
-auto-level ^
-write x1.png ^
-threshold 40%% ^
-bordercolor black -border 1 ^
-write x2.png ^
-format %%@\n info:
Code: Select all
50x5+1+658
Each write merely creates an image we can look at, to check the work. It will be quicker if you don't write those, and don't scale to 50 pixels wide.
snibgo's IM pages: im.snibgo.com