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

조회 수: 12 (최근 30일)
Adrian
Adrian 2024년 4월 29일
댓글: Mathieu NOE 2024년 4월 30일
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)');

답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by