How to perform 2D fit of image using Fit2D Gaussian optimization toolbox

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)');

Respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2023b

Preguntada:

el 29 de Abr. de 2024

Comentada:

el 30 de Abr. de 2024

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by