Plotting 3 dimensional plot using two vectors and a matrix, and also creating a fit - image processing
3 views (last 30 days)
I have a camera from which I have taken images of a body using different temperatures and exposure times (integration time).
So for example I have the following two vectors:
xT = [10,20,30]; %A vector representing the object's temperature
yExp = [100,500,1000,5000,10000]; % A vector representing the exposure time in milliseconds.
I also have the following matrix of the median pixel grayscale value for each and every condition:
pMat = [5000,7000,9000,11000,13000; 7000,9000,11000,13000,15000; 9000,11000,13000,15000,17000] % A matrix example in which each row is a different temperature and each column is each integration time.
Now I want to plot the matrix pMat against xT and yExp to show the pixel values against those conditions. I would also like to make a function
fit to the created surface to extrapolate/interpolate the median pixel values for different conditions but I don't have the Curve Fitting tool so I have to program the fitting. Can anyone help me with those two questions?
Thanks in advance.
Dave B on 2 Feb 2022
Edited: Dave B on 2 Feb 2022
The plotting question is pretty easy, you just need to arrange your xT and yExp values so that they correspond to the shape of pMat. The meshgrid function does great for this:
xT = [10,20,30];
yExp = [100,500,1000,5000,10000];
pMat = [5000,7000,9000,11000,13000; 7000,9000,11000,13000,15000; 9000,11000,13000,15000,17000] ;
[yExpi, xTi]=meshgrid(yExp, xT); % note that meshgrid was called with y, x - if you call it with x,y you'll need to transpose to plot
surf(xTi, yExpi, pMat);
% or a scatter if you want, just turn all the previous matrices into
% vectors with (:)
scatter3(xTi(:), yExpi(:), pMat(:))
For curve fitting, it's not clear exactly what curve (surface) you want to fit...but you have x and y values and an f(x,y), so you can apply whatever math you have to predict f(x,y) based on your observed x,y. For interpolation, you might consider uysing scatteredInterpolant which is really simple to use:
s=scatteredInterpolant(xTi(:), yExpi(:), pMat(:));
s([15 25], [5000 6000]) % interpolated values where (xT, yExp) are (15, 5000) and (25, 6000)
You could also use interp2 here pretty easily, you'll just need to transpose your pMat matrix:
interp2(xT,yExp,pMat',[15 25],[5000 6000])
Note that (linear) interpolation is just finding the points that lie on the planes in the above surf, i.e. looking at the neighbors and drawing lines in between them: