How to perform 2D fit of image using Fit2D Gaussian optimization toolbox
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello, I am trying to perform a 2D fit using this toolbox: https://www.mathworks.com/matlabcentral/fileexchange/41938-fit-2d-gaussian-with-optimization-toolbox?status=SUCCESS
I am having trouble converting the image into the required format for this toolbox.
The toolbox instructions are as follows:
FMGAUSSFIT performs a gaussian fit on 3D data (x,y,z). [fitresult,..., rr] = fmgaussfit(xx,yy,zz) uses ZZ for the surface height. XX and YY are vectors or matrices defining the x and y components of a surface. If XX and YY are vectors, length(XX) = n and length(YY) = m, where [m,n] = size(Z). In this case, the vertices of the surface faces are (XX(j), YY(i), ZZ(i,j)) triples. To create XX and YY matrices for arbitrary domains, use the meshgrid function. FMGAUSSFIT uses the lsqcurvefit tool, and the OPTIMZATION TOOLBOX. The initial guess for the gaussian is places at the maxima in the ZZ plane. The fit is restricted to be in the span of XX and YY.
clc
clear all
close all
cmap = jet(256);
new_cmap_range = linspace(120, 300, 256);
new_cmap = interp1(linspace(0, 1, 256), cmap, linspace(0, 1, 256), 'linear');
filename = 'ANP_polarizer50_90mm.png';
I0 = imread(filename);
%----------------------------------
%extract x,y,z coordinates
[xx, yy] = meshgrid(1:size(I0, 2), 1:size(I0, 1));
zz = double(I0);
%use 2D Gauss fit
[fitresult, zfit, fiterr, zerr, resnorm, rr] = fmgaussfit(xx,yy,zz);
imshow(I0,new_cmap);
axis on
set(gca, 'YDir', 'normal'); %set y axis direction
title('Beam');
colorbar; %add colorbar
impixelinfo;
xlabel('Position (px)');
ylabel('Postion (px)');
1 Kommentar
Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!