multiarray 0.18.0 → 0.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -1
- data/lib/multiarray/operations.rb +32 -8
- data/test/tc_multiarray.rb +8 -0
- data/test/tc_sequence.rb +9 -0
- metadata +3 -3
data/Rakefile
CHANGED
@@ -408,6 +408,19 @@ module Hornetseye
|
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
411
|
+
# Clip values to specified range
|
412
|
+
#
|
413
|
+
# @param [Range] range Allowed range of values.
|
414
|
+
#
|
415
|
+
# @return [Node] Array with clipped values.
|
416
|
+
def clip( range = 0 .. 0xFF )
|
417
|
+
if range.exclude_end?
|
418
|
+
raise "Clipping does not support ranges with end value " +
|
419
|
+
"excluded (such as #{range})"
|
420
|
+
end
|
421
|
+
major( range.begin ).minor range.end
|
422
|
+
end
|
423
|
+
|
411
424
|
# Fill array with a value
|
412
425
|
#
|
413
426
|
# @param [Object] value Value to fill array with.
|
@@ -478,15 +491,11 @@ module Hornetseye
|
|
478
491
|
raise "Filter has #{filter.dimension} dimension(s) but should " +
|
479
492
|
"not have more than #{dimension}"
|
480
493
|
end
|
481
|
-
|
482
|
-
while filter.dimension < dimension
|
483
|
-
filter = Hornetseye::lazy( 1 ) { filter }
|
484
|
-
array = array.unroll
|
485
|
-
end
|
494
|
+
filter = Hornetseye::lazy( 1 ) { filter } while filter.dimension < dimension
|
486
495
|
if filter.dimension == 0
|
487
|
-
|
496
|
+
self * filter
|
488
497
|
else
|
489
|
-
Hornetseye::lazy { |i,j|
|
498
|
+
Hornetseye::lazy { |i,j| self[j].product filter[i] }
|
490
499
|
end
|
491
500
|
end
|
492
501
|
|
@@ -497,7 +506,22 @@ module Hornetseye
|
|
497
506
|
# @return [Node] Result of convolution.
|
498
507
|
def convolve( filter )
|
499
508
|
filter = Node.match( filter, typecode ).new filter unless filter.is_a? Node
|
500
|
-
|
509
|
+
array = self
|
510
|
+
( dimension - filter.dimension ).times { array = array.roll }
|
511
|
+
array.product( filter ).diagonal { |s,x| s + x }
|
512
|
+
end
|
513
|
+
|
514
|
+
# Sobel operator
|
515
|
+
#
|
516
|
+
# @param [Integer] direction Orientation of Sobel filter.
|
517
|
+
#
|
518
|
+
# @return [Node] Result of Sobel operator.
|
519
|
+
def sobel( direction )
|
520
|
+
( dimension - 1 ).downto( 0 ).inject self do |retval,i|
|
521
|
+
filter = i == direction ? Hornetseye::Sequence( SINT, 3 )[ -1, 0, 1 ] :
|
522
|
+
Hornetseye::Sequence( SINT, 3 )[ 1, 2, 1 ]
|
523
|
+
Hornetseye::lazy { retval.convolve filter }
|
524
|
+
end.force
|
501
525
|
end
|
502
526
|
|
503
527
|
# Compute histogram of this array
|
data/test/tc_multiarray.rb
CHANGED
@@ -432,6 +432,14 @@ class TC_MultiArray < Test::Unit::TestCase
|
|
432
432
|
assert_raise( RuntimeError ) { S[ 1, 2, 3 ].convolve f }
|
433
433
|
end
|
434
434
|
|
435
|
+
def test_sobel
|
436
|
+
m = M[ [ 0, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 0 ] ]
|
437
|
+
assert_equal [ [ -1, 0, 1, 0 ], [ -2, 0, 2, 0 ], [ -1, 0, 1, 0 ] ],
|
438
|
+
m.sobel( 0 ).to_a
|
439
|
+
assert_equal [ [ -1, -2, -1, 0 ], [ 0, 0, 0, 0 ], [ 1, 2, 1, 0 ] ],
|
440
|
+
m.sobel( 1 ).to_a
|
441
|
+
end
|
442
|
+
|
435
443
|
def test_histogram
|
436
444
|
assert_equal [ 0, 1, 1, 2, 0 ],
|
437
445
|
M[ [ 1, 2 ], [ 3, 3 ] ].histogram( 5, :weight => 1 ).to_a
|
data/test/tc_sequence.rb
CHANGED
@@ -333,6 +333,11 @@ class TC_Sequence < Test::Unit::TestCase
|
|
333
333
|
assert_equal [ C( 0.0, 85.0, 255.0 ) ], S[ C( 1, 2, 4 ) ].normalise.to_a
|
334
334
|
end
|
335
335
|
|
336
|
+
def test_clip
|
337
|
+
assert_equal [ 0, 1, 3, 4 ], S[ -1, 1, 3, 5 ].clip( 0 .. 4 ).to_a
|
338
|
+
assert_equal [ C( 3, 4, 5 ) ], S[ C( 2, 4, 6 ) ].clip( 3 .. 5 ).to_a
|
339
|
+
end
|
340
|
+
|
336
341
|
def test_sum
|
337
342
|
[ S( O, 3 ), S( I, 3 ) ].each do |t|
|
338
343
|
assert_equal 9, t[ 4, 2, 3 ].sum
|
@@ -361,6 +366,10 @@ class TC_Sequence < Test::Unit::TestCase
|
|
361
366
|
convolve( S[ C( 1, 0, 0 ), C( 0, 1, 0 ), C( 0, 0, 1 ) ] )
|
362
367
|
end
|
363
368
|
|
369
|
+
def test_sobel
|
370
|
+
assert_equal [ 0, -1, 0, 1, 0 ], S[ 0, 0, 1, 0, 0 ].sobel( 0 ).to_a
|
371
|
+
end
|
372
|
+
|
364
373
|
def test_histogram
|
365
374
|
[ O, I ].each do |t|
|
366
375
|
assert_equal [ 0, 1, 2, 1, 1 ],
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 18
|
8
|
-
-
|
9
|
-
version: 0.18.
|
8
|
+
- 1
|
9
|
+
version: 0.18.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jan Wedekind
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-12 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|