I have an image with the size `5575x9440` and I'm implementing a modified version of the algorithm used in this paper on it, but because the code performance is low right now, I have divided the image to `52628` submatrices of the size `25x40 (1000 pixels)` and my first experiments show that some lines of code that are marked in the following picture as yellow are not needed at all (meaning that the 2 and 3 degree polynomials always have at least one real positive root) and so there's no need to check it. (Deleting these ten lines will make the code 3rd times faster and I have other plans to accelerate the code further)

Because the code is slow right now, I cannot experiment all of these `52628` matrices and I have to choose a sample size and choose some random matrices to try. But how to calculate the sample size?

I have posted a summary of what I have tried so far here in this question and I really need your help?