Plotting 3 dimensional plot using two vectors and a matrix, and also creating a fit - image processing

조회 수: 11 (최근 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.

채택된 답변

Dave B
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)
ans = 1×2
12000 14400
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])
ans = 1×2
12000 14400
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 CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by