mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
modified tests for CvMat#threshold
This commit is contained in:
parent
62e46603a9
commit
8ba37a3ce3
1 changed files with 29 additions and 29 deletions
|
@ -877,8 +877,8 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
def test_threshold
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
test_proc = lambda { |type, type_sym, expected_mat, expected_threshold|
|
||||
mat1 = mat0.threshold(3, 7, type)
|
||||
mat2 = mat0.threshold(3, 7, type_sym)
|
||||
mat1 = mat0.threshold(expected_threshold, 7, type)
|
||||
mat2 = mat0.threshold(expected_threshold, 7, type_sym)
|
||||
mat3, th3 = mat0.threshold(5, 7, type | CV_THRESH_OTSU)
|
||||
mat4, th4 = mat0.threshold(3, 7, type_sym, true)
|
||||
mat5, th5 = mat0.threshold(5, 7, type | CV_THRESH_OTSU, true)
|
||||
|
@ -893,33 +893,33 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
}
|
||||
# Binary
|
||||
expected = [0, 0, 0,
|
||||
0, 7, 7,
|
||||
0, 0, 7,
|
||||
7, 7, 7]
|
||||
test_proc.call(CV_THRESH_BINARY, :binary, expected, 3)
|
||||
test_proc.call(CV_THRESH_BINARY, :binary, expected, 4)
|
||||
|
||||
# Binary inverse
|
||||
expected = [7, 7, 7,
|
||||
7, 0, 0,
|
||||
7, 7, 0,
|
||||
0, 0, 0]
|
||||
test_proc.call(CV_THRESH_BINARY_INV, :binary_inv, expected, 3)
|
||||
test_proc.call(CV_THRESH_BINARY_INV, :binary_inv, expected, 4)
|
||||
|
||||
# Trunc
|
||||
expected = [0, 1, 2,
|
||||
3, 3, 3,
|
||||
3, 3, 3]
|
||||
test_proc.call(CV_THRESH_TRUNC, :trunc, expected, 3)
|
||||
3, 4, 4,
|
||||
4, 4, 4]
|
||||
test_proc.call(CV_THRESH_TRUNC, :trunc, expected, 4)
|
||||
|
||||
# To zero
|
||||
expected = [0, 0, 0,
|
||||
0, 4, 5,
|
||||
0, 0, 5,
|
||||
6, 7, 8]
|
||||
test_proc.call(CV_THRESH_TOZERO, :tozero, expected, 3)
|
||||
test_proc.call(CV_THRESH_TOZERO, :tozero, expected, 4)
|
||||
|
||||
# To zero inverse
|
||||
expected = [0, 1, 2,
|
||||
3, 0, 0,
|
||||
3, 4, 0,
|
||||
0, 0, 0]
|
||||
test_proc.call(CV_THRESH_TOZERO_INV, :tozero_inv, expected, 3)
|
||||
test_proc.call(CV_THRESH_TOZERO_INV, :tozero_inv, expected, 4)
|
||||
|
||||
assert_raise(ArgumentError) {
|
||||
mat0.threshold(1, 2, :foobar)
|
||||
|
@ -928,16 +928,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
def test_threshold_binary
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
mat1 = mat0.threshold_binary(3, 7)
|
||||
mat1 = mat0.threshold_binary(4, 7)
|
||||
expected = [0, 0, 0,
|
||||
0, 7, 7,
|
||||
0, 0, 7,
|
||||
7, 7, 7]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
||||
mat2, thresh2 = mat0.threshold_binary(5, 7, true)
|
||||
assert_in_delta(3, thresh2, 0.001)
|
||||
assert_in_delta(4, thresh2, 0.001)
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
@ -945,16 +945,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
def test_threshold_binary_inverse
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
mat1 = mat0.threshold_binary_inverse(3, 7)
|
||||
mat1 = mat0.threshold_binary_inverse(4, 7)
|
||||
expected = [7, 7, 7,
|
||||
7, 0, 0,
|
||||
7, 7, 0,
|
||||
0, 0, 0]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
||||
mat2, thresh2 = mat0.threshold_binary_inverse(5, 7, true)
|
||||
assert_in_delta(3, thresh2, 0.001)
|
||||
assert_in_delta(4, thresh2, 0.001)
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
@ -962,16 +962,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
def test_threshold_trunc
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
mat1 = mat0.threshold_trunc(3)
|
||||
mat1 = mat0.threshold_trunc(4)
|
||||
expected = [0, 1, 2,
|
||||
3, 3, 3,
|
||||
3, 3, 3]
|
||||
3, 4, 4,
|
||||
4, 4, 4]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
||||
mat2, thresh2 = mat0.threshold_trunc(5, true)
|
||||
assert_in_delta(3, thresh2, 0.001)
|
||||
assert_in_delta(4, thresh2, 0.001)
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
@ -979,16 +979,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
def test_threshold_to_zero
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
mat1 = mat0.threshold_to_zero(3)
|
||||
mat1 = mat0.threshold_to_zero(4)
|
||||
expected = [0, 0, 0,
|
||||
0, 4, 5,
|
||||
0, 0, 5,
|
||||
6, 7, 8]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
||||
mat2, thresh2 = mat0.threshold_to_zero(5, true)
|
||||
assert_in_delta(3, thresh2, 0.001)
|
||||
assert_in_delta(4, thresh2, 0.001)
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
@ -996,16 +996,16 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
|||
|
||||
def test_threshold_to_zero_inverse
|
||||
mat0 = create_cvmat(3, 3, :cv8u, 1) { |j, i, n| CvScalar.new(n) }
|
||||
mat1 = mat0.threshold_to_zero_inverse(3)
|
||||
mat1 = mat0.threshold_to_zero_inverse(4)
|
||||
expected = [0, 1, 2,
|
||||
3, 0, 0,
|
||||
3, 4, 0,
|
||||
0, 0, 0]
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
||||
mat2, thresh2 = mat0.threshold_to_zero_inverse(5, true)
|
||||
assert_in_delta(3, thresh2, 0.001)
|
||||
assert_in_delta(4, thresh2, 0.001)
|
||||
expected.each_with_index { |x, i|
|
||||
assert_equal(x, mat1[i][0])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue