Trim noisy image

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
il_mix
Posts: 3
Joined: 2016-03-30T22:18:17-07:00
Authentication code: 1151

Trim noisy image

Post by il_mix »

Hi, everyone!

I need to trim the white border from some grayscale (actually B/W) images. These are scans of paper pages (comix strips), and there are some noisy pixels that prevent a good trim with this "standard" ImageMagick command

Code: Select all

convert input -bordercolor white -border 1x1 -fuzz 50% -trim +repage output
As said, these are B/W images, so the "fuzz" parameter is quite useless (pixel values are 0 or 255).
Here is an example of input and trimmed image. Due to some noise on the border (need to zoom to view it) the trim algorithm fails (better, didn't meet my needs).

INPUT
Image

OUTPUT
Image

Any idea about how to trim the full border?

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

Re: Trim noisy image

Post by fmw42 »

Please supply your IM version and platform when asking questions. Please post an example actual image so others can test. You can post to some free hosting service such as dropbox.com and put the URL here.

Please read viewtopic.php?f=1&t=9620
il_mix
Posts: 3
Joined: 2016-03-30T22:18:17-07:00
Authentication code: 1151

Re: Trim noisy image

Post by il_mix »

About the IM version I will have to wait this evening to update the message.
About the "actual image", the two images are actual input/output of the command I wrote. There are no contents in the panels, but if a script works on the posted image it is enough for me. Also, since the panels content may vary, I think that empty panels are the "worst case" regarding border trimming.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trim noisy image

Post by snibgo »

I suggest you de-noise the image and find what trim would be obtained. Then crop the original to that trim. For example:

Code: Select all


f:\web\im>%IM%convert input_zpshxil0xao.png -median 5x5 -format %@ info:
2221x3062+134+89

f:\web\im>%IM%convert input_zpshxil0xao.png -crop 2221x3062+134+89 c.png
You will need a script to get the ouput from the first convert into the second.
snibgo's IM pages: im.snibgo.com
il_mix
Posts: 3
Joined: 2016-03-30T22:18:17-07:00
Authentication code: 1151

Re: Trim noisy image

Post by il_mix »

@snibgo, I'll give it a try. I think I can do quite a hard median without screwing the results, given the images I'm working on.
I also thought about trimming (or medianing, given your hint) all images than crop with a median (arithmetical) of the results.
Post Reply