numG1=readmatrix('Hardness.xlsx','Range','A2:A5'); numG2=readmatrix('Hardness.xlsx','Range','A7:A10'); numG3=readmatrix('Hardness.xlsx','Range','A12:A15'); %=============== calculate the Actual Compressive Force =================== ACF1(1,:)=numG1(1,:)/9.8;writematrix(ACF1(1,:),'Hardness.xlsx','Range','B2'); ACF1(2,:)=numG2(1,:)/9.8;writematrix(ACF1(2,:),'Hardness.xlsx','Range','B7'); ACF1(3,:)=numG3(1,:)/9.8;writematrix(ACF1(3,:),'Hardness.xlsx','Range','B12'); ACF2(1,:)=numG1(2,:)/9.8;writematrix(ACF2(1,:),'Hardness.xlsx','Range','B3'); ACF2(2,:)=numG2(2,:)/9.8;writematrix(ACF2(2,:),'Hardness.xlsx','Range','B8'); ACF2(3,:)=numG3(2,:)/9.8;writematrix(ACF2(3,:),'Hardness.xlsx','Range','B13'); ACF3(1,:)=numG1(3,:)/9.8;writematrix(ACF3(1,:),'Hardness.xlsx','Range','B4'); ACF3(2,:)=numG2(3,:)/9.8;writematrix(ACF3(2,:),'Hardness.xlsx','Range','B9'); ACF3(3,:)=numG3(3,:)/9.8;writematrix(ACF3(3,:),'Hardness.xlsx','Range','B14'); ACF4(1,:)=numG1(4,:)/9.8;writematrix(ACF4(1,:),'Hardness.xlsx','Range','B5'); ACF4(2,:)=numG2(4,:)/9.8;writematrix(ACF4(2,:),'Hardness.xlsx','Range','B10'); ACF4(3,:)=numG3(4,:)/9.8;writematrix(ACF4(3,:),'Hardness.xlsx','Range','B15'); I1=imread('1Wood.jpg'); I2=imread('2Alluminium Alloy.jpg'); I3=imread('3Lead Brass.jpg'); I4=imread('4Cast Iron.jpg'); I1=rgb2gray(I1); I2=rgb2gray(I2); I3=rgb2gray(I3); I4=rgb2gray(I4); % figure(1);subplot(1,2,1);imshow(I);xlabel('Origin'); dia1=diameterGain(I1);writematrix(dia1(1,:),'Hardness.xlsx','Range','C2');writematrix(dia1(2,:),'Hardness.xlsx','Range','C7');writematrix(dia1(3,:),'Hardness.xlsx','Range','C12'); dia2=diameterGain(I2);writematrix(dia2(1,:),'Hardness.xlsx','Range','C3');writematrix(dia2(2,:),'Hardness.xlsx','Range','C8');writematrix(dia2(3,:),'Hardness.xlsx','Range','C13'); dia3=diameterGain(I3);writematrix(dia3(1,:),'Hardness.xlsx','Range','C4');writematrix(dia3(2,:),'Hardness.xlsx','Range','C9');writematrix(dia3(3,:),'Hardness.xlsx','Range','C14'); dia4=diameterGain(I4);writematrix(dia4(1,:),'Hardness.xlsx','Range','C5');writematrix(dia4(2,:),'Hardness.xlsx','Range','C10');writematrix(dia4(3,:),'Hardness.xlsx','Range','C15'); %=================== calculate for Group 1,2,3 ============================ temp1=(2*ACF1)/(pi*5*(5-power(power(5,2)-power(dia1,2),0.5))); temp2=(2*ACF2)/(pi*5*(5-power(power(5,2)-power(dia2,2),0.5))); temp3=(2*ACF3)/(pi*5*(5-power(power(5,2)-power(dia3,2),0.5))); temp4=(2*ACF4)/(pi*5*(5-power(power(5,2)-power(dia4,2),0.5))); BNH_Group1=[temp1(1,3);temp2(1,3);temp3(1,3);temp4(1,3)];writematrix(BNH_Group1,'Hardness.xlsx','Range','D2'); BNH_Group2=[temp1(2,3);temp2(2,3);temp3(2,3);temp4(2,3)];writematrix(BNH_Group2,'Hardness.xlsx','Range','D7'); BNH_Group3=[temp1(3,3);temp2(3,3);temp3(3,3);temp4(3,3)];writematrix(BNH_Group3,'Hardness.xlsx','Range','D12'); %============================== function to measure the diameaters========= function[Dia]= diameterGain(I) [m,n]=size(I); a=double(I); sigma=10; filterExtent = ceil(4*sigma); x = -filterExtent:filterExtent; %=======================Gaussian filtering&gradient calculation============ c = 1/(sqrt(2*pi)*sigma); gaussKernel = c * exp(-(x.^2)/(2*sigma^2)); gaussKernel = gaussKernel/sum(gaussKernel); derivGaussKernel = gradient(gaussKernel); negVals = derivGaussKernel < 0; posVals = derivGaussKernel > 0; derivGaussKernel(posVals) = derivGaussKernel(posVals)/sum(derivGaussKernel(posVals)); derivGaussKernel(negVals) = derivGaussKernel(negVals)/abs(sum(derivGaussKernel(negVals))); aSmooth=imfilter(a,gaussKernel,'conv','replicate'); aSmooth=imfilter(aSmooth,gaussKernel','conv','replicate'); hv=fspecial('sobel'); dx = imfilter(aSmooth, derivGaussKernel, 'conv','replicate'); dy = imfilter(aSmooth, derivGaussKernel', 'conv','replicate'); mag = hypot(dx,dy); magmax = max(mag(:)); if magmax>0 magGrad = mag / magmax; end PercentOfPixelsNotEdges = 0.7; counts=imhist(magGrad, 64); highThresh = find(cumsum(counts) > 0.7*m*n, 1 ,'first' ) / 64; lowThresh = 0.4*highThresh; magGrad=imcomplement(magGrad); figure(8);imshow(magGrad); %============================= User Operation ============================ %Take the length/pixel ratio % (click the ruler on the right side with your mouse to take out 1cm) axis on; [p,q]=ginput(2); ratio= 10/power(power(abs(p(1,:)-p(2,:)),2)+power(abs(q(1,:)-q(2,:)),2),0.5); % unit:mm/pixl %Take out the diameter of the indentation from small one to large one. % (click on the indentation on the left that is clearer, % then click on the leftmost and rightmost indentations in order from small to large. % There are a total of three indentations) [p1,q1]=ginput(6); dia1= ratio * power(power(abs(p1(1,:)-p1(2,:)),2)+power(abs(q1(1,:)-q1(2,:)),2),0.5); dia2= ratio * power(power(abs(p1(3,:)-p1(4,:)),2)+power(abs(q1(3,:)-q1(4,:)),2),0.5); dia3= ratio * power(power(abs(p1(5,:)-p1(6,:)),2)+power(abs(q1(5,:)-q1(6,:)),2),0.5); %=============================function output============================== Dia=[dia1;dia2;dia3]; end 这个代码是把图像怎么处理了
最新发布