Intelligent trimming in Magick++

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
carllos

Intelligent trimming in Magick++

Post by carllos »

Intelligent trimming in Magick++

Hi,

I’m new to ImageMagick. I need a way to automatically trim images and have a few questions:

-I’ve found a MagickTrimImage function that allows intelligent trimming, is there any Magick++ equivalent (trim() takes no arguments)?
-if not, can I use Magick++ and MagickWand In the same program? (If so, how to compile such a hybrid)?
-is there a way to leave about 5% margin when trimming? (that is, not to trim all the background, but leave a minimum amount, so that it will look more natural)?

Thanks in advance for the answers.

Karol
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Intelligent trimming in Magick++

Post by anthony »

carllos wrote:is there a way to leave about 5% margin when trimming? (that is, not to trim all the background, but leave a minimum amount, so that it will look more natural)?
Generally you trim, and then re-add a border of the right color.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
carllos

Re: Intelligent trimming in Magick++

Post by carllos »

Generally you trim, and then re-add a border of the right color.
Thanks for the answer, but that doesn't work for me. Usually the background has it's own texture - that's also why I can't use Image.trim(), so I can't just add a monocolor boarder.

Let's say this is a the picture:
http://www.torun.mm.pl/~carllos_pl/im/213011527.jpg

This is what I get with MagickTrimImage (still haven't found aMagick++ equivalent):
http://www.torun.mm.pl/~carllos_pl/im/2 ... r_trim.jpg

And this is what I would want to get:
http://www.torun.mm.pl/~carllos_pl/im/2 ... 20want.jpg

Note: I do not want to lose the background (eg. by flood-filling it).

Karol
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Intelligent trimming in Magick++

Post by anthony »

Then do the trim but rather than output an image output the results of the trim.
You can then adjust those results and do the crop yourself.

Code: Select all

convert image -trim -format '%wx%h%O' info:
Also see 'blured trim'....
http://www.imagemagick.org/Usage/crop/#trim_blur
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
carllos

Re: Intelligent trimming in Magick++

Post by carllos »

Thank you very much this is what I was looking for,

Is there a Magick++ equivalent for this, or is it just accesible by the command line?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Intelligent trimming in Magick++

Post by anthony »

You should be able to get that info directly from the trimmed image using 'get attributes'
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply