Commit Graph

8 Commits

Author SHA1 Message Date
Paul Lindner fa46c3935d Correct various misspelled words
Change-Id: I236e880526e4c2b0bd318da041983d557e0aa885
2017-09-11 08:33:31 -07:00
mpl 997d400cbd pkg/images/resize: disable TestCompareResizeToHalveInplace for now
It's more important for now to be able to monitor for other failures in
the Camlistore repo than leaving this test on.

After having looked into the issue, I know a little more but not enough
for a definitive conclusion or fix.
It's all added as comments so we don't start from scratch again later.

Also, to make up for the loss of this test, I'm adding two other tests,
TestCompareOriginalToHalveInPlace, and TestCompareOriginalToResized,
that are similar enough to catch other problems in the same context I
believe.

Context: issue #635

Change-Id: I80a30f544fb9ab2e7c69118ef8509d3d687c2d27
2015-11-26 16:59:52 +01:00
mpl be155b4503 pkg/images/resize: fix filenames in tests
Setting the filename from the type, after resizing, does not work anymore
after fc890a65cd , because resized images
are now always RGBA, since we're using xdraw.

Change-Id: I561f43a3ebe9cb3e1d7404295635899ab6b62e7a
2015-11-20 21:43:12 +01:00
mpl fc890a65cd pkg/images/resize: use golang.org/x/image/draw for YCbCr
Later, we should look into using it for more cases. First, to see if we
can phase "halving in place" out, and also to see the gains with other
image types (non YCbCr).

Change-Id: I4b95e2039407f1a91e04cb502674819f17680e02
2015-09-05 01:07:43 +02:00
mpl 710a4236ee pkg/images/resize: show that golang.org/x/image/draw is a win
While investigating issue #635 I remembered that golang.org/x/image/draw
might offer some interesting features. It indeed happens to have some
rescaling routines that seem to work better in the YCbCr case than our
custom code, which is illustrated by these benchmarks:

% go test -v -bench Benchmark.*YCrCb.* -run Bench* -benchmem
% ./pkg/images/resize/
PASS
BenchmarkResizeYCrCb-4   	      20	  79213653 ns/op
9437475 B/op	       5 allocs/op
BenchmarkNewResizeYCrCb-4	     100	  15711294 ns/op
1048668 B/op	       2 allocs/op
BenchmarkHalveYCrCb-4    	     100	  17328467 ns/op
128 B/op	       1 allocs/op
ok  	camlistore.org/pkg/images/resize	5.889s

One can see that not only the new resize is faster, and uses less memory
than the old one, but it is also about as fast as "resizing by halving
in place". And this is with the ApproxBiLinear algorithm; some quick
additional tests seemed to indicate that NearestNeighbor was twice as
fast, with about the same memory usage. I chose ApproxBiLinear as it
seemed the most conservative choice for now.

I think it is also worth investigating whether we can be rid of "halving
in place", since it would make for simpler code overall, and since
ApproxBiLinear might be faster in most cases. It would have the nice
side-effect of solving issue #635 too. However, "halving in place" will
always win when it comes to memory usage, so it depends on our
priorities.

Finally, these other new benchmarks show that using the new resize does
not make the #635 mystery much worse (going from ~16% to ~18%), and that
interestingly the results of the old resize and the new resize are
pretty different by themselves.

% go test -v -run TestCompare ./pkg/images/resize/
=== RUN   TestCompareOldResizeToHalveInplace
--- FAIL: TestCompareOldResizeToHalveInplace (2.49s)
	resize_test.go:377: *image.Gray PSNR 63.7793
	resize_test.go:377: *image.Gray16 PSNR 59.9547
	resize_test.go:377: *image.NRGBA PSNR 62.8252
	resize_test.go:377: *image.NRGBA64 PSNR 62.8252
	resize_test.go:377: *image.Paletted PSNR 51.4949
	resize_test.go:377: *image.RGBA PSNR 62.8252
	resize_test.go:377: *image.RGBA64 PSNR 62.8252
	resize_test.go:377: *image.YCbCr PSNR 61.9664
	resize_test.go:382: *image.YCbCr not the same 18077 pixels
different 16.35%
	resize_test.go:377: *image.YCbCr PSNR 52.4121
	resize_test.go:382: *image.YCbCr not the same 18139 pixels
different 16.40%
	resize_test.go:377: *image.YCbCr PSNR 51.4972
	resize_test.go:382: *image.YCbCr not the same 17932 pixels
