func ToVector(filename string) eigenface.FaceVector {
	im := readImage(filename)

	face := eigenface.FaceVector{
		Width:  im.Bounds().Max.X - im.Bounds().Min.X,
		Height: im.Bounds().Max.Y - im.Bounds().Min.Y,
	}
	face.Pixels = make([]float64, face.Width*face.Height)
	minX := im.Bounds().Min.X
	minY := im.Bounds().Min.Y

	// iterate through image row by row
	for y := 0; y < face.Height; y++ {
		for x := 0; x < face.Width; x++ {
			color := im.At(x-minX, y-minY)
			// ORL database images are 16-bit grayscale, so can use any of RGB values
			value, _, _, _ := color.RGBA()
			face.Pixels[(y*face.Width)+x] = float64(value)
		}
	}
	return face
}
예제 #2
0
파일: main.go 프로젝트: riginding/lime
func (t *qmlfrontend) DefaultFg() color.RGBA {
	c := scheme.Spice(&render.ViewRegions{})
	c.Foreground.A = 0xff
	return color.RGBA(c.Foreground)
}
예제 #3
0
파일: main.go 프로젝트: uni3orns/lime
func (t *tbfe) DefaultBg() color.RGBA {
	c := scheme.Spice(&render.ViewRegions{})
	c.Background.A = 0xff
	return color.RGBA(c.Background)
}
예제 #4
0
func MakeBamFromGif(animation *gif.GIF, sequences []image.Point) (*BAM, error) {
	maxHeight, maxWidth := 0, 0

	for _, img := range animation.Image {
		if img.Bounds().Dy() > maxHeight {
			maxHeight = img.Bounds().Dy()
		}
		if img.Bounds().Dx() > maxWidth {
			maxWidth = img.Bounds().Dx()
		}
	}

	bam := &BAM{Width: maxWidth, Height: maxHeight}
	bam.Frames = make([]BamFrame, len(animation.Image))
	bam.Sequences = make([]BamSequence, len(sequences))
	bam.Image = make([]image.Paletted, len(animation.Image))

	bam.Palette = make([]color.Color, 256)
	currentPaletteEntry := 1
	bam.Palette[0] = color.RGBA{0, 255, 0, 255}

	for idx, img := range animation.Image {
		bam.Frames[idx].Width = uint16(img.Bounds().Dx())
		bam.Frames[idx].Height = uint16(img.Bounds().Dy())
		bam.Frames[idx].CenterX = int16(img.Bounds().Min.X)
		bam.Frames[idx].CenterY = int16(img.Bounds().Min.Y)
		for _, color := range img.Palette {
			if !ColorInPalette(color, bam.Palette) {
				_, _, _, a := color.RGBA()
				if currentPaletteEntry < 256 {
					if a == 0xffff {
						bam.Palette[currentPaletteEntry] = color
						currentPaletteEntry++
					}
				} else {
					log.Printf("WARNING: palette overflow, unable to place %v %d", color, currentPaletteEntry)
				}
			}
		}
	}
	for i := currentPaletteEntry; i < len(bam.Palette); i++ {
		bam.Palette[i] = color.RGBA{0, 0, 0, 0}
	}
	for idx, img := range animation.Image {
		b := img.Bounds()
		rect := image.Rectangle{b.Min, b.Max}
		bam.Image[idx] = *image.NewPaletted(rect, bam.Palette)
		for y := b.Min.Y; y < b.Max.Y; y++ {
			for x := b.Min.X; x < b.Max.X; x++ {
				col := img.At(x, y)
				_, _, _, a := col.RGBA()
				// convert transparent gif pixels to our transparent pixel
				if a == 0 {
					col = bam.Palette[0]
				}
				bam.Image[idx].Set(x, y, bam.Palette.Convert(col))
			}
		}

	}

	for idx, seq := range sequences {
		bam.Sequences[idx].Start = seq.X
		bam.Sequences[idx].Count = seq.Y
		startFrame := seq.X
		for i := seq.X; i < seq.X+seq.Y; i++ {
			bam.SequenceToImage = append(bam.SequenceToImage, int16(startFrame))
			startFrame++
		}
	}

	return bam, nil
}
예제 #5
0
파일: main.go 프로젝트: nicecai/lime
func (t *tbfe) DefaultBg() color.RGBA {
	c := scheme.Spice(&render.ViewRegions{})
	log4go.Debug("##############################\nHERE! %s\n###################", c)
	c.Background.A = 0xff
	return color.RGBA(c.Background)
}
예제 #6
0
func (f *frontend) DefaultFg() color.RGBA {
	c := f.colorScheme().Spice(&render.ViewRegions{})
	c.Foreground.A = 0xff
	return color.RGBA(c.Foreground)
}
예제 #7
0
파일: main.go 프로젝트: richardfontana/lime
func newQLimeView(v *backend.View) *QLimeView {
	log4go.Debug("new_QLimeView entered")
	defer log4go.Debug("new_QLimeView exited")
	var ret QLimeView
	ret.Widget = qt5.NewWidget()
	ret.v = v
	ret.Widget.OnPaintEvent(func(ev *qt5.PaintEvent) {
		p := qt5.NewPainter()
		defer p.Close()
		p.Begin(ret)
		b := v.Buffer()
		ps := p.Font().PointSize()

		pen := qt5.NewPen()
		p.SetPen(pen)
		brush := qt5.NewBrush()
		brush.SetStyle(qt5.SolidPattern)
		def := scheme.Settings[0]
		p.SetBrush(brush)
		f := p.Font()
		f.SetFixedPitch(true)
		p.SetFont(f)

		brush.SetColor(color.RGBA(def.Settings["background"]))
		p.DrawRect(ev.Rect())
		is_widget, ok := v.Settings().Get("is_widget", false).(bool)
		is_widget = ok && is_widget
		pen.SetColor(color.RGBA(def.Settings["background"]))
		p.SetPen(pen)

		for y := 0; y < 20; y++ {
			pos := b.TextPoint(y, 0)
			line := b.Line(pos)

			if is_widget {
				p.DrawText(qt5.Point{0, (y + 1) * (ps + 2)}, b.Substr(line))
			} else {
				for line.Contains(pos) {
					scope := primitives.Region{pos, pos}
					sn := v.ScopeName(pos)
					for line.Contains(pos) {
						pos++
						if v.ScopeName(pos) != sn {
							scope.B = pos
							break
						}
					}
					is := line.Intersection(scope)
					c := color.RGBA(def.Settings["foreground"])
					s := scheme.ClosestMatchingSetting(sn)
					if v, ok := s.Settings["foreground"]; ok {
						c = color.RGBA(v)
					}
					pen.SetColor(c)
					p.SetPen(pen)
					_, col := b.RowCol(line.A)
					p.DrawText(qt5.Point{col * ps / 2, (y + 1) * (ps + 2)}, b.Substr(is))
					line.A = is.End()
				}
			}
		}
	})
	ret.Widget.OnResizeEvent(func(ev *qt5.ResizeEvent) {
		if w, ok := v.Settings().Get("is_widget", false).(bool); ok && !w {
			ret.Widget.SetMinimumSize(qt5.Size{600, 100})
		}
	})
	v.Settings().Set("lime.qt.widget", &ret)
	return &ret
}
예제 #8
0
func Histogram(img image.Image, rect image.Rectangle) ([]int, string) {
	var hist []int
	var pix []uint8
	var colormodel string
	var bounds image.Rectangle
	stride := 0
	n := 0
	switch img := img.(type) {
	case *image.RGBA:
		colormodel = "rgba"
		img = img.SubImage(rect).(*image.RGBA)
		pix = img.Pix
		n = 4
		stride = img.Stride
		bounds = img.Bounds()
	case *image.NRGBA:
		colormodel = "rgba"
		img = img.SubImage(rect).(*image.NRGBA)
		pix = img.Pix
		n = 4
		stride = img.Stride
		bounds = img.Bounds()
	// case *image.RGBA64: -- 16-bit values
	case *image.Gray:
		colormodel = "gray"
		img = img.SubImage(rect).(*image.Gray)
		pix = img.Pix
		n = 1
		stride = img.Stride
		bounds = img.Bounds()
	// case *image.Gray16: -- 16-bit values
	case *image.YCbCr:
		colormodel = "ycbcr"
		hist = HistogramYCbCr(img, rect, false)
		if hist != nil {
			return hist, colormodel
		}
	default:
		colormodel = "other"
	}
	if n > 0 {
		hist = make([]int, n*256)
		for y, o := bounds.Min.Y, 0; y < bounds.Max.Y; y, o = y+1, o+stride {
			for x := 0; x < n*bounds.Dx(); x += n {
				for i := 0; i < n; i++ {
					hist[int(pix[o+x+i])+i*256] += 1
				}
			}
		}
	} else {
		colormodel = "rgb"
		hist = make([]int, 3*256)
		for y := rect.Min.Y; y < rect.Max.Y; y += 1 {
			for x := rect.Min.X; x < rect.Max.X; x += 1 {
				color := img.At(x, y)
				r, g, b, _ := color.RGBA()
				hist[r>>8] += 1
				hist[(g>>8)+256] += 1
				hist[(b>>8)+512] += 1
			}
		}
	}
	return hist, colormodel
}