function [x y wx wy]=autogaussfit1(imgname,guess,imgdetails) %guess = [offset amplitude centroidlocation width] %imgdetails = [HWSrulerlocation exp.time] %output vectors same format as guess thisfile=mfilename('fullpath'); thisdir=strrep(thisfile,mfilename(),''); rulerz = imgdetails(1,1); exposure = imgdetails(1,2); M=readimgs(imgname,1); [rows cols] = size(M); x = lsqcurvefit(@gauss_beam1D,guess,1:cols,mean(M,1)); y = lsqcurvefit(@gauss_beam1D,guess,[1:cols]',mean(M,2)); %sensor image display_dalsa_image(M); print('-dpdf',['gaussfit_image_z' num2str(imgdetails(1,1)) '.pdf']) %row analysis wx=x(4)*12e-6*1000; figure hold plot(mean(M,1)) plot(1:cols,gauss_beam1D(x,1:cols),'Color',[1 0 0]) title(['Mean Row Intensity vs. Row Number: Ruler position z = ' num2str(rulerz) ... 'mm. Exposure time t = ' num2str(exposure) 'us']) xlabel('Row Number on Image (pixels)') ylabel('Mean Intensity along Row') text(0.8,0.55,['Calculated Width = ' num2str(wx) 'mm'],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.45,['Fit Offset = ' num2str(x(1))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.4,['Fit Pixel Amplitude = ' num2str(x(2))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.35,['Fit Centroid = ' num2str(x(3))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.3,['Fit Pixel Width = ' num2str(x(4))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.0,-0.13,[thisfile,'.m'],'FontSize',8,'Interpreter','none','Units','normalized') legend('Data Line','Fit Line','Location','Northeast') orient landscape print('-dpdf',['gaussfit_rows_z' num2str(rulerz) '.pdf']) hold figure %column analysis wy=y(4)*12e-6*1000; hold plot(mean(M,2)) plot(1:cols,gauss_beam1D(y,1:cols),'Color',[1 0 0]) title(['Mean Column Intensity vs. Column Number: Ruler position z = ' num2str(rulerz) ... 'mm. Exposure time t = ' num2str(exposure) 'us']) xlabel('Row Number on Image (pixels)') ylabel('Mean Intensity along Row') text(0.8,0.55,['Calculated Width = ' num2str(wy) 'mm'],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.45,['Fit Offset = ' num2str(y(1))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.4,['Fit Pixel Amplitude = ' num2str(y(2))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.35,['Fit Centroid = ' num2str(y(3))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.8,0.3,['Fit Pixel Width = ' num2str(y(4))],'FontSize',12,'Interpreter','none','Units','normalized'); text(0.0,-0.13,[thisfile,'.m'],'FontSize',8,'Interpreter','none','Units','normalized') legend('Data Line','Fit Line','Location','Northeast') orient landscape print('-dpdf',['gaussfit_cols_z' num2str(rulerz) '.pdf']) hold hold wx = [rulerz wx]; wy= [rulerz wy];