From 179bb4a20ad93d418e3e911f90f98b6099a3f0ef Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 24 Aug 2020 14:49:50 +0100 Subject: Add verbose option to print min/max values --- cmd/pggraph/main.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'cmd/pggraph') diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go index 2da5c57..fd61761 100644 --- a/cmd/pggraph/main.go +++ b/cmd/pggraph/main.go @@ -25,7 +25,7 @@ import ( "rescribe.xyz/preproc" ) -const usage = `Usage: pggraph [-vertical] [-width] inimg graphname +const usage = `Usage: pggraph [-vertical] [-width] [-v] inimg graphname Creates a graph showing the proportion of black pixels for slices through a binarised image. This is useful to determine @@ -49,14 +49,15 @@ func sideways(img *image.Gray) *image.Gray { return new } -func graph(title string, points map[int]float64, w io.Writer) error { +func graph(title string, points map[int]float64, w io.Writer) (float64, float64, error) { var xvals, yvals []float64 var xs []int var midxvals, midyvals []float64 var midxs []int + var miny, maxy float64 if len(points) < 2 { - return fmt.Errorf("Not enough points to graph, only %d\n", len(points)) + return miny, maxy, fmt.Errorf("Not enough points to graph, only %d\n", len(points)) } for x, _ := range points { @@ -92,6 +93,18 @@ func graph(title string, points map[int]float64, w io.Writer) error { midyvals = append(midyvals, points[x]) } + miny = 100.0 + maxy = 0.0 + for _, x := range midxs { + y := points[x] + if y < miny { + miny = y + } + if y > maxy { + maxy = y + } + } + middleSeries := chart.ContinuousSeries{ XValues: midxvals, YValues: midyvals, @@ -131,6 +144,10 @@ func graph(title string, points map[int]float64, w io.Writer) error { }, YAxis: chart.YAxis{ Name: "Proportion of black pixels", + Range: &chart.ContinuousRange{ + Min: 0.0, + Max: 0.5, + }, }, Series: []chart.Series{ mainSeries, @@ -141,7 +158,7 @@ func graph(title string, points map[int]float64, w io.Writer) error { }, } - return graph.Render(chart.PNG, w) + return miny, maxy, graph.Render(chart.PNG, w) } func main() { @@ -151,6 +168,7 @@ func main() { } vertical := flag.Bool("vertical", false, "Slice image vertically (from top to bottom) rather than horizontally") width := flag.Int("width", 5, "Width of slice in pixels (height if in vertical mode)") + verbose := flag.Bool("v", false, "Print the minimum and maximum values of the middle section to the console") flag.Parse() if flag.NArg() < 2 { flag.Usage() @@ -192,8 +210,12 @@ func main() { if *vertical { title += " (vertical)" } - err = graph(title, points, f) + miny, maxy, err := graph(title, points, f) if err != nil { log.Fatalf("Could not create graph: %v\n", err) } + + if *verbose { + fmt.Printf("%s %0.2f %0.2f\n", flag.Arg(0), miny, maxy) + } } -- cgit v1.2.1-24-ge1ad From 34dda838f09cd3c9d95d435e8fa8ac446401843f Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 24 Aug 2020 15:04:42 +0100 Subject: [pggraph] have verbose printing include options it was run with --- cmd/pggraph/main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmd/pggraph') diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go index fd61761..9842efd 100644 --- a/cmd/pggraph/main.go +++ b/cmd/pggraph/main.go @@ -216,6 +216,10 @@ func main() { } if *verbose { - fmt.Printf("%s %0.2f %0.2f\n", flag.Arg(0), miny, maxy) + v := "" + if *vertical { + v = " vertical" + } + fmt.Printf("%s %d%s %0.2f %0.2f\n", flag.Arg(0), *width, v, miny, maxy) } } -- cgit v1.2.1-24-ge1ad From 54510d7c797682d37b1bb0d62d8bb7c3f5951388 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 12 Apr 2021 14:31:39 +0100 Subject: Update go-chart dependency (should solve issues with bad go-sdk version) --- cmd/pggraph/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cmd/pggraph') diff --git a/cmd/pggraph/main.go b/cmd/pggraph/main.go index 9842efd..353dce4 100644 --- a/cmd/pggraph/main.go +++ b/cmd/pggraph/main.go @@ -20,7 +20,7 @@ import ( "os" "sort" - chart "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/v2" "rescribe.xyz/integral" "rescribe.xyz/preproc" ) -- cgit v1.2.1-24-ge1ad