Effective algorithm for finding 16x16 pixel same squares in a big image - C# -


i coding software @ visual studio 2010 using c#. software finding same squares @ image after square selected. every square composed 16x16 pixel. current algorithm starts first pixel , scan entire image pixel pixel comparing determine same pixel squares selected one. takes big time. can suggest me better way ?

also every square ordered. start 0 - 16 - 32 - 48

a square can not start 5 or 65 etc

thank you

you cache checksum of each image-region. have check ones match checksum equality.

let's assume each image 16x16 rgb elements. (and yes, have integer overflow.)

all of in pseudo code - you're expected able translate c#.

add int field image class, or create image wrapper int 'checksum'

int checksum = 0 each pixel in image {    checksum += pixel.red + pixel.blue + pixel.green    // wanted here,    // checksum *= 17 + pixel.red    // checksum *= 17 + pixel.blue    // checksum *= 17 + pixel.green    // make "unique enough", hashcode } image.checksum = checksum 

now when go search can go this:

/**  * equals method before:   */ boolean equals(image a, image b) {   x = 0..15 /* 16 pixels in x */     y = 0..15 /* 16 pixels in y */       if a.getpixel(x,y) != b.getpixel(x,y) return false;   return true; }  /**  * equals method after:   *. boolean equals(image a, image b) {   /* check lets skip loop in cases */   /* still have verify image equal pixel pixel though */   if a.checksum != b.checksum return false;   x = 0..15 /* 16 pixels in x */     y = 0..15 /* 16 pixels in y */       if a.getpixel(x,y) != b.getpixel(x,y) return false;   return true; } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -