Exemple #1
0
func TestHOG_boundary(t *testing.T) {
	const (
		sbin  = 4
		frac  = 3
		fname = "000084.jpg"
	)
	// Load image.
	file, err := os.Open(fname)
	if err != nil {
		t.Fatal(err)
	}
	im, _, err := image.Decode(file)

	// Take top-left part which is divisible by sbin and frac.
	im = ensureDivis(im, sbin*frac)
	// Make a rectangle of the top-left part of the image.
	// Not the most top-left window but the second-most.
	size := im.Bounds().Size()
	rect := image.Rectangle{size.Div(frac), size.Div(frac).Mul(2)}

	// Sub-sample image
	subim := image.NewRGBA(image.Rectangle{image.ZP, rect.Size()})
	draw.Draw(subim, subim.Bounds(), im, rect.Min, draw.Src)

	// Convert to real values.
	f := HOG(rimg64.FromColor(im), FGMRConfig(sbin))
	g := HOG(rimg64.FromColor(subim), FGMRConfig(sbin))

	// Take rectangle in f of same size as g.
	min := rect.Min.Div(sbin)
	subf := f.SubImage(image.Rectangle{min, min.Add(g.Size())})

	const prec = 1e-9
	// Skip last element because of a slight difference.
	// (Not using cell outside image.)
	for x := 0; x < g.Width; x++ {
		for y := 0; y < g.Height; y++ {
			for d := 0; d < g.Channels; d++ {
				want := g.At(x, y, d)
				got := subf.At(x, y, d)
				if math.Abs(want-got) > prec {
					t.Errorf("wrong value: at %d, %d, %d: want %g, got %g", x, y, d, want, got)
				}
			}
		}
	}
}
Exemple #2
0
func loadRealImage(file string) (*rimg64.Multi, error) {
	im, err := loadImage(file)
	if err != nil {
		return nil, err
	}
	f := rimg64.FromColor(im)
	return f, nil
}
Exemple #3
0
func loadFeatImage(fname string, sbin int) (*rimg64.Multi, error) {
	file, err := os.Open(fname)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	im, _, err := image.Decode(file)
	if err != nil {
		return nil, err
	}
	return hog.HOG(rimg64.FromColor(im), hog.FGMRConfig(sbin)), nil
}
Exemple #4
0
func TestHOG_VersusFGMR(t *testing.T) {
	const (
		sbin  = 8
		fname = "000084.jpg"
	)

	// Load image.
	file, err := os.Open(fname)
	if err != nil {
		t.Fatal(err)
	}
	im, _, err := image.Decode(file)
	if err != nil {
		t.Fatal(err)
	}

	// Remove outside pixel before running C code.
	rect := im.Bounds().Inset(1).Inset(sbin / 2)
	inside := image.NewRGBA(image.Rectangle{image.ZP, rect.Size()})
	draw.Draw(inside, inside.Bounds(), im, rect.Min, draw.Src)
	// Compute transforms.
	ref := fgmr(rimg64.FromColor(inside), sbin)
	f := HOG(rimg64.FromColor(im), FGMRConfig(sbin))

	const prec = 1e-5
	// Skip first and last element. (Not using cell outside image.)
	for x := 1; x < f.Width-1; x++ {
		for y := 1; y < f.Height-1; y++ {
			for d := 0; d < f.Channels; d++ {
				want := ref.At(x, y, d)
				got := f.At(x, y, d)
				if math.Abs(want-got) > prec {
					t.Errorf("wrong value at (%d, %d, %d): want %g, got %g", x, y, d, want, got)
				}
			}
		}
	}
}
Exemple #5
0
func BenchmarkC(b *testing.B) {
	const (
		sbin  = 8
		fname = "000084.jpg"
	)

	// Load image.
	file, err := os.Open(fname)
	if err != nil {
		b.Fatal(err)
	}
	im, _, err := image.Decode(file)
	if err != nil {
		b.Fatal(err)
	}

	f := rimg64.FromColor(im)
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		fgmr(f, sbin)
	}
}
Exemple #6
0
func (phi *RGB) Apply(im image.Image) (*rimg64.Multi, error) {
	return rimg64.FromColor(im), nil
}
Exemple #7
0
func (phi *OfRGB) Apply(im image.Image) (*rimg64.Multi, error) {
	return phi.Real.Apply(rimg64.FromColor(im))
}
Exemple #8
0
func (t Transform) Apply(im image.Image) (*rimg64.Multi, error) {
	return HOG(rimg64.FromColor(im), t.Conf), nil
}