1 / 10

Edge Detection 解题报告

Edge Detection 解题报告. 计算机科学技术系 赵静 09908114 zhaojing@db.pku.edu.cn. 题型:模拟类. 85. 85. 85. 85. 85. 0. 0. 85. 85. 85. 85. 85. 75. 75. Input Image. Output Image. 关键点:时空限制. 空间限制: sizeof (char) * 1000000000 = 1GB 逐个计算 只保留当前像素及周围像素的值 随时输出计算结果 时间限制 尽量避免重复计算. 数据结构. 输入数据

Download Presentation

Edge Detection 解题报告

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. Edge Detection 解题报告 计算机科学技术系 赵静 09908114 zhaojing@db.pku.edu.cn

  2. 题型:模拟类 85 85 85 85 85 0 0 85 85 85 85 85 75 75 Input Image Output Image

  3. 关键点:时空限制 • 空间限制:sizeof (char) * 1000000000 = 1GB • 逐个计算 • 只保留当前像素及周围像素的值 • 随时输出计算结果 • 时间限制 • 尽量避免重复计算

  4. 数据结构 • 输入数据 • long imageWidth; • int pixVal[MAXRUNS + 2]; // pixel values in runs • long runLength[MAXRUNS + 2]; // runs • int lastRunIndex; • 用于计算的关键数据结构 • int runIndex[3]; // index of run containing pixel • long leftInRun[3]; // number of further pixels in the run • long column; // column of pixel in center of filter, 0 to imageWidth - 1

  5. runIndex[0]=1 runIndex[1]=2 runIndex[2]=2 leftInRun[0]=2 leftInRun[1]=10 leftInRun[2]=3 数据结构图示 runLength pixVal

  6. 算法(1):计算单一目的像素值 int edgeFilter() { int mid = pixVal[runIndex[1]]; // pixel value in mid row int max = 0; for (int r = 0; r < 3; r++) // for each row used in the filter if (runIndex[r] > 0 && runIndex[r] <= lastRunIndex) { // skip dummy rows max = updateMax(runIndex[r], mid, max); if (column > 0 && leftInRun[r] == runLength[runIndex[r]] - 1) max = updateMax(runIndex[r]-1, mid, max); if (column < imageWidth -1 && leftInRun[r] == 0) max = updateMax(runIndex[r]+1, mid, max); } return max; }

  7. 算法(2):减少重复计算的策略 leftInRun[0]=2 leftInRun[1]=10 long minRun() { long minAfter = 2000000000; for (int r = 0; r < 3; r++) { if (leftInRun[r] == runLength[runIndex[r]] - 1) return 1; if (minAfter > leftInRun[r]) minAfter = leftInRun[r]; } if (minAfter == 0) return 1; return minAfter; } leftInRun[2]=3 minAfter=2

  8. 算法(3):整体流程 outBufferPixVal = edgeFilter(); outBufferRun = minRun(); advance(outBufferRun); // skip past all the pixels calculated while (runIndex[1] <= lastRunIndex) { outPixVal = edgeFilter(); outRun = minRun(); advance(outRun); if (outPixVal == outBufferPixVal) // combine runs with equal values outBufferRun += outRun; else // output old runLength, save new one { cout << outBufferPixVal << " " << outBufferRun << endl; outBufferPixVal = outPixVal; outBufferRun = outRun; } }

  9. 值得注意的细节:起始状态 runLength[0] = 2*imageWidth; // add initial border runLength[lastRunIndex--] = 2*imageWidth; // add end border for (int r = 0; r < 3; r++) { runIndex[r] = 0; // dummy run index before actual image leftInRun[r] = (3-r)*imageWidth - 1; // pixels -3,-2,-1 rows into image } advance(2*imageWidth); // +2 rows to first pixels -1,0,1 rows into image runIndex[0]=0 leftInRun[0]=6 runIndex[1]=1 leftInRun[1]=3 runIndex[2]=2 leftInRun[2]=14

  10. The End Thank you for your attention!

More Related