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?".
iknowmac
Posts: 3 Joined: 2016-07-18T16:16:25-07:00
Authentication code: 1151
Contact:
Post
by iknowmac » 2016-07-18T16:40:48-07:00
Hi Guys... I'm trying to trim the top and left of a registration based on a barcode and block rectangle. See image...
https://goo.gl/photos/rFDiKzzhUeKoWWiu7
Here is the code I'v tried, but have gotten inconsistent behavior...
Code: Select all
convert input.jpg -gravity NorthWest -crop \
`convert input.jpg -canny 0x1+10%+30% -virtual-pixel edge -blur 0x5 -fuzz 10% -trim \
-format '%[fx:w-20]x%[fx:h-20]+%[fx:page.x-10]+%[fx:page.y-10]' \
info:` +repage output_trimmed.jpg
Here is an image of what I am looking to achieve...
https://goo.gl/photos/zitxKiGLKhNbg76SA
ImageMagick version...
Any assistance would be appreciated...
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:
Post
by snibgo » 2016-07-18T17:38:18-07:00
You might also show an example where your command doesn't do what you want.
You might find it helpful at the start to turn the most of the paper white, and some ink black:
Code: Select all
convert input.jpg -contrast-stretch 1%x50% -canny 0x1+10%+30% -virtual-pixel edge {etc...}
And, of course, don't use JPEG unless you really have to.
iknowmac
Posts: 3 Joined: 2016-07-18T16:16:25-07:00
Authentication code: 1151
Contact:
Post
by iknowmac » 2016-07-19T14:24:06-07:00
This is tremendous snibgo... It's getting closer and closer... Below are three examples of what I mean by "inconsistent behavior" using your suggestion.
https://goo.gl/photos/En9HE9mphZEwbgtL7
https://goo.gl/photos/DhNbMYnsB4trzFa68
https://goo.gl/photos/yTZPVF8YFmZx7XzQA
Sometimes the top and left are right on, and other times is over or under. Would it be possible to use just the black rectangle on the left to get an accurate alignment each time? I really don't need the barcode, I thought it would just be easier to align on.
Thanks for all you advice...
iknowmac
Posts: 3 Joined: 2016-07-18T16:16:25-07:00
Authentication code: 1151
Contact:
Post
by iknowmac » 2016-07-21T13:04:24-07:00
After a lot of tweaking I finally have something usable...
Code: Select all
convert input.png -crop \
`convert input.png -morphology Smooth Octagon:3 -canny 0x1+10%+30% -trim -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]' info:` \
+repage output_trimmed.png
However is there a way to only apply the trim to the top and left of the image and leave the rest alone?
snibgo
Posts: 12159 Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:
Post
by snibgo » 2016-07-21T13:16:58-07:00
"-crop" takes parameters WxH+X+Y. If W==0, it will crop from the x-offset to the remainder of the width. Likewise H.
So just use 0x0 instead of %[fx:w]x%[fx:h]
Users browsing this forum: Ahrefs [Bot] , Google [Bot] and 12 guests