예제 #1
0
파일: dft.py 프로젝트: PhloxAR/PhloxAR
    def low_pass(cls, xco, yco=None, size=(64, 64)):
        """
        Create a low pass filter of given size.
        :param xco: x cutoff
                    (int) horizontal cutoff frequency
                    (list) provide a list of three cut off frequencies
                    to create a 3 channel filter
        :param yco: y cutoff
                    (int) vertical cutoff frequency
                    (list) provide a list of three cutoff frequencies
                    to create a 3 channel filter
        :param size: size of the filter (width, height)
        :return: DFT filter
        """
        if isinstance(xco, list):
            if len(xco) != 3 and len(xco) != 1:
                warnings.warn("xco list must be of size 3 or 1")
                return None
            if isinstance(yco, list):
                if len(yco) != 3 and len(yco) != 1:
                    warnings.warn("yco list must be of size 3 or 1")
                    return None
                if len(yco) == 1:
                    yco = [yco[0]] * len(xco)
            else:
                yco = [yco] * len(xco)

            stacked_filter = DFT()

            for xfreq, yfreq in zip(xco, yco):
                stacked_filter = stacked_filter._stack_filters(cls.low_pass(
                        xfreq, yfreq, size))

            image = PhloxAR.core.image.Image(stacked_filter._narray)
            ret = DFT(narray=stacked_filter._narray, image=image,
                         xco_low=xco, yco_low=yco, channels=len(xco), size=size,
                         type=stacked_filter._type, order=cls._order,
                         fpass=stacked_filter._fpass)
            return ret

        w, h = size
        xco = np.clip(int(xco), 0, w / 2)

        if yco is None:
            yco = xco

        yco = np.clip(int(yco), 0, h / 2)
        flt = np.zeros((w, h))
        flt[0:xco, 0:yco] = 255
        flt[0:xco, h - yco:h] = 255
        flt[w - xco:w, 0:yco] = 255
        flt[w - xco:w, h - yco:h] = 255
        img = PhloxAR.core.image.Image(flt)
        lowpass_filter = DFT(size=size, narray=flt, image=img, type="lowpass",
                      xco_low=xco, yco_low=yco, fpass="******")
        return lowpass_filter
예제 #2
0
파일: dft.py 프로젝트: PhloxAR/PhloxAR
    def band_pass(cls, xco_low, xco_high, yco_low=None, yco_high=None,
                  size=(64, 64)):
        """
        Create a band filter of given size and order.
        Creates a high pass filter of given size and order.
        :param xco_low: (int) horizontal cutoff frequency
                        (list) provide a list of three cut off frequencies
                        to create a 3 channel filter
        :param yco: (int) vertical cutoff frequency
                    (list) provide a list of three cutoff frequencies
                    to create a 3 channel filter
        :param size: size of the filter (width, height)
        :return: DFT filter
        """

        lowpass = cls.low_pass(xco_low, yco_low, size)
        highpass = cls.high_pass(xco_high, yco_high, size)
        lowpassnumpy = lowpass.narray
        highpassnumpy = highpass.narray
        bandpassnumpy = lowpassnumpy + highpassnumpy
        bandpassnumpy = np.clip(bandpassnumpy, 0, 255)

        img = PhloxAR.core.image.Image(bandpassnumpy)
        bandpass = DFT(size=size, image=img, narray=bandpassnumpy,
                       type="bandpass", xco_low=xco_low, yco_low=yco_low,
                       xco_high=xco_high, yco_high=yco_high, fpass="******",
                       channels=lowpass.channels)

        return bandpass