Page 1 of 1

Remove blackborder after scanning

Posted: 2012-07-16T00:05:16-07:00
by adil@alfasoft.ro
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.

Image

Thanks for your help!

Re: Remove blackborder after scanning

Posted: 2012-07-16T01:25:56-07:00
by whugemann
Something like

Code: Select all

convert test.jpg -deskew 40% -crop 480x680+10+10 -gravity center -extent 500x700 ready.jpg
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.

Re: Remove blackborder after scanning

Posted: 2012-07-16T01:39:03-07:00
by adil@alfasoft.ro
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.

Re: Remove blackborder after scanning

Posted: 2012-07-16T10:13:23-07:00
by fmw42
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

Re: Remove blackborder after scanning

Posted: 2012-07-17T00:17:34-07:00
by adil@alfasoft.ro
It's working! Thank you very much Fred.

Re: Remove blackborder after scanning

Posted: 2013-05-30T06:17:14-07:00
by hri
Hello,

I have the same problem but i need to do this with Magick.NET is there a way to do this ?

Regads,

Re: Remove blackborder after scanning

Posted: 2013-05-30T17:03:04-07:00
by fmw42
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

Image

Re: Remove blackborder after scanning

Posted: 2013-05-30T23:45:40-07:00
by hri
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
Can you please clarify your idea? how to average the image down to one row? Is there a way with Magick.NET?
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

Re: Remove blackborder after scanning

Posted: 2013-05-31T09:16:26-07:00
by fmw42
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.