Search code examples
dm-script

What's the center of FFT image in dm-script


I'd like to draw a circle in FFT image, and the circle center is image center. The first issue I faced is what's the center of this FFT image. If I used the code below to get the center of FFT image, let's assume 4096*4096, the img_origin is 2048.5. Since the image coordinate starts from 0,0, why it's not 2047.5? Even if the image coordinate starts from 1,1, it should be 2048.

Number img_pixel_size, img_origin
String img_pixel_size_unit
Image img := GetFrontImage()
img.ImageGetDimensionCalibration(0, img_origin, img_pixel_size, img_pixel_size_unit, 1)
Result(img_origin)

Solution

  • This is better answered by looking at smaller images, say 4x4. See the result of the following examples script:

    number size = 4
    image img := RealImage("Real",4,size, size)
    img = 10
    image fftimg := realFFT(img)
    fftimg.ShowImage()
    
    Number img_pixel_size, img_origin
    String img_pixel_size_unit
    fftimg.ImageGetDimensionCalibration(0, img_origin, img_pixel_size, img_pixel_size_unit, 1)
    Result("\n Origin:" + img_origin)
    
    number r = 1
    component circle = NewOvalAnnotation(size/2-r,size/2-r,size/2+r,size/2+r)
    circle.ComponentSetForegroundColor(1,0,0)
    circle.ComponentSetDrawingMode(2)
    circle.ComponentSetFillMode(2)
    fftimg.ImageGetImageDisplay(0).ComponentAddChildAtEnd( circle )
    
    component circle2 = NewOvalAnnotation(img_origin-r,img_origin-r,img_origin+r,img_origin+r)
    circle.ComponentSetForegroundColor(0,1,0)
    circle2.ComponentSetDrawingMode(2)
    circle2.ComponentSetFillMode(2)
    fftimg.ImageGetImageDisplay(0).ComponentAddChildAtEnd( circle2 )
    

    4x4

    Any picture consists of finitely sized areas (pixels) which represent the value of a mathematical (dimensionless) point. In a coordinate system, it is then up to a convention where within the pixel-area this point lies. Two commonly used conventions are a) in the centre of this area or b) in the "origin" of this area.

    DigitalMicrograph uses the latter. It also counts the y-axis from top to bottom. Hence, DigitalMicrograph has the convention of the "point value" belonging to the top-left corner of a pixel.

    For an even-sizes image (like 4x4) the 0-th order coefficient of the FT (representing the constant value) is stored in the "central" pixel at index [size/2 x size/2] or in this case at (2/2) (i.e. the 3rd row and 3rd column) as can be seen as the white pixel. Drawing a circle around the image centre (green) is mathematically correct, but not very pleasing to the eye. (The brain has a very hard time to "centre" a value in the top-left corner of a square area.) Therefore the calibration-origin is given as the centre of the pixel instead, allowing for drawing around it like the red circle.

    In case of an uneven image (say 3x3) which is far less frequent in image analysis, the 0-th order coefficient of the FT is stored at [(size+1)/2 x (size+1)/2] or (1/1) in this case (2nd pixel, 2nd row).