// HanningWindow // // last modified 10-Sept-2002 RTH // // Applies a Hanning window to a selected image or // simply creates a Hanning window. // The Hanning window is important to determine // the position of peaks in Fourier space // with sub-pixel accuracy. // For more details on Hanning windows see: // W.J. deRuijter, J. Comp. Assist. Microsc., 6 (1994) p195. // // // number size, sizeX, sizeY, top, left, bottom, right, ii, posX, posY number zoom, test image front, hannX, hannY, hann, out if(TwoButtonDialog("Create Hanning window or\n apply Hanning window\n to topmost image?", "Apply", "create")) { front := GetFrontImage(); GetSize(front, sizeX, sizeY); GetSelection(front, top, left, bottom, right); GetWindowPosition(front, posX, posY); zoom = GetZoom(front); // // test if image/selection is square and of the power of two // if((right-left) != bottom - top) Throw( "Only for square images (selections) of the power of two!" ); test = bottom - top; while( test / 2 >= 1 ) test = test/2; if( test != 1 ) Throw( "Only for square images (selections) of the power of two!" ); // // Create Hanning window // ii = 1; hannX := CreateFloatImage("", (right-left), (bottom-top)); hannX = 0; hannX[0, 0, 1, (right-left)] = 1 - cos( 2 * Pi() * icol / (right-left)); while( ii < (right-left) ) { hannX[ii, 0, 2*ii, (right-left)] = hannX[0, 0, ii, (right-left)] ii = ii * 2 } // hannY = hannX; RotateLeft(hannY); hann = hannX * hannY // // Display image // out = front[top, left, bottom, right] * hann; SetName(out, GetName(front) + "H"); DisplayAt(out, posX + 14, posY + 21); } else { size = 256; getNumber("Size of Hanning window?", size, size) hannX := CreateFloatImage("", size, size); hannX = 0; hannX[0,0,1,size] = 1 - cos( 2 * Pi() * icol / size); ii = 1; while( ii < size ) { hannX[ii, 0, 2*ii, size] = hannX[0, 0, ii, size]; ii = ii * 2; } hannY = hannX; RotateLeft(hannY); hann = hannX * hannY; SetName(hann, "Hanning window") ShowImage(hann); }