different 16.21%
	resize_test.go:377: *image.YCbCr PSNR 51.6399
	resize_test.go:382: *image.YCbCr not the same 17881 pixels
different 16.17%
	resize_test.go:377: *image.YCbCr PSNR 50.7736
	resize_test.go:382: *image.YCbCr not the same 17976 pixels
different 16.25%
	resize_test.go:377: *image.YCbCr PSNR 52.4536
	resize_test.go:382: *image.YCbCr not the same 18180 pixels
different 16.44%
=== RUN   TestCompareNewResizeToHalveInplace
--- FAIL: TestCompareNewResizeToHalveInplace (2.27s)
	resize_test.go:377: *image.Gray PSNR 63.7793
	resize_test.go:377: *image.Gray16 PSNR 59.9547
	resize_test.go:377: *image.NRGBA PSNR 62.8252
	resize_test.go:377: *image.NRGBA64 PSNR 62.8252
	resize_test.go:377: *image.Paletted PSNR 51.4949
	resize_test.go:377: *image.RGBA PSNR 62.8252
	resize_test.go:377: *image.RGBA64 PSNR 62.8252
	resize_test.go:377: *image.YCbCr PSNR 59.5902
	resize_test.go:382: *image.YCbCr not the same 20757 pixels
different 18.77%
	resize_test.go:377: *image.YCbCr PSNR 52.0962
	resize_test.go:382: *image.YCbCr not the same 20811 pixels
different 18.82%
	resize_test.go:377: *image.YCbCr PSNR 51.3374
	resize_test.go:382: *image.YCbCr not the same 20671 pixels
different 18.69%
	resize_test.go:377: *image.YCbCr PSNR 51.3586
	resize_test.go:382: *image.YCbCr not the same 20618 pixels
different 18.64%
	resize_test.go:377: *image.YCbCr PSNR 57.2346
	resize_test.go:382: *image.YCbCr not the same 20705 pixels
different 18.72%
	resize_test.go:377: *image.YCbCr PSNR 50.7504
	resize_test.go:382: *image.YCbCr not the same 20847 pixels
different 18.85%
=== RUN   TestCompareOldResizeToNewResize
--- FAIL: TestCompareOldResizeToNewResize (2.54s)
	resize_test.go:377: *image.Gray PSNR +Inf
	resize_test.go:377: *image.Gray16 PSNR +Inf
	resize_test.go:377: *image.NRGBA PSNR +Inf
	resize_test.go:377: *image.NRGBA64 PSNR +Inf
	resize_test.go:377: *image.Paletted PSNR +Inf
	resize_test.go:377: *image.RGBA PSNR +Inf
	resize_test.go:377: *image.RGBA64 PSNR +Inf
	resize_test.go:377: *image.YCbCr PSNR 59.1024
	resize_test.go:382: *image.YCbCr not the same 16350 pixels
different 14.78%
	resize_test.go:377: *image.YCbCr PSNR 62.6523
	resize_test.go:377: *image.YCbCr PSNR 62.7010
	resize_test.go:377: *image.YCbCr PSNR 59.1396
	resize_test.go:382: *image.YCbCr not the same 16225 pixels
different 14.67%
	resize_test.go:377: *image.YCbCr PSNR 59.0844
	resize_test.go:382: *image.YCbCr not the same 16294 pixels
different 14.73%
	resize_test.go:377: *image.YCbCr PSNR 59.0534
	resize_test.go:382: *image.YCbCr not the same 16413 pixels
different 14.84%

Change-Id: Ia8c578a53416ec0f1cac1477a1a68acfede84b24
2015-09-05 00:59:50 +02:00
mpl be3ea3fe01 images/resize: add YCbCr 4:1:1 and 4:1:0 samples
Also fixed a typo and left TODOs.

Related: issue #635

Change-Id: I6797094c3eaeb26a2d9397c1174c2548fad7d312
2015-08-21 18:17:01 +02:00
Brad Fitzpatrick bfe51f3ad5 gofmt
Change-Id: Ie6be315d02a439cbfdd870a0b0b7f16cba12a168
2014-03-20 12:29:45 -07:00
Brad Fitzpatrick 9366723666 Rename pkg/misc/resize to pkg/images/resize
Change-Id: I9b8105cbae0c6dc66ccbb1dd15a48363ee2f1e85
2013-12-16 17:49:28 -08:00