### Confused about median

Posted:

**2018-10-21T12:59:14-07:00**Hi there,

using Linux and ImageMagick 6.9.10-8 Q16 x86_64 20180723

I'm somewhat confused about the results of -statistic median. Please correct me if I'm wrong: Assuming that we do have a 2x2 grayscale grid with two pixel having a value of 134 (gray) and two having a value of 255 (pure white). Calculating the median of that would be: (134, 134, 255, 255) - pick the middle values (134, 255) sum them and divide by 2 = ~194. Correct?

The documentation states that -statistic will "replace each pixel with corresponding statistic from the neighborhood." so if I apply -statistic median 2x2 to a picture, all 4 pixels should be replaced by the result of the statistic, shouldn't they (probably due to my english skills I understood it wrongly)?

I created a 6x4 graphic in which I do have different pixels and issued the following command:

And I do not understand the result. The above example grid:

134 255

255 134

turns into

255 255

255 255

None of the tests I did has shown the result for a mathematical median operation (is my calculation wrong?)

I started playing around with that when I was looking for a median-resize and found this post: https://www.imagemagick.org/discourse-s ... hp?t=31624 though instead of going with a 5x5 grid I'd like to use the median result of just 4px (2x2).

Okay, so what do I do wrong?

Jean

using Linux and ImageMagick 6.9.10-8 Q16 x86_64 20180723

I'm somewhat confused about the results of -statistic median. Please correct me if I'm wrong: Assuming that we do have a 2x2 grayscale grid with two pixel having a value of 134 (gray) and two having a value of 255 (pure white). Calculating the median of that would be: (134, 134, 255, 255) - pick the middle values (134, 255) sum them and divide by 2 = ~194. Correct?

The documentation states that -statistic will "replace each pixel with corresponding statistic from the neighborhood." so if I apply -statistic median 2x2 to a picture, all 4 pixels should be replaced by the result of the statistic, shouldn't they (probably due to my english skills I understood it wrongly)?

I created a 6x4 graphic in which I do have different pixels and issued the following command:

Code: Select all

`convert scale-test.png -statistic median 2x2 scale1.png`

134 255

255 134

turns into

255 255

255 255

None of the tests I did has shown the result for a mathematical median operation (is my calculation wrong?)

I started playing around with that when I was looking for a median-resize and found this post: https://www.imagemagick.org/discourse-s ... hp?t=31624 though instead of going with a 5x5 grid I'd like to use the median result of just 4px (2x2).

Okay, so what do I do wrong?

Jean