Wanting to confirm my approch at editing a image is valid

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
wappy
Posts: 9
Joined: 2013-11-09T18:27:19-07:00
Authentication code: 6789

Wanting to confirm my approch at editing a image is valid

Post by wappy »

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
User avatar
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

Post by fmw42 »

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.
wappy
Posts: 9
Joined: 2013-11-09T18:27:19-07:00
Authentication code: 6789

Re: Wanting to confirm my approch at editing a image is vali

Post by wappy »

Hi Fred.

I just uploaded 4 sample images to dropbox here is the link.

https://www.dropbox.com/sh/dp5ezraog0iiuqi/Avj5JiEJKq
User avatar
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

Post by fmw42 »

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
wappy
Posts: 9
Joined: 2013-11-09T18:27:19-07:00
Authentication code: 6789

Re: Wanting to confirm my approch at editing a image is vali

Post by wappy »

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
User avatar
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

Post by fmw42 »

-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
Post Reply