Skip to main content

Posts

Showing posts from November, 2018

Image binng in matlab

Here are my own image binning codes. The first one was built on 2015/3/2. And the second one was written on 2018/11/5. I think I have a big improvement. Ha~ ==== function [ox,oy]=binning(x,y,nbins) % This function is used to bin data to average %  % x: x-axis data % y: y-axis data % nbins: binning factor % % 2015/03/02  % Renfong m=max(size(x)); n0=fix(m/nbins); n1=mod(m,nbins); if n1==0 ox=zeros(n0,1); oy=zeros(n0,1); for ii=1:n0 for jj=1:nbins ox(ii)=ox(ii)+x((ii-1)*nbins+jj); oy(ii)=oy(ii)+y((ii-1)*nbins+jj); end ox(ii)=ox(ii); oy(ii)=oy(ii); end else ox=zeros(n0+1,1); oy=zeros(n0+1,1); for ii=1:n0 for jj=1:nbins ox(ii)=ox(ii)+x((ii-1)*nbins+jj); oy(ii)=oy(ii)+y((ii-1)*nbins+jj); end ox(ii)=ox(ii); oy(ii)=oy(ii); end for ii=1:n1 ox(n0+1)=ox(n0+1)+x(n0*nbins+ii); oy(n0+1)=oy(n0+1)+y(n0*nbins+ii); end ox(n0+1)=ox(n0+1)*nbins/n1; oy(n0+1)=oy(n0+1)*nbins/n1; end ==== function out=xy_bins(img,nbins) ...

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(:))...

Non-local means filter --> Image denoise

There are several denoise filters such as Gaussian, bilateral and so on[1]. However, they may deteriorate the image quality. Non-local means filter is a powerful (but time-consuming >"<) denoise filter, which can preserve the detail of the image by averaging neighbor pixels with similar neighborhoods! The Matlab code can be found from the website listed in ref 2. For more detail refer to ref 3. Example: [1] https://web.cs.hacettepe.edu.tr/~erkut/bil717.s12/w09-bilateral-nlmeans.pdf [2] https://pastebin.com/28GsvWkW [3] https://www.youtube.com/watch?v=9tUns4HYtcw

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.

The difficulty of electron tomography

The difficulties limit the direct application to electron tomography The tilt range has to be from -90 degree to +90 degree The number of projections in a tilt series needs to be 2N for an N*N object The grid points past the resolution circle cannot be experimentally determined These limitations are overcome by combining the PPFFT with an iterative process. Ref: http://www.physics.ucla.edu/research/imaging/EST/index.html