Page 1 of 1

Using -fx on a bilevel image

Posted: 2017-08-29T16:21:40-07:00
by edsw
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.

Re: Using -fx on a bilevel image

Posted: 2017-08-29T16:38:17-07:00
by fmw42
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.

Re: Using -fx on a bilevel image

Posted: 2017-08-29T16:57:07-07:00
by snibgo
edsw wrote:Black is 1.0 and white 0.0, are they not?
No. Black is 0.0.

Re: Using -fx on a bilevel image

Posted: 2017-08-29T17:41:56-07:00
by edsw
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.