I am trying to crop out the background of a document so that I can then flatten and remove perspective of the document. I can use Fred Weinhaus's unperspective for that part. The problem I am having is preparing the image mask to use. I have an example document with a blank page on a wood table, I am trying to create a mask of the page and remove the background but am having difficulty doing so because of the darkness change of the wood.
Here's my original
Here's after using unperpsective with a couple different -f values
cropping document with variable background
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: cropping document with variable background
I don't have too much time right now, but try separating channels and see if one of them works better. Also try converting to other colorspaces and separate channels and see if one of them works.
Note that your page here is gray and has a brown background. Thus for gray saturation will be low. Perhaps you can do a fuzzy floodfill on the gray to white and then replace all non-white with black to create a mask.
Note that your page here is gray and has a brown background. Thus for gray saturation will be low. Perhaps you can do a fuzzy floodfill on the gray to white and then replace all non-white with black to create a mask.
Re: cropping document with variable background
You can play around with something like this:
convert 0M5Hiq1.jpg -normalize -fuzz 50% -fill black -opaque red -fill black -opaque brown out.jpg
Arvin
convert 0M5Hiq1.jpg -normalize -fuzz 50% -fill black -opaque red -fill black -opaque brown out.jpg
Arvin
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: cropping document with variable background
This seems to work well for me on IM 6.8.6.0 Q16 Mac OSX as I mentioned above separating the Saturation channel
convert 0M5Hiq1.jpg -colorspace HSL -channel g -separate +channel -fuzz 10% -fill black -opaque black -fill white +opaque black mask.png
But you can play with the -fuzz value
convert 0M5Hiq1.jpg -colorspace HSL -channel g -separate +channel -fuzz 10% -fill black -opaque black -fill white +opaque black mask.png
But you can play with the -fuzz value
Re: cropping document with variable background
Thanks! Will test this with a variety of captures that I have but it has worked well with the initial set. Greatly appreciated, also thanks for all your scripts on your site.fmw42 wrote:This seems to work well for me on IM 6.8.6.0 Q16 Mac OSX as I mentioned above separating the Saturation channel
convert 0M5Hiq1.jpg -colorspace HSL -channel g -separate +channel -fuzz 10% -fill black -opaque black -fill white +opaque black mask.png
But you can play with the -fuzz value