Finding points of zero slope from 3D function
I will be fitting 3D differences of Gaussians to data, and from these fits I want to be able to identify troughs and peaks (points of zero slope) in my resultant functions. I can compute XYZ data points and look for local maxima, but the results are not satisfactory, at least the way I am doing it.
Below is a sample script showing my problem:
syms a1 a2 b1 b2 b3 b4 c x x0 y y0
DoG3D(a1, a2, b1, b2, b3, b4, c, x, x0, y, y0) = ...
(a1 * exp(-1/2 * (((x - x0)/b1)^2 + ((y - y0)/b2)^2))) - ... % Gaus 1
(a2 * exp(-1/2 * (((x - x0)/b3)^2 + ((y - y0)/b4)^2))) + ... % Gaus 2
c;
% The constants below will differ, depending on a fit, but here are some % convenient ones % a1 a2 b1 b2 b3 b4 c x x0 y y0 DoG3DFit(x, y) = DoG3D(-50, -25, 50, 150, 100, 300, 10, x, 220, y, 180);
pretty(DoG3D)
figure subplot(2, 2, 1) fsurf(DoG3DFit, [-1000, 1000]) daspect([50, 50, 1])
% Trying to solve it numerically is unsatisfactory (at least this way) [X, Y] = meshgrid(-1000:1000, -1000:1000); matDoG3DFit = matlabFunction(DoG3DFit); Z = matDoG3DFit(X, Y); Zpoints = or(imregionalmax(Z), imregionalmax(-Z)); subplot(2, 2, 2) imagesc(Zpoints) axis image xy
% In 2D, this is easy
DoG(a1, a2, b1, b2, c, x, x0) = ...
a1 * exp(-1/2 * (((x - x0)/b1)^2)) - ... % Gaus 1
a2 * exp(-1/2 * (((x - x0)/b2)^2)) + ... % Gaus 2
c;
pretty(DoG)
zeroPoints = solve(diff(DoG(-50, -25, 50, 150, 10, x, 220), x) == 0, x); subplot(2, 2, 3) fplot(DoG(-50, -25, 50, 150, 10, x, 220), [-1000, 1000]) hold on scatter(zeroPoints, DoG(-50, -25, 50, 150, 10, zeroPoints, 220), 'r')
% How do I do the same in 3D?
I am hoping there is a way, using the Symbolic Math or other toolbox, to generate formulae that will describe the locations where the slope is zero. These should be, to my understanding, at point (x0, y0), and then at points around the rim of the "caldera." The location of those points will depend upon what constants I supply DoG3D, above.
If this were a 2D difference of Gaussians, I would simply take the derivative and solve for 0, but I do not know what the equivalent approach is for a 3D function.
Can someone please help me to achieve this? Or is there no such solution?
댓글 수: 1
- I don't think this is what you want, but if you just want to plot the maximum you can use contourslice, i.e.
- But from your question it looks as if you want to be able to generate an analytical solution.Doesn't the original (2D) method still work? I think at the 'caldera' both dz/dx = 0 and dz/dy = 0.So if you find either of these derivatives, you can find the maximum/minimum.Offcourse these derivatives are a bit more complicated..
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!