Пример #1
0
    def updateNoise(self):
        """Updates the noise sample. Does not change any of the noise parameters 
            but choses a new random sample given the previously set parameters.
        """

        if not (self.noiseType in [
                'binary', 'Binary', 'normal', 'Normal', 'uniform', 'Uniform'
        ]):
            Ph = numpy.random.uniform(0, 2 * numpy.pi, int(self._size**2))
            Ph = numpy.reshape(Ph, (int(self._size), int(self._size)))
            In = self.noiseTex * exp(1j * Ph)
            Im = numpy.real(ifft2(In))
            Im = ifftshift(Im)
            gsd = filters.getRMScontrast(Im)
            factor = (gsd * self.noiseClip)
            numpy.clip(Im, -factor, factor, Im)
            self.tex = Im / factor
        elif self.noiseType in ['normal', 'Normal']:
            self.tex = numpy.random.randn(int(
                self._sideLength[1]), int(
                    self._sideLength[0])) / self.noiseClip
        elif self.noiseType in ['uniform', 'Uniform']:
            self.tex = 2.0 * numpy.random.rand(int(self._sideLength[1]),
                                               int(self._sideLength[0])) - 1.0
        else:
            numpy.random.shuffle(
                self.noiseTex)  # pick random noise sample by shuffleing values
            self.tex = numpy.reshape(
                self.noiseTex,
                (int(self._sideLength[1]), int(self._sideLength[0])))
Пример #2
0
    def updateNoise(self):
        """Updates the noise sample. Does not change any of the noise parameters but choses a new random sample given the previously set parameters.
        """

        if not(self.noiseType in ['binary','Binary','normal','Normal','uniform','Uniform']):
            Ph=numpy.random.uniform(0,2*numpy.pi,int(self._size**2))
            Ph=numpy.reshape(Ph,(int(self._size),int(self._size)))
            In=self.noiseTex*exp(1j*Ph)
            self.tex=numpy.real(ifft2(In))
            self.tex=ifftshift(self.tex)
            gsd=filters.getRMScontrast(self.tex)
            factor=(gsd*self.noiseClip)
            numpy.clip(self.tex,-factor,factor,self.tex)
            self.tex=self.tex/factor
        else:
            numpy.random.shuffle(self.noiseTex)  # pick random noise sample by shuffleing values
            self.tex=numpy.reshape(self.noiseTex,(int(self._sideLength[1]),int(self._sideLength[0]))) #reshape to sqaure
Пример #3
0
    def updateNoise(self):
        """Updates the noise sample. Does not change any of the noise parameters 
            but choses a new random sample given the previously set parameters.
        """

        if not(self.noiseType in ['binary','Binary','normal','Normal','uniform','Uniform']):
            if (self.noiseType in ['image', 'Image']) and (self.imageComponent in ['amplitude','Amplitude']):
                self.noiseTex = numpy.random.uniform(0,1,int(self._size**2))
                self.noiseTex = numpy.reshape(self.noiseTex,(int(self._size),int(self._size)))
                if self.filter in ['Butterworth','butterworth']:
                    self.noiseTex = fftshift(self._filter(self.noiseTex))
                elif self.filter in ['Gabor','gabor']:
                    self.noiseTex = fftshift(self._gabor(self.noiseTex))
                elif self.filter in ['Isotropic','isotropic']:
                    self.noiseTex = fftshift(self._isotropic(self.noiseTex))
                self.noiseTex[0][0] = 0
                In = self.noiseTex * exp(1j*self.noisePh)
                Im = numpy.real(ifft2(In))
            else:
                Ph = numpy.random.uniform(0,2*numpy.pi,int(self._size**2))
                Ph = numpy.reshape(Ph,(int(self._size),int(self._size)))
                In = self.noiseTex * exp(1j*Ph)
                Im = numpy.real(ifft2(In))
                Im = ifftshift(Im)
            gsd = filters.getRMScontrast(Im)
            factor = gsd*self.noiseClip
            numpy.clip(Im, -factor, factor, Im)
            self.tex = Im / factor
        elif self.noiseType in ['normal','Normal']:
            self.noiseTex = numpy.random.randn(int(self._sideLength[1]),int(self._sideLength[0])) / self.noiseClip
        elif self.noiseType in ['uniform','Uniform']:
            self.noiseTex = 2.0 * numpy.random.rand(int(self._sideLength[1]),int(self._sideLength[0])) - 1.0
        else:
            numpy.random.shuffle(self.noiseTex)  # pick random noise sample by shuffleing values
            self.noiseTex = numpy.reshape(self.noiseTex,(int(self._sideLength[1]),int(self._sideLength[0])))
        if self.noiseType in ['binary','Binary','normal','Normal','uniform','Uniform']:
            if self.filter in ['butterworth', 'Butterworth', 'Gabor','gabor','Isotropic','isotropic']:
                if self.units == 'pix':
                    if self._size[0] == self._size[1]:
                        baseImage = numpy.array(
                                Image.fromarray(self.noiseTex).resize(
                                        (int(self._size[0]), int(self._size[1])),
                                        Image.NEAREST
                                )
                        )
                    else:
                        msg = ('NoiseStim can only apply filters to square noise images')
                        raise ValueError(msg)
                else:
                    baseImage = numpy.array(
                            Image.fromarray(self.noiseTex).resize(
                                    (int(self._size), int(self._size)),
                                    Image.NEAREST
                            )
                    )
                baseImage = numpy.array(baseImage).astype(
                        numpy.float32) * 0.0078431372549019607 - 1.0
                FT = fft2(baseImage)
                spectrum = numpy.absolute(fftshift(FT))
                angle = numpy.angle(FT)
                if self.filter in ['butterworth','Butterworth']:
                    spectrum = fftshift(self._filter(spectrum))
                elif self.filter in ['isotropic','Isotropic']:
                    spectrum = fftshift(self._isotropic(spectrum))
                elif self.filter in ['gabor','Gabor']:
                    spectrum = fftshift(self._gabor(spectrum))
                spectrum[0][0] = 0 # set DC to zero
                FT = spectrum * exp(1j*angle)
                
                Im = numpy.real(ifft2(FT))
                gsd = filters.getRMScontrast(Im)
                factor = gsd*self.noiseClip
                numpy.clip(Im, -factor, factor, Im)
                self.tex = Im / factor
            else:
                if not(self.noiseType in ['image','Image']):
                    self.tex = self.noiseTex
