Ejemplo n.º 1
0
def FFT3D(array):
    """Returns the FFT of a three dimensional array
	
	This method can be used to obtain the FFT of a three dimensional array.
	"""
    import FFT
    N1, N2, N3 = array.shape
    return FFT.fft(FFT.fft2d(array, (N1, N2), axes=(0, 1)), N3, axis=2)
Ejemplo n.º 2
0
def filter2d_freq(img, the_filter):
    height = len(img)
    width = len(img[0])
    adjust_height = calculate_pow2(height)
    adjust_width  = calculate_pow2(width)

    FFT_filter = np.zeros((adjust_height,adjust_width), np.int32)
    adjust_img = np.zeros((adjust_height,adjust_width), np.int32)

    for x in xrange(height):
        for y in xrange(width):
            adjust_img[x, y] = img[x, y]

    for x in xrange(len(the_filter)):
        for y in xrange(len(the_filter[0])):
            FFT_filter[x, y] = the_filter[x, y]

    FFT_filter = FFT.centralize(FFT_filter)
    adjust_img = FFT.centralize(adjust_img)

    FFT_filter = FFT.fft2d(FFT_filter, 1)
    FFT_image = FFT.fft2d(adjust_img, 1)

    print "done Fourier transform"

    Result = FFT_image * FFT_filter

    print "done frequecy processing"

    Result = FFT.fft2d(Result, -1).real

    print "done Inverse Fourier transform"

    Result_img = np.zeros((height, width), np.float64)

    Result = diolog_transform(Result)

    for x in xrange(height):
        for y in xrange(width):
            Result_img[x, y] = Result[x, y]

    Result_img = centralize(Result_img)

    return Result_img
Ejemplo n.º 3
0
    def execute_cb( self, *args ):
	layer = gview.app.sel_manager.get_active_layer()
	if not layer_is_raster(layer):
	    gvutils.error("Please select a raster layer.");
	    return
	ds = layer.get_parent().get_dataset()
	data = gdalnumeric.DatasetReadAsArray(ds)

	if self.switch_forward.get_active():
	    data_tr = FFT.fft2d(data)
	else:
	    data_tr = FFT.inverse_fft2d(data)

	array_name = gdalnumeric.GetArrayFilename(data_tr)
	if self.switch_new_view.get_active():
	    gview.app.new_view()
	gview.app.file_open_by_name(array_name)
Ejemplo n.º 4
0
    def execute_cb(self, *args):
        layer = gview.app.sel_manager.get_active_layer()
        if not layer_is_raster(layer):
            gvutils.error("Please select a raster layer.")
            return
        ds = layer.get_parent().get_dataset()
        data = gdalnumeric.DatasetReadAsArray(ds)

        if self.switch_forward.get_active():
            data_tr = FFT.fft2d(data)
        else:
            data_tr = FFT.inverse_fft2d(data)

        array_name = gdalnumeric.GetArrayFilename(data_tr)
        if self.switch_new_view.get_active():
            gview.app.new_view()
        gview.app.file_open_by_name(array_name)
Ejemplo n.º 5
0
    else:
        Usage()

    i = i + 1

if infile is None:
    Usage()
if outfile is None:
    Usage()

if type == None:
    type = gdal.GDT_CFloat32

indataset = gdal.Open(infile, gdal.GA_ReadOnly)

out_driver = gdal.GetDriverByName(format)
outdataset = out_driver.Create(outfile, indataset.RasterXSize,
                               indataset.RasterYSize, indataset.RasterCount,
                               type)

for iBand in range(1, indataset.RasterCount + 1):
    inband = indataset.GetRasterBand(iBand)
    outband = outdataset.GetRasterBand(iBand)

    data = inband.ReadAsArray(0, 0)
    if transformation == 'forward':
        data_tr = FFT.fft2d(data)
    else:
        data_tr = FFT.inverse_fft2d(data)
    outband.WriteArray(data_tr)
Ejemplo n.º 6
0
def main(argv):
    infile = None
    outfile = None
    frmt = 'GTiff'
    typ = None
    transformation = 'forward'

    # Parse command line arguments.
    i = 1
    while i < len(argv):
        arg = argv[i]

        if arg == '-inv':
            transformation = 'inverse'
            if typ is None:
                typ = gdal.GDT_Float32

        elif arg == '-of':
            i = i + 1
            frmt = argv[i]

        elif arg == '-ot':
            i = i + 1
            typ = ParseType(argv[i])
            # set_type = 'yes'

        elif infile is None:
            infile = arg

        elif outfile is None:
            outfile = arg

        else:
            return Usage()

        i = i + 1

    if infile is None:
        return Usage()
    if outfile is None:
        return Usage()

    if typ is None:
        typ = gdal.GDT_CFloat32

    indataset = gdal.Open(infile, gdal.GA_ReadOnly)

    out_driver = gdal.GetDriverByName(frmt)
    outdataset = out_driver.Create(outfile, indataset.RasterXSize,
                                   indataset.RasterYSize,
                                   indataset.RasterCount, typ)

    for iBand in range(1, indataset.RasterCount + 1):
        inband = indataset.GetRasterBand(iBand)
        outband = outdataset.GetRasterBand(iBand)

        data = inband.ReadAsArray(0, 0)
        if transformation == 'forward':
            data_tr = FFT.fft2d(data)
        else:
            data_tr = FFT.inverse_fft2d(data)
        outband.WriteArray(data_tr)
    return 0
