示例#1
0
    def testFivebyFive(self):
        """ Test using a 5x5 window """
        in0 = np.random.rand(1, 1)
        in1 = np.random.rand(4000, 4000)

        check0 = sps.medfilt2d(in0, 5)
        check1 = sps.medfilt2d(in1, 5)

        self.assertTrue(
            np.allclose(check0,
                        mf.MedianFilter(kernel_size=5, input=[in0])[0]))
        self.assertTrue(
            np.allclose(check1,
                        mf.MedianFilter(kernel_size=5, input=[in1])[0]))
示例#2
0
    def testNinebyNine(self):
        """ Test using a 9x9 window """
        in0 = np.random.rand(1, 1)
        in1 = np.random.rand(997, 997)

        check0 = sps.medfilt2d(in0, 9)
        check1 = sps.medfilt2d(in1, 9)

        self.assertTrue(
            np.allclose(
                check0,
                mf.MedianFilter(kernel_size=9, input=[in0], bw=16, bh=16)[0]))
        self.assertTrue(
            np.allclose(check1,
                        mf.MedianFilter(kernel_size=9, input=[in1])[0]))
示例#3
0
	def testLopsidedImage(self):
		""" Test using non-square images """
		in0 = np.random.rand(1, 73)
		in1 = np.random.rand(5, 3)
		in2 = np.random.rand(2, 3)
		in3 = np.random.rand(8013, 700)

		check0 = sps.medfilt2d(in0, 1)
		check1 = sps.medfilt2d(in1, 1)
		check2 = sps.medfilt2d(in2, 3)
		check3 = sps.medfilt2d(in3, 5)

		self.assertTrue(np.allclose(check0, mf.MedianFilter(kernel_size=1, input=[in0])[0]))
		self.assertTrue(np.allclose(check1, mf.MedianFilter(kernel_size=1, input=[in1])[0]))
		self.assertTrue(np.allclose(check2, mf.MedianFilter(kernel_size=3, input=[in2])[0]))
		self.assertTrue(np.allclose(check3, mf.MedianFilter(kernel_size=5, input=[in3])[0]))
示例#4
0
	def testLopsidedWindow(self):
		""" Test using non-square windows """
		in0 = np.random.rand(1, 73)
		in1 = np.random.rand(5, 3)
		in2 = np.random.rand(2, 3)
		in3 = np.random.rand(8013, 700)

		check0 = sps.medfilt2d(in0, (1, 11))
		check1 = sps.medfilt2d(in1, (11, 1))
		check2 = sps.medfilt2d(in2, (3, 5))
		check3 = sps.medfilt2d(in3, (9, 5))

		self.assertTrue(np.allclose(check0, mf.MedianFilter(kernel_size=(1, 11), input=[in0])[0]))
		self.assertTrue(np.allclose(check1, mf.MedianFilter(kernel_size=(11, 1), input=[in1])[0]))
		self.assertTrue(np.allclose(check2, mf.MedianFilter(kernel_size=(3, 5), input=[in2])[0]))
		self.assertTrue(np.allclose(check3, mf.MedianFilter(kernel_size=(9, 5), input=[in3])[0]))
示例#5
0
    def testOneByOne(self):
        """ Test using a 1x1 window """
        in0 = np.random.rand(1, 1)
        in1 = np.random.rand(29, 29)
        in2 = np.random.rand(93, 93)
        in3 = np.random.rand(7000, 7000)

        check0 = sps.medfilt2d(in0, 1)
        check1 = sps.medfilt2d(in1, 1)
        check2 = sps.medfilt2d(in2, 1)
        check3 = sps.medfilt2d(in3, 1)

        self.assertTrue(
            np.allclose(check0, mf.MedianFilter(kernel_size=1, input=in0)))
        self.assertTrue(
            np.allclose(check1, mf.MedianFilter(kernel_size=1, input=in1)))
        self.assertTrue(
            np.allclose(check2, mf.MedianFilter(kernel_size=1, input=in2)))
        self.assertTrue(
            np.allclose(check3, mf.MedianFilter(kernel_size=1, input=in3)))
示例#6
0
	def testStreamsMore(self):
		""" A more comprehensive test of streams """
		inList0 = [np.random.rand(100, 67) for i in xrange(10)]

		check0 = [sps.medfilt2d(elem, (5, 7)) for elem in inList0]

		ans0 = mf.MedianFilter(kernel_size=(5,7), input=inList0)

		for i in xrange(10):
			self.assertTrue(np.allclose(check0[i], ans0[i]))



		inList1 = [np.random.rand(600, 1024) for i in xrange(10)]

		check1 = [sps.medfilt2d(elem, (7, 9)) for elem in inList1]

		ans1 = mf.MedianFilter(kernel_size=(7, 9), input=inList1)

		for i in xrange(10):
			self.assertTrue(np.allclose(check1[i], ans1[i]))
示例#7
0
	def testStreams(self):
		""" Test using streams """
		in99 = np.random.rand(5,3)
		in0 = np.random.rand(5, 3)
		in1 = np.random.rand(5, 3)
		in2 = np.random.rand(5, 3)
		in3 = np.random.rand(600, 1024)

		check99 = sps.medfilt2d(in99, 1)
		check0 = sps.medfilt2d(in0, 3)
		check1 = sps.medfilt2d(in1, 3)
		check2 = sps.medfilt2d(in2, 3)
		check3 = sps.medfilt2d(in3, 5)

		self.assertTrue(np.allclose(check99, mf.MedianFilter(kernel_size=1, input=[in99]*3)[0]))


		self.assertTrue(np.allclose(check0, mf.MedianFilter(kernel_size=3, input=[in0, in1, in0])[0]))
		self.assertTrue(np.allclose(check1, mf.MedianFilter(kernel_size=3, input=[in0, in1, in1])[1]))

		self.assertTrue(np.allclose(check1, mf.MedianFilter(kernel_size=3, input=[in99, in0, in1, in2])[2]))
		self.assertTrue(np.allclose(check2, mf.MedianFilter(kernel_size=3, input=[in99, in0, in1, in2])[3]))

		self.assertTrue(np.allclose(check3, mf.MedianFilter(kernel_size=5, input=[in3]*5)[1]))