Пример #4
0
    def updateNoise(self):
        """Updates the noise sample. Does not change any of the noise parameters 
            but choses a new random sample given the previously set parameters.
        """

        if not(self.noiseType in ['binary','Binary','normal','Normal','uniform','Uniform']):
            if (self.noiseType in ['image', 'Image']) and (self.imageComponent in ['amplitude','Amplitude']):
                self.noiseTex = numpy.random.uniform(0,1,int(self._size**2))
                self.noiseTex = numpy.reshape(self.noiseTex,(int(self._size),int(self._size)))
                if self.filter in ['Butterworth','butterworth']:
                    self.noiseTex = fftshift(self._filter(self.noiseTex))
                elif self.filter in ['Gabor','gabor']:
                    self.noiseTex = fftshift(self._gabor(self.noiseTex))
                elif self.filter in ['Isotropic','isotropic']:
                    self.noiseTex = fftshift(self._isotropic(self.noiseTex))
                self.noiseTex[0][0] = 0
                In = self.noiseTex * exp(1j*self.noisePh)
                Im = numpy.real(ifft2(In))
            else:
                Ph = numpy.random.uniform(0,2*numpy.pi,int(self._size**2))
                Ph = numpy.reshape(Ph,(int(self._size),int(self._size)))
                In = self.noiseTex * exp(1j*Ph)
                Im = numpy.real(ifft2(In))
                Im = ifftshift(Im)
            gsd = filters.getRMScontrast(Im)
            factor = gsd*self.noiseClip
            numpy.clip(Im, -factor, factor, Im)
            self.tex = Im / factor
        elif self.noiseType in ['normal','Normal']:
            self.noiseTex = numpy.random.randn(int(self._sideLength[1]),int(self._sideLength[0])) / self.noiseClip
        elif self.noiseType in ['uniform','Uniform']:
            self.noiseTex = 2.0 * numpy.random.rand(int(self._sideLength[1]),int(self._sideLength[0])) - 1.0
        else:
            numpy.random.shuffle(self.noiseTex)  # pick random noise sample by shuffleing values
            self.noiseTex = numpy.reshape(self.noiseTex,(int(self._sideLength[1]),int(self._sideLength[0])))
        if self.noiseType in ['binary','Binary','normal','Normal','uniform','Uniform']:
            if self.filter in ['butterworth', 'Butterworth', 'Gabor','gabor','Isotropic','isotropic']:
                if self.units == 'pix':
                    if self._size[0] == self._size[1]:
                        baseImage = imresize(self.noiseTex, (int(self._size[0]),int(self._size[1])), interp='nearest')
                    else:
                        msg = ('NoiseStim can only apply filters to square noise images')
                        raise ValueError(msg)
                else: 
                    baseImage = imresize(self.noiseTex, (int(self._size),int(self._size)), interp='nearest')
                baseImage = numpy.array(baseImage).astype(
                        numpy.float32) * 0.0078431372549019607 - 1.0
                FT = fft2(baseImage)
                spectrum = numpy.absolute(fftshift(FT))
                angle = numpy.angle(FT)
                if self.filter in ['butterworth','Butterworth']:
                    spectrum = fftshift(self._filter(spectrum))
                elif self.filter in ['isotropic','Isotropic']:
                    spectrum = fftshift(self._isotropic(spectrum))
                elif self.filter in ['gabor','Gabor']:
                    spectrum = fftshift(self._gabor(spectrum))
                spectrum[0][0] = 0 # set DC to zero
                FT = spectrum * exp(1j*angle)
                
                Im = numpy.real(ifft2(FT))
                gsd = filters.getRMScontrast(Im)
                factor = gsd*self.noiseClip
                numpy.clip(Im, -factor, factor, Im)
                self.tex = Im / factor
            else:
                if not(self.noiseType in ['image','Image']):
                    self.tex = self.noiseTex