Skip to content

Instantly share code, notes, and snippets.

default Stream<T> dropWhile(Predicate<? super T> predicate)
private Stream stream = Stream.of(1,2,10,3,4,5,6,7,8,9);
stream.dropWhile(x -> (Integer)x<4).forEach(a -> System.out.println(a));
edgeDetection(&pixels)
func edgeDetection(pixels *[][]color.Color){
ppixels := *pixels
//make image grey scale
for x:=0;x<len(ppixels);x++{
for y:=0;y<len(ppixels[0]);y++{
r,g,b,a:=ppixels[x][y].RGBA()
grey := 0.299*float64(r) + 0.587*float64(g) + 0.114*float64(b)
c:=uint8(grey+0.5)
gaussianKernel := mat.NewDense(5,5,[]float64{
1.0/256,4.0/256,6.0/256,4.0/256,1.0/256,
4.0/256,16.0/256,24.0/256,16.0/256,4.0/256,
6.0/256,24.0/256,36.0/256,24.0/256,6.0/256,
4.0/256,16.0/256,24.0/256,16.0/256,4.0/256,
1.0/256,4.0/256,6.0/256,4.0/256,1.0/256,
})
spartialFilter(&pixels,gaussianKernel)
boxKernel := mat.NewDense(3,3,[]float64{
1.0/9,1.0/9,1.0/9,
1.0/9,1.0/9,1.0/9,
1.0/9,1.0/9,1.0/9,
})
spartialFilter(&pixels,boxKernel)
func spartialFilter(pixels *[][]color.Color,kernel *mat.Dense){
ppixel := *pixels
type pixelDetail struct {
xOld,yOld int
xNew,yNew float64
oldPixel color.Color
}
type job struct {
i,j int
sm *mat.Dense
pm *[]pixelDetail
op color.Color
diagonal :=int(math.Sqrt(float64(size.X*size.X) +float64(size.Y*size.Y)))
simpleRotationByAngle(math.Pi/10,&pixels,diagonal)
import (
"image/color"
"math"
"sync"
)
func simpleRotationByAngle(angle float64, pixels *[][]color.Color, diagonal int){
func greyScale(pixels *[][]color.Color) {
ppixels := *pixels
xLen:=len(ppixels)
yLen := len(ppixels[0])
//create new image
newImage:=make([][]color.Color, xLen)
for i:=0;i<len(newImage);i++{
newImage[i] = make([]color.Color,yLen)
}
//idea is processing pixels in parallel
func upsideDown(pixels [][]color.Color) {
for i:=0; i<len(pixels);i++{
tr:=pixels[i]
for j:=0; j<len(tr)/2;j++{
k:= len(tr) -j -1
tr[j],tr[k] = tr[k],tr[j]
}
}
}
rect := image.Rect(0,0,len(pixels),len(pixels[0]))
nImg := image.NewRGBA(rect)
for x:=0; x<len(pixels);x++{
for y:=0; y<len(pixels[0]);y++ {
q:=pixels[x]
if q==nil{
continue
}
p := pixels[x][y]
size:= img.Bounds().Size()
var pixels [][]color.Color
//put pixels into two three two dimensional array
for i:=0; i<size.X;i++{
var y []color.Color
for j:=0; j<size.Y;j++{
y = append(y,img.At(i,j))
}
pixels = append(pixels,y)
}