1 / 17

Notes on Pattern Period Algorithm

Notes on Pattern Period Algorithm. Measuring the Pattern Period. 1. Select pattern region (should be apx the size of the width of the contour) 2. Copy bitmap of this region 3. Invert color (shade). Inverse Template Moves Along Skeleton. 1. Select pattern region (should be apx

debrar
Download Presentation

Notes on Pattern Period Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Notes on Pattern Period Algorithm

  2. Measuring the Pattern Period 1. Select pattern region (should be apx the size of the width of the contour) 2. Copy bitmap of this region 3. Invert color (shade)

  3. Inverse Template Moves Along Skeleton 1. Select pattern region (should be apx the size of the width of the contour) 2. Copy bitmap of this region 3. Invert color (shade) 4. Set transparency to 50% 5. Return to original location

  4. Variance of (Inverse Template + Image) vs Position 1. Select pattern region (should be apx the size of the width of the contour) 2. Copy bitmap of this region 3. Invert color (shade) 4. Set transparency to 50% 5. Return to original location 6. Move along skeleton 7. Record variance in template region

  5. Distance Between Peaks in Variance Array is Pattern Period 1. Select pattern region (should be apx the size of the width of the contour) 2. Copy bitmap of this region 3. Invert color (shade) 4. Set transparency to 50% 5. Return to original location 6. Move along skeleton 7. Record Sum of differences 8. Compute period of pattern using separation of peaks.

  6. 2500 2000 1500 Variance 1000 500 0 0 5 10 15 20 25 30 35 40 45 Shift Count Sample Run on Wheat Head inverse template window pat_match(image[0],278,165,289,208,6); path of motion starting position ending position Starting and ending positions are obtained from object skeleton window half-width

  7. Function to Determine the Pattern Period double pat_match(BITMAP *img, int xs, int ys, int xf, int yf, int del) { char ch; int mat[2*del+1][2*del+1]; double temp[2*del+1][2*del+1]; int z; int pix; int npat = 1+(int)fmax(fabs(xf-xs),fabs(yf-ys)); int ipat = 0; double pat[npat]; double avg; double var; double prod; double count; bool startcount; bool movingup; double period; double pcount; double ncyc; for(int i=0;i<npat;i++) pat[i] = 0.0; for(int i=-del;i<=del;i++)// builds the inverse template for(int j=-del;j<=del;j++) { pix = getpixel(img,xs+i,ys+j); mat[i+del][j+del] = 255 - (int)getb(pix); }

  8. if(fabs(xs-xf)>fabs(ys-yf))// if slope is more horizontal than vertical { for(int i=xs;i<=xf;i++) { z = ys + (yf-ys)*(i-xs)/(int)fabs(xs-xf); avg = 0.0; var = 0.0; count = 0.0; for(int p=-del;p<=del;p++)// template data generation for(int q=-del;q<=del;q++) { temp[p+del][q+del] = (double)mat[p+del][q+del] + (double)getb(getpixel(img,i+p,z+q)); avg += temp[p+del][q+del]; count += 1.0; } avg = avg/count;// compute mean for(int p=-del;p<del;p++)// compute variance for(int q=-del;q<del;q++) { prod = temp[p+del][q+del]-avg; var += prod*prod; } pat[ipat] += var/count;// array is loaded with variance values ipat += 1; } }

  9. else// slope is more vertical than horizontal { for(int i=ys;i<yf;i++) { z = xs + (xf-xs)*(i-ys)/(int)fabs(ys-yf); avg = 0.0; var = 0.0; count = 0.0; for(int p=-del;p<=del;p++)// template data generation for(int q=-del;q<=del;q++) { temp[p+del][q+del] = (double)mat[p+del][q+del] + (double)getb(getpixel(img,z+p,i+q)); avg += temp[p+del][q+del]; count += 1.0; } avg = avg/count;// compute mean for(int p=-del;p<del;p++)// compute variance for(int q=-del;q<del;q++) { prod = temp[p+del][q+del]-avg; var += prod*prod; } pat[ipat] += var/count;// array is loaded with variance values ipat += 1; } }

  10. startcount = false;movingup = false; period = 0.0;pcount = 0.0; ncyc = 0.0; for(int i=1; i<npat; i++)// counts period length maxima-to-maxima { if(startcount) { pcount += 1.0; if(movingup) { if(pat[i]<pat[i-1])// turning down so next maxima reached { period += pcount;// save this period and inc num cycles ncyc += 1.0; movingup = false;// reset to begin next period count pcount = 0.0; } } else { if(pat[i]>pat[i-1])// reached bottom during period count movingup = true;// starting back up toward a maxima } } else { if(pat[i]<pat[i-1])//don't start counting until at a maxima startcount = true; } } period = period/ncyc;// returns average period return period; }

  11. 2500 2000 1500 Variance 1000 500 0 0 5 10 15 20 25 30 35 40 45 Shift Count In-Line Scan On Pattern

  12. 1600 1400 1200 1000 Variance 800 600 400 200 0 0 5 10 15 20 25 30 35 40 45 Shift Count In-Line Scan Near Pattern shifted by 3 pixels to the left, scan-line angle off by two pixels local minima (noted) corrupt average period computation (1) attempt to ignore outliers - small number of samples preclude this (2) perform fourier analysis - computationally intensive (3) filter (smooth) data - can shift peaks (but period relatively unaffected)

  13. 1600 1400 1200 1000 Variance 800 600 400 200 0 0 5 10 15 20 25 30 35 40 45 Shift Count Out-of-Line Scan scan-line off by 4 pixels over a run of 40 pixels clearly error in the scan line has a severe effect on pattern matching

  14. Finite Impulse Response (FIR) Filter running average version for(int m=0;m<2;m++) { smooth = (pat[0] + pat[1] + pat[2])/3.0; pat[1] = smooth; for(int i=2;i<npat-1;i++) { smooth += -pat[i-2]/3.0 + pat[i+1]/3.0; pat[i] = smooth; } pat[npat-1] = smooth - pat[npat-3]/3.0 + pat[npat-1]/3.0; } . . . . . . there are special cases for endpoints

  15. 2500 2000 Variance 1500 1000 500 Shift Count 0 0 5 10 15 20 25 30 35 40 45 In-Line Scan On Pattern with FIR Filter measured period increases by < 0.5 pixels 10.667 goes to 11.0 pixels

  16. 1600 1400 Variance 1200 1000 800 600 400 200 Shift Count 0 0 5 10 15 20 25 30 35 40 45 In-Line Scan Near Pattern with FIR filter small local minima eliminated

  17. 1400 1200 Variance 1000 800 600 400 200 Shift Count 0 0 5 10 15 20 25 30 35 40 45 Out-of-Line Scan with FIR Filter FIR Filter captures major peaks in out-of-line scann

More Related