Beispiel #1
0
    def testFilter3(self):
        """Simple test of a three by three kernel median filter"""
        dataIn = numpy.arange(100, dtype=numpy.int32)
        dataIn = dataIn.reshape((10, 10))

        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=(3, 3),
                               conditionnal=False)

        self.assertTrue(dataOut[0, 0] == 10)
        self.assertTrue(dataOut[9, 0] == 90)
        self.assertTrue(dataOut[9, 9] == 98)
        self.assertTrue(dataOut[0, 9] == 18)

        self.assertTrue(dataOut[0, 4] == 13)
        self.assertTrue(dataOut[9, 4] == 93)
        self.assertTrue(dataOut[4, 4] == 44)

        dataIn = numpy.array([0, -1, 1, 12, 6, -2, 100, 4, 12],
                             dtype=numpy.int16)
        dataIn = dataIn.reshape((3, 3))
        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=(3, 3),
                               conditionnal=False)
        self.assertTrue(dataOut.shape == dataIn.shape)
        self.assertTrue(dataOut[1, 1] == 4)
        self.assertTrue(dataOut[0, 0] == 6)
        self.assertTrue(dataOut[0, 1] == 1)
        self.assertTrue(dataOut[1, 0] == 6)
Beispiel #2
0
    def testInputDataIsNotModify(self):
        """Make sure input data is not modify by the median filter"""
        dataIn = numpy.arange(100, dtype=numpy.int32)
        dataIn = dataIn.reshape((10, 10))
        dataInCopy = dataIn.copy()

        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=(3, 3),
                               conditionnal=False)
        self.assertTrue(numpy.array_equal(dataIn, dataInCopy))
Beispiel #3
0
    def testFilterWidthOne(self):
        """Make sure a filter of one by one give the same result as the input"""
        dataIn = numpy.arange(100, dtype=numpy.int32)
        dataIn = dataIn.reshape((10, 10))

        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=(1, 1),
                               conditionnal=False)

        self.assertTrue(numpy.array_equal(dataIn, dataOut))
Beispiel #4
0
    def testFilter3(self):
        """Simple test of a three by three kernel median filter"""
        dataIn = numpy.arange(100, dtype=numpy.int32)

        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=5,
                               conditionnal=False)

        self.assertTrue(dataOut[0] == 1)
        self.assertTrue(dataOut[9] == 9)
        self.assertTrue(dataOut[99] == 98)
Beispiel #5
0
    def testTypes(self):
        for testType in [
                numpy.float32, numpy.float64, numpy.int16, numpy.uint16,
                numpy.int32, numpy.int64, numpy.uint64
        ]:

            data = numpy.random.rand(10, 10).astype(dtype=testType)
            out = medianfilter(input_buffer=data,
                               kernel_dim=(3, 3),
                               conditionnal=False)
            self.assertTrue(out.dtype.type is testType)
Beispiel #6
0
    def testFilter3(self):
        dataIn = numpy.arange(100, dtype=numpy.int32)
        dataIn = dataIn.reshape((10, 10))

        dataOut = medianfilter(input_buffer=dataIn,
                               kernel_dim=(3, 3),
                               conditionnal=True)

        self.assertTrue(dataOut[0, 0] == 10)
        self.assertTrue(dataOut[0, 1] == 1)
        self.assertTrue(numpy.array_equal(dataOut[1:8, 1:8], dataIn[1:8, 1:8]))
        self.assertTrue(dataOut[9, 9] == 98)
Beispiel #7
0
    def testThreads(self):
        """Make sure the result doesn't depends on the number of threads used"""
        dataIn = numpy.random.rand(100, 100)

        dataOut1Thr = medianfilter(input_buffer=dataIn,
                                   kernel_dim=(3, 3),
                                   conditionnal=False,
                                   nthread=1)
        dataOut2Thr = medianfilter(input_buffer=dataIn,
                                   kernel_dim=(3, 3),
                                   conditionnal=False,
                                   nthread=2)
        dataOut4Thr = medianfilter(input_buffer=dataIn,
                                   kernel_dim=(3, 3),
                                   conditionnal=False,
                                   nthread=4)
        dataOut8Thr = medianfilter(input_buffer=dataIn,
                                   kernel_dim=(3, 3),
                                   conditionnal=False,
                                   nthread=8)

        self.assertTrue(numpy.array_equal(dataOut1Thr, dataOut2Thr))
        self.assertTrue(numpy.array_equal(dataOut1Thr, dataOut4Thr))
        self.assertTrue(numpy.array_equal(dataOut1Thr, dataOut8Thr))
Beispiel #8
0
 def _computeFilteredImage(self, kernelWidth, conditional):
     assert(self.plot is not None)
     return medianfilter(self._originalImage,
                         (kernelWidth, kernelWidth),
                         conditional)