Ejemplo n.º 7
0
    else:
        Usage()

    i = i + 1

if infile is None:
    Usage()
if  outfile is None:
    Usage()

if type == None:
    type = GDT_CFloat32

indataset = gdal.Open( infile, GA_ReadOnly )

out_driver = gdal.GetDriverByName(format)
outdataset = out_driver.Create(outfile, indataset.RasterXSize, indataset.RasterYSize, indataset.RasterCount, type)

for iBand in range(1, indataset.RasterCount + 1):
    inband = indataset.GetRasterBand(iBand)
    outband = outdataset.GetRasterBand(iBand)

    data = inband.ReadAsArray(0, 0)
    if transformation == 'forward':
        data_tr = FFT.fft2d(data)
    else:
        data_tr = FFT.inverse_fft2d(data)
    outband.WriteArray(data_tr)

Ejemplo n.º 8
0
def espectrofourier(img, libdir, ts, frings, fsectors, raios, angulos):
	M,N = img.shape[0], img.shape[1]
	d = min(M,N) # dimensao menor das imagens
	ci, cj = M/2, N/2 # coordenadas do centro da img
	rmax = d/2 # raio maximo da circ. que cabe na img
	slices = []
	desc = []
	
	F = FFT.fft2d(img)
	Fview = iadftview(F) # passar threshold aqui!
	
	# threshold realizado com dinamica - valores de extinção:
	#iawrite(Fview,'../tmp/fv.pgm')
	#os.system('%s./extinction htop ../tmp/fv.pgm ../tmp/result.pgm' % (libdir)) 
	#Fvd = iaread('../tmp/result.pgm')
	#iashow(Fv)
	
	#Fvd = (Fvd>1)*Fview
	#iawrite(Fv,'../tmp/fv2.pgm')
	
	
	#iashow(dimask)
	#nz = nonzeroarea(dimask)
	#print nz
	#print "soma de tudo = "+str(nz.sum())
	#ts = nz.sum()/nz.shape[0]
	#print ts
	#iashow(Fview)
	# threshold simples:
	#Fv = Fview
	Fv = Fview * (Fview > ts)
	#iashow(Fv)
	#a = raw_input()
	
	# em seguida é cortado o lado direito da imagem do espectro
	if M>N: # se a imagem for mais alta que larga:
		rightside = iaroi(Fv,[abs(ci-rmax),cj],[(ci+rmax-1),N])
		#rightsided = iaroi(Fvd,[abs(ci-rmax),cj],[(ci+rmax-1),N])
	
	elif N>M: # se for mais larga que alta:
		rightside = iaroi(Fv,[0,cj],[M-1,(cj+rmax-1)])
		#rightsided = iaroi(Fvd,[0,cj],[M-1,(cj+rmax-1)])
	
	else: # se for quadrada:
		rightside = iaroi(Fv,[0,cj],[M,N])
		#rightsided = iaroi(Fvd,[0,cj],[M,N])
	
	# carrega uma lista com templates para setores
	for ang in angulos:
			file = "../imgs/templates/%d.pbm" % (ang)
			slices.append(iaread(file))
	
	
	for r in raios:		
		circ = iacircle([d,d],r,[rmax,rmax])
		circ = iaroi(circ,[0,rmax],[d,d]) # recorta lado direito do circulo
		circ2 = iacircle([d,d],50,[rmax,rmax])
		circ2 = iaroi(circ2,[0,rmax],[d,d]) 
		ring = circ-circ2 # diminui circulo maior pelo menor para formar anel
		
		if frings == "yes":
			# quantidade de pixels do anel
			qtd = ring.sum()
			
			# aplica a mascara para o anel inteiro
			rough = rightside*ring 
			#roughd = rightsided*ring
		
			# calcular só p/ valores não-zero
			#nz = nonzeroarea(roughd)
			
			mean = rough.sum()/float(qtd)
			std = sqrt(((rough - mean)**2).sum()/qtd)
			desc += [std,mean]
			#desc += [nz.sum()]
				
		# media e desvio padrão dos setores	
		if fsectors == "yes":
			for slice in slices:
				sector = slice*ring
				qtd = sector.sum()
				area = rightside*sector
				#aread = rightsided*sector
				#nz = nonzeroarea(aread)
				mean = area.sum()/float(qtd)
				std = sqrt(((area - mean)**2).sum()/qtd)
				#
				desc += [std,mean]
				#desc += [nz.sum()]
		
	return desc