1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

tested smooth filter functions of CvMat

This commit is contained in:
ser1zw 2011-01-27 00:48:35 +09:00
parent 88a29994ea
commit 65368cd049
2 changed files with 122 additions and 5 deletions

View file

@ -3650,7 +3650,7 @@ rb_smooth_blur_no_scale(int argc, VALUE *argv, VALUE self)
rb_raise(rb_eNotImpError, "unsupport format. (support 8bit unsigned/signed or 32bit floating point only)");
}
dest = new_object(cvGetSize(CVARR(self)), dest_type);
cvSmooth(CVARR(self), CVARR(dest), CV_BLUR_NO_SCALE, IF_INT(p1, 3), IF_INT(p2, 0));
cvSmooth(CVARR(self), CVARR(dest), CV_BLUR_NO_SCALE, IF_INT(p1, 3), IF_INT(p2, 3));
return dest;
}
@ -3668,7 +3668,7 @@ rb_smooth_blur(int argc, VALUE *argv, VALUE self)
VALUE p1, p2, dest;
rb_scan_args(argc, argv, "02", &p1, &p2);
dest = cCvMat::new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
cvSmooth(CVARR(self), CVARR(dest), CV_BLUR, IF_INT(p1, 3), IF_INT(p2, 0));
cvSmooth(CVARR(self), CVARR(dest), CV_BLUR, IF_INT(p1, 3), IF_INT(p2, 3));
return dest;
}
@ -3692,9 +3692,9 @@ rb_smooth_gaussian(int argc, VALUE *argv, VALUE self)
{
SUPPORT_C1C3_ONLY(self);
VALUE p1, p2, p3, p4, dest;
rb_scan_args(argc, argv, "04", &p1, &p2, &p3, p4);
rb_scan_args(argc, argv, "04", &p1, &p2, &p3, &p4);
dest = cCvMat::new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
cvSmooth(CVARR(self), CVARR(dest), CV_GAUSSIAN, IF_INT(p1, 3), IF_INT(p2, 0), IF_DBL(p3, 0.0), IF_DBL(p4, 0.0));
cvSmooth(CVARR(self), CVARR(dest), CV_GAUSSIAN, IF_INT(p1, 3), IF_INT(p2, 3), IF_DBL(p3, 0.0), IF_DBL(p4, 0.0));
return dest;
}
@ -3732,7 +3732,7 @@ rb_smooth_bilateral(int argc, VALUE *argv, VALUE self)
VALUE p1, p2, dest;
rb_scan_args(argc, argv, "02", &p1, &p2);
dest = cCvMat::new_object(cvGetSize(CVARR(self)), cvGetElemType(CVARR(self)));
cvSmooth(CVARR(self), CVARR(dest), CV_BILATERAL, IF_INT(p1, 3), IF_INT(p2, 0));
cvSmooth(CVARR(self), CVARR(dest), CV_BILATERAL, IF_INT(p1, 3), IF_INT(p2, 3));
return dest;
}

View file

