C # Scan image for specific block

I have an image:

size 1000x1000 white with random black dots. (It may contain a black square (size 50x50))

Is there an easy way to find out if an image contains a black square (size 50x50)? I was thinking about scanning each pixel of the image, and if a black pixel was found, scan it next to it until I get a 50x50 square or until I get a white pixel and start scanning. but he will have to scan more than a million pixels (if he did not find the square).

This is basically code (you don’t need to fill it, as I said, it will take too much time to scan it), a million times if the entire image is white and much larger in accordance with the number of black pixels.)

        for (int i = 0; i < pic.Width; i++)
        {
            for (int j = 0; j < pic.Height; j++)
            {
                if (pic.GetPixel(i, j) == Color.Black)
                {
                    //Search for the entire square at that area
                }
            }
        }

, ( ). ?

+5
3

Boyer-Moore, , , , , , . , . , 50 . , .

. , , GetPixel , . 2D-, , , , .

, System.Drawing.Bitmap, LockBits, , 1D- .

+5

, , 50- ( ) , .

, - 1 50x50. , , , : , , . 1/2500- , , 400 .

, , , . .

+2

All Articles