-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
677 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# traceskeleton.go | ||
|
||
Golang version using prallel goroutines. | ||
|
||
## Usage | ||
|
||
``` | ||
import "traceskeleton" | ||
``` | ||
|
||
See `example.go` for detailed usage. | ||
|
||
All source code is in `src/traceskeleton/traceskeleton.go` | ||
|
||
## Compile | ||
|
||
``` | ||
export GO_PATH=$PWD; go build example.go | ||
``` | ||
|
||
**Note:** This is my "Hello World" in Go, feel free to PR if you feel something could be done more idiomatically! | ||
|
||
|
||
**Developed at [Frank-Ratchye STUDIO for Creative Inquiry](https://studioforcreativeinquiry.org) at Carnegie Mellon University.** |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package main | ||
|
||
import "traceskeleton" | ||
|
||
import ( | ||
"image/png" | ||
"os" | ||
"log" | ||
"time" | ||
"fmt" | ||
"io/ioutil" | ||
) | ||
|
||
// read png image using stdlib | ||
func readImage(path string) ([]uint8, int, int){ | ||
reader, err := os.Open(path) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer reader.Close() | ||
m, err := png.Decode(reader) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
bounds := m.Bounds() | ||
var w = bounds.Max.X - bounds.Min.X; | ||
var h = bounds.Max.Y - bounds.Min.Y; | ||
var im = make([]uint8, w*h) | ||
for y := bounds.Min.Y; y < bounds.Max.Y; y++ { | ||
for x := bounds.Min.X; x < bounds.Max.X; x++ { | ||
r, _, _, _ := m.At(x, y).RGBA() | ||
if r >= 32768 { | ||
im[w*y+x] = 1 | ||
}else{ | ||
im[w*y+x] = 0 | ||
} | ||
} | ||
} | ||
return im,w,h | ||
} | ||
|
||
func main() { | ||
var im, w, h = readImage(os.Args[1]); | ||
|
||
traceskeleton.ThinningZS(im,w,h); // do raster thinning first | ||
|
||
start := time.Now() | ||
var p = traceskeleton.TraceSkeleton(im,w,h,0,0,w,h,10,999); // trace to polylines | ||
fmt.Println(time.Since(start)) | ||
|
||
// save the result as scalable vector graphics | ||
ioutil.WriteFile("out.svg", []byte(traceskeleton.PolylinesToSvg(p,w,h)), 0644); | ||
} |
Oops, something went wrong.