cropping noisy background/border

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
zuck
Posts: 2
Joined: 2016-12-21T13:49:11-07:00
Authentication code: 1151

cropping noisy background/border

Post by zuck »

Hi there,
I'm looking for a way to crop a mostly dark/black but noisy background (or make it transparent) from a stack of images.
Here are some examples: http://imgur.com/a/8gE82
I tried trimming with the fuzz-option, but that's not enough. I'm sure there is a solution with the imagemagick-magic, but I'm a bit overwhelmed by the options and algorithms. :shock: I would be very grateful for any ideas.
I'm using a Linux system with the folloing imagemagick version: ImageMagick 6.9.6-7 Q16 x86_64

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

Re: cropping noisy background/border

Post by fmw42 »

try

Code: Select all

convert image -fuzz XX% -trim +repage result
see http://www.imagemagick.org/Usage/crop/#trim_fuzz
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: cropping noisy background/border

Post by anthony »

Also see... trimming noisy image
http://www.imagemagick.org/Usage/crop/#trim_noisy

This blurs the image to filter out the noise, trims it with an appropriate fuzz, then applies that trim results to the unblurred image with some adjustments.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
zuck
Posts: 2
Joined: 2016-12-21T13:49:11-07:00
Authentication code: 1151

Re: cropping noisy background/border

Post by zuck »

Thanks for the replies.

@fmw42: I tried that already and the result wasn't satisfcatory, apparently the bits of noise are too large.
@anthony: That worked quite well after playing with the blurring-value, thank you.
For the sake of completeness, the commands I used:

Code: Select all

for i in *.jpg; do convert $i -crop `convert $i -virtual-pixel edge -blur 0x50 -fuzz 30% -trim -format '%[fx:w-20]x%[fx:h-20]+%[fx:page.x+10]+%[fx:page.y+10]'  info:`   +repage   crop_$i;done
and

Code: Select all

for i in *.jpg; do convert $i -crop `convert $i -virtual-pixel edge -blur 0x50 -fuzz 30% -trim -format '%wx%h%O' info:`   +repage   crop_$i;done
Follow-up luxury problem: As the manuscripts aren't always perfectly adjusted I have two options: cropping the manuscript too large or too small (see commands above). Is there somehow an option to make the difference between an inner and an outer crop transparent.
Example: http://imgur.com/a/M9H9L (I'd wish to make those black pixels in the bottom right corner disappear...)
Post Reply