A = imread('D:\Learn\MatlabCode\Material manufacturing and technology\cailiao1.png'); % Indentation image acquired
A1 = rgb2gray(A);
figure
imshow(A1);
threshold=graythresh(A1);
B = im2bw(A1,threshold); % Separate the indentation from the background with the im2bw function in MATLAB
figure
imshow(B);
C = edge(B,'sobel',(graythresh(A1)*.1));
% Use strel function and imdilate function to expand the edge to fill the gaps in the edge
I = strel('line',3,90);
H = strel('line',3,0);
D = imdilate(C,[I H]);
E = imfill(D,'holes'); % Here the imfill function is used to fill these gaps
figure
imshow(C);
area = bwarea(E);
% Here we find the diameter of the indentation, and then convert the diameter calculated in the figure to the unit we want.
d = sqrt(4*area/pi)/100;
P = 1514.65;
D = 5;
HBN = 2*P/(pi*D*(D-sqrt(D^2-d^2)));
fprintf('The Brinell Hardness Number is %f\n',HBN);
%https://wenku.baidu.com/view/50dd30c56137ee06eff918d0.html
我们需要先读取图片,然后将图片进行灰度处理,再进行边缘化和二值化处理,最后读出半径,带入施加的力后可以计算出来布氏硬度。