| 1 |
#from ex import Lattice,ReciprocalUnitCell,SpatialUnitCell |
|---|
| 2 |
#from ex.gui import LatticeOverlay,UnitCellOverlay |
|---|
| 3 |
#from alg import FFT,Conjugate,PeakSearch,HighPassFilter |
|---|
| 4 |
#from iplt import PeakList |
|---|
| 5 |
#from ex.alg import LatticeFilter, GaussianLatticeFilter |
|---|
| 6 |
|
|---|
| 7 |
from ost.geom import * |
|---|
| 8 |
from ost.io import LoadImage,SaveImage |
|---|
| 9 |
from ost.img import * |
|---|
| 10 |
from ost.img.alg import * |
|---|
| 11 |
from iplt import Lattice,ReciprocalUnitCell,SpatialUnitCell |
|---|
| 12 |
from iplt.alg import * |
|---|
| 13 |
from iplt.gui import LatticeOverlay,UnitCellOverlay |
|---|
| 14 |
from ost.gui import PointlistOverlay |
|---|
| 15 |
|
|---|
| 16 |
def ShowPeaks(viewer,peaklist): |
|---|
| 17 |
peak_overlay=PointlistOverlay() |
|---|
| 18 |
peak_overlay.Add(PointList(peaklist)) |
|---|
| 19 |
viewer.AddOverlay(peak_overlay) |
|---|
| 20 |
|
|---|
| 21 |
def CorrelationAverage(image,peaklist,width,height): |
|---|
| 22 |
result=CreateImage(Size(width,height)) |
|---|
| 23 |
result.SetSpatialSampling(image.GetSpatialSampling()) |
|---|
| 24 |
for p in peaklist: |
|---|
| 25 |
itmp=image.Extract(Extent(Size(width,height),p)) |
|---|
| 26 |
itmp.SetSpatialOrigin(Point(0,0)) |
|---|
| 27 |
result+=itmp |
|---|
| 28 |
return result |
|---|
| 29 |
|
|---|
| 30 |
def CreateLatticeFromUnitCell(uc,sampling): |
|---|
| 31 |
return Lattice(uc.GetVecA()/sampling[0],uc.GetVecB()/sampling[1]) |
|---|
| 32 |
|
|---|
| 33 |
def FilterPeaklist(peaklist,real_lattice,rel_dis): |
|---|
| 34 |
result=PeakList() |
|---|
| 35 |
for p in peaklist: |
|---|
| 36 |
comp=real_lattice.CalcComponents(p) |
|---|
| 37 |
dx=abs(comp[0]-round(comp[0])) |
|---|
| 38 |
dy=abs(comp[0]-round(comp[0])) |
|---|
| 39 |
if rel_dis*rel_dis>dx*dx+dy*dy: |
|---|
| 40 |
result.push_back(p) |
|---|
| 41 |
return result |
|---|
| 42 |
|
|---|
| 43 |
def CrossCorrelate(im,ref): |
|---|
| 44 |
imfft=im.Apply(alg.DFT()) |
|---|
| 45 |
reffft=ref.Apply(alg.DFT()) |
|---|
| 46 |
reffft.ApplyIP(alg.Conj()) |
|---|
| 47 |
result=imfft*reffft |
|---|
| 48 |
result.ApplyIP(alg.DFT()) |
|---|
| 49 |
return result |
|---|