C# Scanning an image for a certain block -


i have picture:

size of 1000x1000 white random black dots. (it may contain black square (size 50x50))

is there easy way know if picture contains black square (size 50x50)? thought of scanning every pixel of picture , if black pixel found, scan 1 next him till 50x50 square or till white pixel , keep scanning. have scan on million pixel (if hasn't found square).

thats code (no need complete it, said before, take way time scan it. million times if whole picture white , lot more according number of black pixels.)

        (int = 0; < pic.width; i++)         {             (int j = 0; j < pic.height; j++)             {                 if (pic.getpixel(i, j) == color.black)                 {                     //search entire square @ area                 }             }         } 

and yes, time important (thats why don't want pixel on million times). ideas?

like boyer-moore string searching algorithm, if item looking @ not part of looking for, can skip whole size of looking for. in case, can check see if given pixel black. if it's not, can skip forward 50 pixels. if is, have small box black square in.

in case, though, may not need complicated. i'm guessing if algorithm slow it's because you're calling getpixel function million times, , that slow part. if can pixels 2d array, algorithm go fast enough not need rewritten.

assuming you're using system.drawing.bitmap check out lockbits documentation see small sample includes copying bitmap 1d array super-fast access.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -