5 de set. de 2010

Script Python para cortar todas imagens em um arquivo e salvar

'''
Created on 05/09/2010
@author: tiago buriol
'''
import os
import Image  # PIL - Python Image Library (instale via Sinaptyc)

diretorio = "/home/buriol/PYTHON_PROJECTS/CILAMCE2010/src/ReconstrCROPPED"
arquivos = os.listdir(diretorio)
arquivos.sort()  #ordena os arquivos pelo nome
n=0

# Corta imagens e salva
for arquivo in arquivos:
    fullpath = os.path.join(diretorio,arquivo)
    if os.path.isfile(fullpath):
        n = n + 1
        img = Image.open(fullpath)
        print "Lendo arquivo", n, "de", len(arquivos)
        im =  img.crop([0,0,128,128])
        im.save(os.path.join("/home/buriol/Imagens",arquivo), "BMP")

Visualizando tensores como elipsóides usando VTK e Python

# Biblioteca vtk para python
from vtk import *

# ENTRADA DE DADOS
# Pontos
points = vtkPoints()
points.SetNumberOfPoints(3)
points.InsertPoint(0,76.3221,77.55,6.51956)
points.InsertPoint(1,76.61,77.2565,6.48612)
points.InsertPoint(2,77.2707,76.61,6.44554)
# Tensores
dbar = vtkDoubleArray()
dbar.SetNumberOfTuples(3)
dbar.SetNumberOfComponents(9)
dbar.InsertTuple9(0,-1.15233,0.0831558,0.0469417,0.0831558,-1.25721,0.10167,0.0469417,0.10167,-1.10715)
dbar.InsertTuple9(1,-1.18056,0.0817272,0.016076,0.0817272,-1.32675,0.125833,0.016076,0.125833,-1.15438)
dbar.InsertTuple9(2,-1.18056,0.0817272,0.016076,0.0817272,-1.32675,0.125833,0.016076,0.125833,-1.15438)

# PROCESSAMENTO PARA GERAR OS GLIFOS
# Polydata
indata = vtkPolyData()
indata.SetPoints(points)
indata.GetPointData().SetTensors(dbar)
# Codigo para uma esfera
src = vtkSphereSource()
src.SetThetaResolution(16)
src.SetPhiResolution(16)
# glifos
epp = vtkTensorGlyph()
epp.SetInput(indata)
epp.SetSourceConnection(src.GetOutputPort())
epp.SetScaleFactor(1)
epp.ClampScalingOn()
#epp.SymmetricOn()
epp.ColorGlyphsOff()
epp.ThreeGlyphsOff()
epp.ExtractEigenvaluesOn()
epp.SetColorModeToEigenvalues()
# Mapeador para os dados
map = vtkPolyDataMapper()
map.SetInputConnection(epp.GetOutputPort())

# VISUALIZACAO
# Ator
elactor = vtkActor()
elactor.SetMapper(map)
# Renderizador
renderer = vtkRenderer()
renderer.AddActor(elactor)
# Janela
renderWindow = vtkRenderWindow()
renderWindow.AddRenderer( renderer )
# Interador
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
interactor.Initialize()
interactor.Start()