Skip to main content

Posts

Showing posts with the label Example

Simple Pushbuttons UI Template for dm-script

 // Pushbutton UI template // // 2021/04/21 // Renfong class UI_Handler : object { number true, false number UIObjectID void SetUIObjectID(object self, number id) { UIObjectID = id }; UI_Handler(object self) { true = 1; false = 0 result("Obect \"UI_Handler\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~UI_Handler(object self) { true = 1; false = 0 result("Obect\"UI_Handler\" ["+self.ScriptObjectGetID()+"] deconstructed. \n") }; void btn1response(object self) { OKdialog("This is a template") }; }; class MainUI : UIFrame { TagGroup btn1 object UI_Handler number true, false, ver MainUI(object self){ true = 1; false = 0; ver=0.1; UI_Handler = alloc(UI_Handler) result("Obect \"MainUI\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~MainUI(object self){ result("Obect \"MainUI\" ["+self.Scr...

Drift correction in Matlab

In order to improve S/N ratio, microscopist uses several short acquisition time images, and then sum them up. So the drift correction is very important. Here is the demo of how to use Matlab do drift correction. In the first, load an image, and using circshift function to shift the object in the image. Then use fft cross correlation to compute the moving distance. Finally, shift the object to the origial position. Here is the testing code: == % Demo of drift correction % 2018/11/15  by Renfong im1= imread('cameraman.tif');    % reference image [sy,sx]=size(im1); % shift the object im2=circshift(im1,[20,10]);    % the object moved down 20 pixels and moved right 10 pixels. figure(1); subplot(121);imshow(im1); subplot(122);imshow(im2); % Using fft cross correlations to detect the moving distance[1] fftim1=fft2(im1); fftim2=fft2(im2); cc=fftshift(ifft2(fftim1.*conj(fftim2))); [shiftY,shiftX]=find(cc==max(cc(:))...

Some test for Top-hat filter

1. Peak standard deviation:     Set the peak std for 1, 2.5, 5, 10 and 20. After std=10, the signals are difficult to identify. 2. Noise:     Set different noise for 0%, 25%, 50%, 75% and 100%. The peaks are hard to identify from 75% noise. 3. Different THF signal window:     Set the noise to 100% and use the different signal window to identify the signal. The result shows the wider window can improve the peak identification. Summary: The THF can help us to identify the weak signal from the high exponential background. It is noted that the S/N ratio would affect the THF result. If we want to identify the rare element in the material, we may use the high S/N ratio spectrum for applying THF or using the large signal window for noisy data.

Mask creation

// A practice to create mask by built-in function // iradius, itheta, tert image img:=RealImage("Mask",4,256,256) // for STEM equivalent detector image BF, ABF, LAADF, HAADF BF=img*0 BF=(iradius<10) BF.SetName("BF") ABF=img*0 ABF=(iradius>=10 & iradius<20) ABF.SetName("ABF") LAADF=img*0 LAADF=(iradius>=60 & iradius <80) LAADF.SetName("LAADF") HAADF=img*0 HAADF=(iradius>=100 & iradius<135) HAADF.SetName("HAADF") BF.ShowImage() ABF.ShowImage() LAADF.ShowImage() HAADF.ShowImage() // for DPC detector, 4 segment // set rotate angle number ang=15 if(ang>=90) { ang=0 } ang=pi()*ang/180 // Note that the itheta is varied counterclockwise from 0 to -pi() when y>0  //                                                        and clockwise from 0 to +pi() when y<0  ...

Practice of dm-script build-in function: icol & calibration information

Using icol function to create peak. Gaussian peak I=A*exp((x-mu)^2/(2*sigma^2) where mu is the peak center            sigma is the divergence of the peak -- image img=RealImage("peak",4,1024,1) //  peak 1 parameters // N_K edge number int1=30 number mu1=300 number sig1=5 // peak 2 parameters // O_K edge number int2=150 number mu2=432 number sig2=0.9 number int3=50 number mu3=438 number sig3=2.5 // add noise number noise=0.5 // EELS signal creation img=int1*exp(-1*(icol-mu1)**2/(2*sig1**2)) img+=int2*exp(-1*(icol-mu2)**2/(2*sig2**2)) img+=int3*exp(-1*(icol-mu3)**2/(2*sig3**2)) img+=0.05*exp(10-icol/100)+noise*int1*random() // Write calibration img.ImageSetDimensionOrigin(0,100) img.ImageSetDimensionScale(0,1) img.ImageSetDimensionUnitString(0, "eV" ) img.ImageSetIntensityUnitString( "e-" ) img.setname("Test Spec + " + noise*100 + "% noise") img.showimage() -- Result