使用 MATLAB 实现测定烟尘纳米结构包括条纹长度、曲折度和层间间距。进行的晶格条纹分析包含以下图像处理步骤:a感兴趣区域选择b使用直方图均衡增强对比度c高斯低通滤波器d底帽变换e使用Otsu方法进行二值化f骨架化g消除孤立像素和具有3个以上连接的像素。条纹长度的计算方法是条纹所包含的像素数乘以像素长度对于对角线像素长度计算为像素大小的 2 倍。所有短于 0483 nm 的条纹两个芳香环都因不切
MATLAB code for analyzing lattice fringes in HRTEM images:
% Step 1: Select the region of interest (ROI) % Use the imrect tool to draw a rectangle around the region of interest % All pixels outside the ROI will be set to zero rect = imrect; position = wait(rect); xmin = round(position(1)); ymin = round(position(2)); width = round(position(3)); height = round(position(4)); roi = [xmin ymin width height];
% Step 2: Contrast enhancement % Use histogram equalization to enhance contrast img = imread('tem_image.tif'); img_roi = img(roi(2):roi(2)+roi(4)-1, roi(1):roi(1)+roi(3)-1); img_eq = histeq(img_roi);
% Step 3: Gaussian low-pass filter % Use a Gaussian filter to remove high-frequency noise sigma = 2; hsize = 5; h = fspecial('gaussian', hsize, sigma); img_filt = imfilter(img_eq, h);
% Step 4: Bottom-hat transform % Use the bottom-hat transform to enhance dark features in the image se = strel('disk', 5); img_bh = imbothat(img_filt, se);
% Step 5: Otsu thresholding % Use Otsu's method to convert the image to binary level = graythresh(img_bh); img_bw = imbinarize(img_bh, level);
% Step 6: Skeletonization % Use the skeletonize function to thin the binary image img_skel = bwmorph(img_bw, 'skel', Inf);
% Step 7: Morphological operations % Use additional morphological operations to improve the final image img_clean = bwareaopen(img_skel, 3); % remove isolated pixels img_clean = bwmorph(img_clean, 'spur', 5); % remove "H" shapes
% Step 8: Lattice fringe analysis % Use the bwconncomp function to identify connected pixels cc = bwconncomp(img_clean, 8); fringes = []; for i = 1:cc.NumObjects pixel_list = cc.PixelIdxList{i}; if length(pixel_list) >= 2 [y,x] = ind2sub(cc.ImageSize, pixel_list); xdiff = max(x) - min(x); ydiff = max(y) - min(y); if xdiff > 1 && ydiff > 1 % exclude diagonal fringes length = length(pixel_list) * pixel_size; if length >= 0.483 % exclude fringes shorter than 0.483 nm fringes(end+1).pixels = pixel_list; fringes(end).length = length; end end end end
% Step 9: Edge curvature % Calculate the edge curvature for each lattice fringe for i = 1:length(fringes) pixel_list = fringes(i).pixels; [y,x] = ind2sub(cc.ImageSize, pixel_list); xdiff = max(x) - min(x); ydiff = max(y) - min(y); length = fringes(i).length; linear_length = sqrt(xdiff^2 + ydiff^2) * pixel_size; curvature = length / linear_length; fringes(i).curvature = curvature; end
% Step 10: Edge spacing % Calculate the edge spacing for each pair of lattice fringes spacing = []; for i = 1:length(fringes) for j = i+1:length(fringes) if abs(fringes(i).length - fringes(j).length) < 0.1 % length difference less than 0.1 nm dx = []; dy = []; for k = 1:length(fringes(i).pixels) [y1,x1] = ind2sub(cc.ImageSize, fringes(i).pixels(k)); [y2,x2] = ind2sub(cc.ImageSize, fringes(j).pixels(k)); dx(k) = abs(x1 - x2) * pixel_size; dy(k) = abs(y1 - y2) * pixel_size; end if max(dx) < 0.6 && max(dy) < 0.6 % exclude fringes further than 0.6 nm apart distance = mean(sqrt(dx.^2 + dy.^2)); spacing(end+1).fringe1 = i; spacing(end).fringe2 = j; spacing(end).distance = distance; end end end end % Plot the selected fringes and their spacing in blue and green, respectively figure; imshow(img_clean); hold on; for i = 1:length(fringes) plot(fringes(i).pixels, 'b.'); end for i = 1:length(spacing) f1 = fringes(spacing(i).fringe1); f2 = fringes(spacing(i).fringe2); plot([f1.pixels; f2.pixels], 'g-'); end hold off;
原文地址: https://www.cveoy.top/t/topic/bjVc 著作权归作者所有。请勿转载和采集!