Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(28)

Unified Diff: files/source/Metric.cpp

Issue 89059: add ignore edge function in pdiff. SVN Base: http://o3d.googlecode.com/svn/trunk/googleclient/third_party/pdiff/
Patch Set: '' Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: files/source/Metric.cpp
===================================================================
--- files/source/Metric.cpp (revision 87)
+++ files/source/Metric.cpp (working copy)
@@ -122,6 +122,48 @@
B = 200.0f * (f[1] - f[2]);
}
+
+// simple convolution based edge detection with a 3-by-3 size kernel.
+// edgeImg is the result, pixel is either 255 which means an edge point
+// or 0 means it is not edge, based on whether the result
+// of convolution is larger than pre-defiend threshold or not.
+void DetectEdge(RGBAImage* diffImg, int* edgeImg, unsigned int w,
+ unsigned int h, int edgeNeighborNum) {
+ // define the kernel for convolution.
+ int kernelLength = 3;
+ int kernel[9] = {-1, -1, -1, -1, 8, -1, -1, -1, -1};
+ unsigned int x = 0, y = 0;
+ int cx = 0, cy = 0;
+
+ // threshold based on edgeNeighborNum
+ // edgeNeighborNum is the max number of neighbors
+ // a pixel could have to be considered as
+ // edges.
+ int threshold = (8 - edgeNeighborNum) * 255;
+
+ // shrink the image by 1 pixel to avoid checking boundaries.
+ for (y = 1; y < h - 1; y++) {
+ for (x = 1; x < w - 1; x++) {
+ int index = y * w + x;
+ edgeImg[index] = 0;
+ for (cx = -1; cx <=1; cx++) {
+ for (cy = -1; cy <= 1; cy++) {
+ int nx = x + cx;
+ int ny = y + cy;
+ edgeImg[index] +=
+ diffImg->Get_Red(ny * w + nx) *
+ kernel[(cy + 1) * kernelLength + cx + 1];
+ }
+ }
+
+ if (edgeImg[index] >= threshold)
+ edgeImg[index] = 255;
+ else
+ edgeImg[index] = 0;
+ }
+ }
+}
+
bool Yee_Compare(CompareArgs &args)
{
if ((args.ImgA->Get_Width() != args.ImgB->Get_Width()) ||
@@ -290,22 +332,48 @@
if (aB) delete aB;
if (bB) delete bB;
+ if (args.IgnoreEdge)
+ {
+ int* edgeImg = new int[w * h];
+
+ // run convolution based edge detection algorithm.
+ DetectEdge(args.ImgDiff, edgeImg, w, h, args.EdgeNeighborNum);
+
+ // delete edge pixels from the result image.
+ for (y = 1; y < h - 1; y++) {
+ for (x = 1; x < w - 1; x++) {
+ unsigned int index = y * w + x;
+ if (args.ImgDiff->Get_Red(index) == 255 &&
+ edgeImg[index] == 255) {
+ args.ImgDiff->Set(0, 0, 0, 255, index);
+ pixels_failed--;
+ }
+ }
+ }
+
+ delete[] edgeImg;
+ }
+
char different[100];
sprintf(different, "%d pixels are different\n", pixels_failed);
// Always output image difference if requested.
- if (args.ImgDiff) {
- if (args.ImgDiff->WriteToFile(args.ImgDiff->Get_Name().c_str())) {
- args.ErrorStr += "Wrote difference image to ";
- args.ErrorStr+= args.ImgDiff->Get_Name();
- args.ErrorStr += "\n";
- } else {
- args.ErrorStr += "Could not write difference image to ";
- args.ErrorStr+= args.ImgDiff->Get_Name();
- args.ErrorStr += "\n";
+ if (args.ImgDiff)
+ {
vangelis 2009/07/09 02:43:29 seems to be some extra whitespace after the { . Pl
+ if (args.ImgDiff->Get_Name().size() > 0) {
+ if (args.ImgDiff->WriteToFile(
+ args.ImgDiff->Get_Name().c_str())) {
+ args.ErrorStr += "Wrote difference image to ";
+ args.ErrorStr+= args.ImgDiff->Get_Name();
+ args.ErrorStr += "\n";
+ } else {
+ args.ErrorStr +=
+ "Could not write difference image to ";
+ args.ErrorStr+= args.ImgDiff->Get_Name();
+ args.ErrorStr += "\n";
+ }
}
}
-
if (pixels_failed < args.ThresholdPixels) {
args.ErrorStr = "Images are perceptually indistinguishable\n";
args.ErrorStr += different;
« files/source/CompareArgs.h ('k') | no next file »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497