Using -fx on a bilevel 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
edsw
Posts: 2
Joined: 2017-08-29T14:15:11-07:00
Authentication code: 1151

Using -fx on a bilevel image

Post by edsw » 2017-08-29T16:21:40-07:00

I am trying to turn white those black pixels of a bilevel image
that have less than 3 black neighbours. The original image is
predominantly white. At least two things do not work as expected.
(1)
`convert file1.bmp -fx "p[0,0]&&((p[-1,0]+...+p[-1,-1])>2.7)" file2.bmp'
works long and turns several white pixels black.
`convert file1.bmp -fx "p[0,0]||((p[-1,0]+...+p[-1,-1])>2.7)" file2.bmp'
takes much less time and does not.
(2)
The latter gets rid of (thin) lines and keeps the (fatter) polygons.
However, the polygons lose some "fat", at neat "step" boundaries too.
Even more surprisingly, replacing `2.7' with `1.7' makes the loss
greater while replacing `2.7' with `3.7' makes it smaller.

It seems I have got some notation wrong. Black is 1.0 and white 0.0,
are they not? && is AND and || OR, are they not?

The ImageMagic is 7.0.6-0 Q16 x86; not that it is likely to matter.

User avatar
fmw42
Posts: 22095
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Using -fx on a bilevel image

Post by fmw42 » 2017-08-29T16:38:17-07:00

Please post an example image. You can upload to some free hosting service and put the URL here.

Also what platform are you on?

Have you considered using a 3x3 moving average window to get the mean (-statistic mean 3x3) and then converting anything less than or equal to 3/9=33.33% (3/9 since the mean contains the center pixel) to white? Probably easier the negate the image and threshold on anything above 5/9=55.55% (or anything equal to or greater than 6/9=66.67%), then negate again.

snibgo
Posts: 9391
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Using -fx on a bilevel image

Post by snibgo » 2017-08-29T16:57:07-07:00

edsw wrote:Black is 1.0 and white 0.0, are they not?
No. Black is 0.0.
snibgo's IM pages: im.snibgo.com

edsw
Posts: 2
Joined: 2017-08-29T14:15:11-07:00
Authentication code: 1151

Re: Using -fx on a bilevel image

Post by edsw » 2017-08-29T17:41:56-07:00

Thank you, fmw42 and snibgo.
White being 1.0 and black 0.0,
`convert file1.bmp -fx "p[0,0]||((p[-1,0]+...+p[-1,-1])>5.1)" file2.bmp'
does what I meant.
The 3x3 window approach does not let treat the centre differently, does it?
And, if it does not, polygonal concavities make things difficult.

Post Reply