acbbafbf76e8 — Sean Russell 11 years ago
Bug fixes.
4 files changed, 23 insertions(+), 19 deletions(-)

M compareargs.go
M lpyramid.go
M metric.go
M perceptualdiff/main.go
M compareargs.go +0 -8
@@ 1,7 1,6 @@ 
 package perceptualdiff
 
 import (
-	"flag"
 	"fmt"
 )
 

          
@@ 23,13 22,6 @@ this programif not, write to the Free So
 Place, Suite 330, Boston, MA 02111-1307 USA
 */
 
-const copyright = `PerceptualDiff version 1.1.1, Copyright (C) 2006 Yangli Hector Yee
-PerceptualDiff comes with ABSOLUTELY NO WARRANTY
-This is free software, and you are welcome
-to redistribute it under certain conditions
-See the GPL page for details: http://www.gnu.org/copyleft/gpl.html
-
-`
 
 // Args to pass into the comparison function
 type CompareArgs struct {

          
M lpyramid.go +1 -2
@@ 42,11 42,10 @@ func NewLPyramid(image []float64, width,
 	// Make the Laplacian pyramid by successively
 	// copying the earlier levels and blurring them
 	for i:=0; i<MAX_PYR_LEVELS; i++ {
+		rv.Levels[i] = make([]float64, width * height)
 		if i == 0 {
-			rv.Levels[i] = make([]float64, width, height)
 			copy(rv.Levels[i], image)
 		} else {
-			rv.Levels[i] = make([]float64, width * height)
 			rv.convolve(rv.Levels[i], rv.Levels[i - 1])
 		}
 	}

          
M metric.go +9 -6
@@ 179,21 179,24 @@ func Yee_Compare(args *CompareArgs) bool
 	xyz := NewXYZ()
 	for y = 0; y < h; y++ {
 		for x = 0; x < w; x++ {
+			i := x + y * w
+			var r, g, b float64
+
 			ra, ga, ba, _ := args.ImgA.At(x, y).RGBA()
 			// l is never actually used, AFAICT.  Bug in original algo?
-			var r, g, b float64
-			i := x + y * w
 			r = Pow(float64(ra) / 255.0, args.Gamma)
 			g = Pow(float64(ga) / 255.0, args.Gamma)
 			b = Pow(float64(ba) / 255.0, args.Gamma)
 			aX[i], aY[i], aZ[i] = AdobeRGBToXYZ(r,g,b)
 			_, aA[i], aB[i] = xyz.XYZToLAB(aX[i], aY[i], aZ[i])
-			rb, gb, bb, _ := args.ImgA.At(x, y).RGBA()
+
+			rb, gb, bb, _ := args.ImgB.At(x, y).RGBA()
 			r = Pow(float64(rb) / 255.0, args.Gamma)
 			g = Pow(float64(gb) / 255.0, args.Gamma)
 			b = Pow(float64(bb) / 255.0, args.Gamma)
 			bX[i],bY[i],bZ[i] = AdobeRGBToXYZ(r,g,b)
 			_, bA[i], bB[i] = xyz.XYZToLAB(bX[i], bY[i], bZ[i])
+
 			aLum[i] = aY[i] * args.Luminance
 			bLum[i] = bY[i] * args.Luminance
 		}

          
@@ 203,8 206,8 @@ func Yee_Compare(args *CompareArgs) bool
 		fmt.Printf("Constructing Laplacian Pyramids\n")
 	}
 
-	la := LPyramid{[][]float64{aLum}, w, h}
-	lb := LPyramid{[][]float64{bLum}, w, h}
+	la := NewLPyramid(aLum, w, h)
+	lb := NewLPyramid(bLum, w, h)
 
 	num_one_degree_pixels := (2.0 * Tan(args.FieldOfView * 0.5 * Pi / 180.0) * 180.0 / Pi)
 	pixels_per_degree := float64(w) / num_one_degree_pixels

          
@@ 303,7 306,7 @@ func Yee_Compare(args *CompareArgs) bool
 	  }
   }
 
-	different := fmt.Sprintf("%d pixels are different\n", pixels_failed)
+	different := fmt.Sprintf("%d pixels are different", pixels_failed)
 
   // Always output image difference if requested.
   if args.ImgDiff != nil {

          
M perceptualdiff/main.go +13 -3
@@ 22,10 22,20 @@ Place, Suite 330, Boston, MA 02111-1307 
 */
 
 import (
-	"perceptualdiff"
+	"flag"
+	"fmt"
 	"os"
+	"perceptualdiff"
 )
 
+const copyright = `PerceptualDiff version 1.1.1, Copyright (C) 2006 Yangli Hector Yee
+PerceptualDiff comes with ABSOLUTELY NO WARRANTY
+This is free software, and you are welcome
+to redistribute it under certain conditions
+See the GPL page for details: http://www.gnu.org/copyleft/gpl.html
+
+`
+
 func main() {
 	args := perceptualdiff.NewCompareArgs()
 

          
@@ 43,7 53,7 @@ func main() {
 }
 
 
-func parse_Args(c *CompareArgs) bool {
+func parse_Args(c *perceptualdiff.CompareArgs) bool {
 	flag.BoolVar(&c.Verbose, "verbose", false, "Turns on verbose mode")
 	flag.Float64Var(&c.FieldOfView, "fov", 45.0, "Field of view in degrees (0.1 to 89.9)")
 	flag.UintVar(&c.ThresholdPixels, "threshold", 100, "#pixels p below which differences are ignored")

          
@@ 82,7 92,7 @@ func parse_Args(c *CompareArgs) bool {
 	}
 
 	if *output_file_name != "" {
-		c.ImgDiff = NewRGBAImage(c.ImgA.Bounds().Dx(), c.ImgA.Bounds().Dy(), *output_file_name)
+		c.ImgDiff = perceptualdiff.NewRGBAImage(c.ImgA.Bounds().Dx(), c.ImgA.Bounds().Dy(), *output_file_name)
 	}
 	return true
 }