I scanned some books and randomly there are pages with a black border because of skewing in different sides of the page (probably because the page was not cut straight).
What i would like to do is either:
1.Automatically Color the black borders in white
2.Automatically Cut the black borders
I've attached an example showing the problem that i have.
Thanks for your help!
Remove blackborder after scanning
-
- Posts: 24
- Joined: 2012-01-10T05:19:23-07:00
- Authentication code: 8675308
- whugemann
- Posts: 289
- Joined: 2011-03-28T07:11:31-07:00
- Authentication code: 8675308
- Location: Münster, Germany 52°N,7.6°E
Re: Remove blackborder after scanning
Something like
should do: It corrects the angle by -deskew, then crops the page and extends it again, assuming that the borders of the page are, if not black, then more or less plain white. The code refers to the dimensions of your example.
Code: Select all
convert test.jpg -deskew 40% -crop 480x680+10+10 -gravity center -extent 500x700 ready.jpg
Wolfgang Hugemann
-
- Posts: 24
- Joined: 2012-01-10T05:19:23-07:00
- Authentication code: 8675308
Re: Remove blackborder after scanning
Thank you. The problem is that the black border appear randomly and the width and position is randomly.In my opinion, first operation must be color in white the blackborder, and after that the deskew. But I dot know how to do.
There is an example somewhere in the forum
-bordercolor black -border 4x4 -fuzz "30%" -trim .....
but in my case is not working.
There is an example somewhere in the forum
-bordercolor black -border 4x4 -fuzz "30%" -trim .....
but in my case is not working.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove blackborder after scanning
try this. seems to work for me
convert 28uibes.jpg -bordercolor black -border 1 -fuzz 95% -fill white -draw "color 0,0 floodfill" -alpha off -shave 1x1 28uibes_result.png
convert 28uibes.jpg -bordercolor black -border 1 -fuzz 95% -fill white -draw "color 0,0 floodfill" -alpha off -shave 1x1 28uibes_result.png
-
- Posts: 24
- Joined: 2012-01-10T05:19:23-07:00
- Authentication code: 8675308
Re: Remove blackborder after scanning
It's working! Thank you very much Fred.
Re: Remove blackborder after scanning
Hello,
I have the same problem but i need to do this with Magick.NET is there a way to do this ?
Regads,
I have the same problem but i need to do this with Magick.NET is there a way to do this ?
Regads,
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove blackborder after scanning
Magick.NET is listed as Imagemagick API at http://www.imagemagick.org/script/api.php. So in principle it should work. But I know little about any APIs. So cannot advise past command line concepts.
__________________________
Another way, is to average the image down to one row and analyze the profile to find where the black edges end and pure white starts. Or to find where the pure white ends and you have the text area. Then crop as appropriate and if desired pad back out with white. Using the image provided at the first post:
convert 28uibes.jpg -resize x1! miff:- | im_profile - 28uibes_profile.png
__________________________
Another way, is to average the image down to one row and analyze the profile to find where the black edges end and pure white starts. Or to find where the pure white ends and you have the text area. Then crop as appropriate and if desired pad back out with white. Using the image provided at the first post:
convert 28uibes.jpg -resize x1! miff:- | im_profile - 28uibes_profile.png
Re: Remove blackborder after scanning
Can you please clarify your idea? how to average the image down to one row? Is there a way with Magick.NET?Another way, is to average the image down to one row and analyze the profile to find where the black edges end and pure white starts
I simply need to calculate the black border width and height that is in the image and replace it with white border or crop it....
Thanks in advanced
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Remove blackborder after scanning
the command is as above, but probably better to use -scale
convert 28uibes.jpg -scale x1! image.txt
Once you have the 1 row image as text, you can filter for the color and coordinates. Then find the range of the pure white borders on the left and on the right and crop in the middle of the white borders (or on either the inside or the outside edge of the white -- anywhere is fine). Then pad back out to the original size if desired.
With the image above, there is black on the bottom. So what you probably need to do is find the max (near white) on the left and right, crop, then repeat with averaging to one column and do the same vertically.
convert 28uibes.jpg -scale x1! image.txt
Once you have the 1 row image as text, you can filter for the color and coordinates. Then find the range of the pure white borders on the left and on the right and crop in the middle of the white borders (or on either the inside or the outside edge of the white -- anywhere is fine). Then pad back out to the original size if desired.
With the image above, there is black on the bottom. So what you probably need to do is find the max (near white) on the left and right, crop, then repeat with averaging to one column and do the same vertically.