I am trying to learn how to use ImageMagicK and I wanted to make sure my logic for fixing the problem I am trying to solve makes since.
I am using a sheet feed scanner to scan images and around the image is a black background with streaks from pulling the image through so it is not a solid color value.
What I am wanting to accomplish is to turn the background area that is black and contains streaks into a solid white area and crop and straighten the image.
So I believe I need to create a layer and then use fuzz to blur the black background then I need to take a sample of the black area to get the color value. Then I need to create a mask then somehow I tell it to delete the area outside the mask on the first layer resulting in a white background. And I can discard the second layer . Then I run the crop or trim command.
Does this approach sound valid, Anyone have any tips or suggestions?
Thanks
Wanting to confirm my approch at editing a image is valid
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Wanting to confirm my approch at editing a image is vali
Can you provide an example of the problem? You can post to an free image hosting service such as dropbox and then put a link here.
Re: Wanting to confirm my approch at editing a image is vali
Hi Fred.
I just uploaded 4 sample images to dropbox here is the link.
https://www.dropbox.com/sh/dp5ezraog0iiuqi/Avj5JiEJKq
I just uploaded 4 sample images to dropbox here is the link.
https://www.dropbox.com/sh/dp5ezraog0iiuqi/Avj5JiEJKq
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Wanting to confirm my approch at editing a image is vali
You can do a blur and then a fuzzy trim and get the trim coordinates. Then use those to crop the unblurred image. Actually you can get the trim coords without having to trim by using the string format "%@" see http://www.imagemagick.org/script/escape.php. Using -deskew afterwards will unrotate the image (if less than about 5 deg) and then another trim will remove as much of the black background as possible. You can adjust the fuzz % to suit. The other side does not seem to show the lines, so a simple fuzzy trim ought to work.
cropcoords=`convert image0000001A.jpg -blur 0x2 -fuzz 30% -format "%@" info:`
echo "$cropcoords"
1809x1215+99+110
convert image0000001A.jpg -crop $cropcoords +repage -background black -deskew 40% -fuzz 50% -trim +repage result.jpg
Since the lines are vertical, you can use a 1D blur instead and it will be faster.
cropcoords=`convert image0000001A.jpg -morphology convolve blur:0x2 -fuzz 30% -format "%@" info:`
convert image0000001A.jpg -crop $cropcoords +repage -background black -deskew 40% -fuzz 50% -trim +repage result.jpg
cropcoords=`convert image0000001A.jpg -blur 0x2 -fuzz 30% -format "%@" info:`
echo "$cropcoords"
1809x1215+99+110
convert image0000001A.jpg -crop $cropcoords +repage -background black -deskew 40% -fuzz 50% -trim +repage result.jpg
Since the lines are vertical, you can use a 1D blur instead and it will be faster.
cropcoords=`convert image0000001A.jpg -morphology convolve blur:0x2 -fuzz 30% -format "%@" info:`
convert image0000001A.jpg -crop $cropcoords +repage -background black -deskew 40% -fuzz 50% -trim +repage result.jpg
Re: Wanting to confirm my approch at editing a image is vali
Fred
That works very good thank you very much for your help.
I was trying the commands on one that's turned pretty bad and it does not seem to be able to straiten it can you look at this file at this link and see if you can tell whats wrong? I had been playing with the fuzz and the blur but something is just not working.
https://www.dropbox.com/sh/a3bi9wx9bimaus8/k9OQQdAwcF
That works very good thank you very much for your help.
I was trying the commands on one that's turned pretty bad and it does not seem to be able to straiten it can you look at this file at this link and see if you can tell whats wrong? I had been playing with the fuzz and the blur but something is just not working.
https://www.dropbox.com/sh/a3bi9wx9bimaus8/k9OQQdAwcF
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Wanting to confirm my approch at editing a image is vali
-deskew seems to be limited to about 5 degrees.
You need to increase the blur and the fuzz value. This computes the deskew angle and you only have to trim once.
angle=`convert image0000001B.jpg -morphology convolve blur:0x3 \
-fuzz 50% -background black -deskew 40 -format "%[deskew:angle]\n" -write info: null:`
convert image0000001B.jpg -background black -rotate $angle -fuzz 50% -trim +repage 1tmp1.jpg
You need to increase the blur and the fuzz value. This computes the deskew angle and you only have to trim once.
angle=`convert image0000001B.jpg -morphology convolve blur:0x3 \
-fuzz 50% -background black -deskew 40 -format "%[deskew:angle]\n" -write info: null:`
convert image0000001B.jpg -background black -rotate $angle -fuzz 50% -trim +repage 1tmp1.jpg