Direkt zum InhaltDirekt zur SucheDirekt zur Navigation
▼ Zielgruppen ▼

Humboldt-Universität zu Berlin - Faculty of Mathematics and Natural Sciences - Strukturforschung / Elektronenmikroskopie

Diffractogram.txt

// diffractorgram.s
//
// computes the evenly spaced diffractogram from an arbitrarily sized image

// The following 2 variables control the way the diffractogram id computed:
number padWithWholeImage = 0
number stretchDiffractogram = 1


realImage img

complexImage DoFFTw(image img)
{
number Nedge = 100
complexImage inImg
realImage imgSel
number top, left, bottom, right, width, height,sx,sy,w2,h2,sizeX,sizeY
string name

// get the size of the original image subsection:
img.GetSize(sizeX,sizeY)
img.GetSelection(top, left, bottom, right)

// get the size of the image:
width = right - left
height = bottom - top
h2 = height/2;
w2 = width/2;


if (padWithWholeImage) {
imgSel := RealImage("modified image",4,sizeX,sizeY)
imgSel[top,left,bottom,right] = img[]
imgSel.SetSelection(top, left, bottom, right)
}
else {
imgSel = img[]
imgSel.SetSelection(0,0, height, width)
}
// subtract the mean of the image from the image itself
number avg = mean(img[]);
imgSel[] -= avg;


if (Nedge > w2/2) {Nedge=w2/2; }
if (Nedge > h2/2) {Nedge=h2/2; }


// smoothen the edge of the image:
Image rampX = ExprSize(width,height,w2-abs(icol-w2))/Nedge
Image rampY = ExprSize(width,height,h2-abs(irow-h2))/Nedge

imgSel[] *= tert(rampX>1,1,0.5*(1-cos(Pi()*rampX)))*\
tert(rampY>1,1,0.5*(1-cos(Pi()*rampY)))
deleteimage(rampX)
deleteimage(rampY)

if (padWithWholeImage) {
width = sizeX;
height = sizeY;
}

if (stretchDiffractogram) {
if (width < height) width = height;
if (height < width) height = width;
}


// showimage(imgSel)

// create a new image and copy the original image into it.
// make sure that the parts of the new image that are not overwritten
// by the original, are filled with its average value
inImg := ComplexImage("real space Image", 8, width, height)
if (padWithWholeImage) {
inImg[0,0,sizeY,sizeX] = imgSel
}
else {
inImg[0,0,bottom-top,right-left] = imgSel
}

// compute the FFT and shift the center:
T_fft_C2C(inImg,inImg)
inImg = T_shiftImageCenterComplex(inImg)


// set origin, name and scale:
img.GetName(name)
inImg.setOrigin(floor(width/2)+0.5, floor(height/2)+0.5)
inImg.setName("FFT of " + name)
img.getScale(sx,sy)
inImg.setScale(1/(width*sx),1/(height*sy))
inImg.setUnitString("1/nm")


deleteImage(imgSel)

return inImg
}

if(!GetFrontImage(img))
{
okDialog("There is no Image.")
exit(0)
}

T_fft_SetEstimate()
showImage(DoFFTw(img))