Plotting 3 dimensional plot using two vectors and a matrix, and also creating a fit - image processing
15 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Dave B
2022-2-2
编辑:Dave B
2022-2-2
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 (:)
figure
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:
[xi,yi]=meshgrid(linspace(10,30),linspace(0,10000));
zi=interp2(xT,yExp,pMat',xi,yi);
figure;
scatter3(xi(:),yi(:),zi(:),[],zi(:),'filled');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!