Calculate the size of a grain in an SEM image
Versión 1.0.0 (1,4 KB) por
N/A
Code that allows you to calculate grain size in an SEM or FE-SEM image.
% Load the SEM image
img = imread('sem_image_075_100K.jpg');
% Convert the image to grayscale
img_gray = rgb2gray(img);
% Apply a threshold to the image to segment the grains
img_threshold = img_gray > 128;
% Use bwlabel to identify the individual grains in the image
[labeled_img, num_grains] = bwlabel(img_threshold);
% Initialize a variable to hold the grain sizes
grain_sizes = zeros(1, num_grains);
% Loop over each grain in the image and calculate its size
for i = 1:num_grains
grain_mask = labeled_img == i;
grain_sizes(i) = sum(grain_mask(:));
end
% Calculate the average grain size
avg_grain_size = mean(grain_sizes);
% Print the average grain size to the command window
fprintf('The average grain size is %.2f pixels\n', avg_grain_size);
Citar como
N/A (2025). Calculate the size of a grain in an SEM image (https://la.mathworks.com/matlabcentral/fileexchange/124445-calculate-the-size-of-a-grain-in-an-sem-image), MATLAB Central File Exchange. Recuperado .
Compatibilidad con la versión de MATLAB
Se creó con
R2022b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS LinuxEtiquetas
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Descubra Live Editor
Cree scripts con código, salida y texto formateado en un documento ejecutable.
| Versión | Publicado | Notas de la versión | |
|---|---|---|---|
| 1.0.0 |
