Crop/Trim picture by specific border inside picture

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
Natural_born_chilla
Posts: 2
Joined: 2011-12-01T03:28:25-07:00
Authentication code: 8675308

Crop/Trim picture by specific border inside picture

Post by Natural_born_chilla »

Hello girls and guys,

I already searched a lot on the internet but I just can't find a solution for this.

I have a picture with background (which needs to be removed) - the background is inhomogeneous, i.e. not of the same color etc.

Inside the picture, there is my wanted content. A border with a color I specified defines the surrounding.

How may I crop it? I tried something with txt to find the color, but I'm on windows and can't use grep. Also, it's very slow.

An example (note: the border in reality is 1px exact and same color anywhere):
Image

Any help and ideas are appreciated!!

Flo
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop/Trim picture by specific border inside picture

Post by fmw42 »

try a fuzzy floodfill from each corner to get a constant color around the center area. Then use -trim +repage.

see
http://www.imagemagick.org/Usage/draw/#color
http://www.imagemagick.org/Usage/crop/#trim
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Crop/Trim picture by specific border inside picture

Post by anthony »

The other way is to generate a mask of the dividing color. A trim of that mask will then get you the bound by which you can crop the original.

Something similar to this is done (using blur rather than a mask) in
Trimming 'Noisy' Images
http://www.imagemagick.org/Usage/crop/#trim_noisy

Just generate the bounds mask instead of the blurred image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Natural_born_chilla
Posts: 2
Joined: 2011-12-01T03:28:25-07:00
Authentication code: 8675308

Re: Crop/Trim picture by specific border inside picture

Post by Natural_born_chilla »

Insane! Works like a charm!

I am very thankful for the tip. My solution is just straight forward, I use filltoborder with my specified border color, then trim and repage.

Thank you very much! May the force be with both of you :)
Post Reply