@ -587,5 +587,122 @@ class TestCvMat_imageprocessing < OpenCVTestCase
assert_equal('3fc6bc283fa952e1fd566944d94b3e9a', hash_img(mat2))
assert_equal('18b1d51637b912a38133341ee006c6ff', hash_img(mat3))
end
def test_smooth_blur_no_scale
mat0 = CvMat.load(FILENAME_LENA32x32, CV_LOAD_IMAGE_GRAYSCALE)
mat1 = mat0.smooth_blur_no_scale
mat2 = mat0.smooth_blur_no_scale(3, 3)
mat3 = mat0.smooth_blur_no_scale(7, 7)
mat4 = CvMat.new(32, 32, :cv32f, 1).smooth_blur_no_scale
[mat1, mat2, mat3].each { |m|
assert_equal(1, m.channel)
assert_equal(:cv16u, m.depth)
}
assert_equal(1, mat4.channel)
assert_equal(:cv32f, mat4.depth)
assert_equal('3c9074c87b65117798f48e41a17b2f30', hash_img(mat1))
assert_equal('3c9074c87b65117798f48e41a17b2f30', hash_img(mat2))
assert_equal('9c549aa406a425a65b036c2f9a2689e0', hash_img(mat3))
end
def test_smooth_blur
mat0 = CvMat.load(FILENAME_LENA32x32, CV_LOAD_IMAGE_GRAYSCALE)
mat1 = mat0.smooth_blur
mat2 = mat0.smooth_blur(3, 3)
mat3 = mat0.smooth_blur(7, 7)
mat4 = CvMat.new(32, 32, :cv16u, 1).smooth_blur
mat5 = CvMat.new(32, 32, :cv32f, 1).smooth_blur
mat6 = CvMat.new(32, 32, :cv8u, 3).smooth_blur
[mat1, mat2, mat3].each { |m|
assert_equal(1, m.channel)
assert_equal(:cv8u, m.depth)
}
assert_equal(1, mat4.channel)
assert_equal(:cv16u, mat4.depth)
assert_equal(1, mat5.channel)
assert_equal(:cv32f, mat5.depth)
assert_equal(3, mat6.channel)
assert_equal(:cv8u, mat6.depth)
assert_equal('f2473b5b964ae8950f6a7fa5cde4c67a', hash_img(mat1))
assert_equal('f2473b5b964ae8950f6a7fa5cde4c67a', hash_img(mat2))
assert_equal('d7bb344fc0f6ec0da4b9754d319e4e4a', hash_img(mat3))
end
def test_smooth_gaussian
mat0 = CvMat.load(FILENAME_LENA32x32, CV_LOAD_IMAGE_GRAYSCALE)
mat1 = mat0.smooth_gaussian
mat2 = mat0.smooth_gaussian(3, 3)
mat3 = mat0.smooth_gaussian(3, 3, 3)
mat4 = mat0.smooth_gaussian(3, 3, 3, 3)
mat5 = mat0.smooth_gaussian(7, 7, 5, 3)
mat6 = CvMat.new(32, 32, :cv16u, 1).smooth_gaussian
mat7 = CvMat.new(32, 32, :cv32f, 1).smooth_gaussian
mat8 = CvMat.new(32, 32, :cv8u, 3).smooth_gaussian
[mat1, mat2, mat3, mat4, mat5].each { |m|
assert_equal(1, m.channel)
assert_equal(:cv8u, m.depth)
}
assert_equal(1, mat6.channel)
assert_equal(:cv16u, mat6.depth)
assert_equal(1, mat7.channel)
assert_equal(:cv32f, mat7.depth)
assert_equal(3, mat8.channel)
assert_equal(:cv8u, mat8.depth)
assert_equal('580c88f3e0e317a5770be3f28f31eda2', hash_img(mat1))
assert_equal('580c88f3e0e317a5770be3f28f31eda2', hash_img(mat2))
assert_equal('a1ffaa14522719e37d75eec18ff8b309', hash_img(mat3))
assert_equal('a1ffaa14522719e37d75eec18ff8b309', hash_img(mat4))
assert_equal('f7f8b4eff3240ffc8f259ce975936d92', hash_img(mat5))
end
def test_smooth_median
mat0 = create_cvmat(64, 64, :cv8u, 1) { |j, i, c|
if (i + j) % 15 != 0
CvScalar.new(255)
else
CvScalar.new(0)
end
}
(-1..1).each { |dy|
(-1..1).each { |dx|
mat0[32 + dy, 32 + dx] = CvScalar.new(0)
}
}
mat1 = mat0.smooth_median
mat2 = mat0.smooth_median(3)
mat3 = mat0.smooth_median(7)
mat4 = CvMat.new(64, 64, :cv8u, 3).smooth_median
assert_equal('7343a41c542e034db356636c06134961', hash_img(mat1))
assert_equal('7343a41c542e034db356636c06134961', hash_img(mat2))
assert_equal('6ae59e64850377ee5470c854761551ea', hash_img(mat3))
end
def test_smooth_bilateral
flunk('FIXME: CvMat#smooth_bilateral is not tested yet.')
mat0 = create_cvmat(64, 64, :cv8u, 1) { |j, i, c|
if i > 32
(i + j) % 15 != 0 ? CvScalar.new(32) : CvScalar.new(224)
else
(i + j) % 15 != 0 ? CvScalar.new(224) : CvScalar.new(32)
end
}
mat1 = mat0.smooth_bilateral
mat2 = mat0.smooth_bilateral(3, 3)
mat3 = mat0.smooth_bilateral(7, 7)
mat4 = CvMat.new(64, 64, :cv8u, 3).smooth_bilateral
end
end