Hi guga,

-> I found it where VisualStudio generated negative values. It was the way the python version was created. It does not calculate the media of G directly, it calculate the median of Gx and later the median of Gy and only after it, it compute the value of G = sqrt (MedianGx^2 + MedianGy^2)

This comment from you is the reason I wrote a 6 numbers sorting routine.

The Median Matrix holds only positive numbers ( pixel values are never negative )

Therefore the calculation for the average middle numbers is correct.

And don't forget you only have to sort 6 values per matrix!!!

`To calculate the edges on the X axes`

[ X X X ]

Gx = [ 0 0 0 ]

[ X X X ]

To calculate the edges on the Y axes

[ X 0 X ]

Gy = [ X 0 X ]

[ X 0 X ]

You only need these 6 numbers. ( X's in the matrices )

For the Sobel Matrix convolution as for the Median Matrix calculations.

( You can save the Gray Color pixel conversion calculations as floating point )

( So you need no conversions from integer and floating point between all the calculation )

For the Median Matrix calculation you only read the 6 [X] pixel values ( always positive ) sort them, get the Median and that's the Gx and Gy.

No convolution needed as with the Sobel coefficients.

The G values should always be positive. ( they represent the new pixel color )

Hi Marinus, ok. But i´m getting a bit confused because this is not what the python version seems to be doing. For what i understood, the sequence of functions are those 2 parts.

1 - Call the function

**estimate_watermark**This function will export 2 buffers containing the median of Sobelx and SobelY calculated from N images . It will export them in Wm_x and Wm_y like this:

a) Create the sobel x and y on all N images

` gradx = list(map(lambda x: cv2.Sobel(`

x, cv2.CV_64F, 1, 0, ksize=KERNEL_SIZE), images))

grady = list(map(lambda x: cv2.Sobel(

x, cv2.CV_64F, 0, 1, ksize=KERNEL_SIZE), images))

So, here we have 100 (or N) Memory Buffers where it is stored the SobelX and Sobel Y on each image individually. So:

GradX from image 1 will contain the sobelx from image1. So, we can called it GradX(1)

GradY from image 1 will contain the sobely from image1. So, we can called it GradY(1)

GradX from image 2 will contain the sobelx from image2. So, we can called it GradX(2)

GradY from image 2 will contain the sobely from image2. So, we can called it GradY(2)

GradX from image N will contain the sobelx from image1. So, we can called it GradX(N)

GradY from image N will contain the sobely from image1. So, we can called it GradY(N)

At the end we have N*2 Memory Buffers containing the sobel (Gx and Gy) from all the N images.

b) After it calculate the sobelx and y on all images it then take their median to export on only 2 new buffers (Wm_x and Wm_y), as below:

` # Compute median of grads`

print("Computing median gradients.")

Wm_x = np.median(np.array(gradx), axis=0)

Wm_y = np.median(np.array(grady), axis=0)

So, this function it is not creating the G on each image, but calculating the median of Gx and Gy from all images to later compute the resultant G from those values as below.

the median calculated from here is at each given position on all N images from where Gradx and GradY were created.

So:

At pos (x = 0, Y = 0), it will get the SobelX and SobelY from images 1 to N and calculate their median and then put the resultant 2 (Gx and Gy) values on Wm_x and Wm_y at the same pos (x = 0, y = 0)

At pos (x = 1, Y = 0), it will get the SobelX and SobelY from images 1 to N and calculate their median and then put the resultant 2 (Gx and Gy) values on Wm_x and Wm_y at the same pos (x = 1, y = 0)

and keep doing it untill all Coordinates were calculated.

2 - Call the function

**crop_watermark**This function will calculate the median G value from the previously created Wm_x and Wm_y

` W_mod = np.sqrt(np.square(gradx) + np.square(grady))`

From this part it is taking the 2 memory buffers created to store the median Gx and Gy to calculate the G from only those 2 memory buffers that will be saved in

**W_mod**So, what is the strategy ? Use your new FastMedianFP to compute median on what ? I really got a bit lost right now.