# Extract interpolated values from a surface fit?

4 visualizaciones (últimos 30 días)
Max el 12 de En. de 2016
Comentada: Max el 13 de En. de 2016
I have a somewhat sparse array, and I'm using the curve fitting tool (cftool) to interpolate a surface about the raster points. (The idea is that I'm trying to show what a section of a valley looked like before it was eroded using a couple of simple geometric constraints. The upper part of the valley still exists, so I have good control on what it looks like. The lower part of the valley is like a trough, and I want to estimate what it looked like. In the image, I've put in my "geometric constraints" in the lower valley).
I get a really nice fit using interpolation with cftool, however, I can't find a way to get the fit into raster form. It's not like fitting a surface, and then applying the polynomial to your array, it's a piecewise linear interpolation.
It looks like the output surface is even rasterized! There must be a simple way to use cftool to get an interpolated raster output that I can convert to a tiff, and not be stuck with just a pretty picture.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Mike Garrity el 13 de En. de 2016
I'm not quite sure what you mean when you're saying "raster form" here. I think that you just mean that you want to evaluate the fitted model on a 2D grid. This page of the documentation describes how to do that.
Here's an example.
I created some sample data:
[x,y] = meshgrid(linspace(-pi,pi,25));
z = cos(x) .* sin(y) + randn(25)/100;
x = x + randn(25)/10;
y = y + randn(25)/10;
Then I went into cftool and created a fit. Then I chose "Save to Workspace ..." from the Fit menu. I let it use the default name, which is fittedmodel.
Back at the MATLAB command line, I can create a 2D mesh using meshgrid:
[x2,y2] = meshgrid(linspace(-pi,pi,400));
and I can evaluate the fitted model using those values:
z2 = fittedmodel(x2,y2);
Now I have a 2D array of values. I could save those as an image file.
imwrite(z2,'sfit_image.png')
That will give me a grayscale image. I could use ind2rgb to convert it to RGB, but I'd need to scale it correctly:
z_ind = round(1 + 255*(z2 - min(z2(:)))/(max(z2(:)) - min(z2(:))));
rgb = ind2rgb(z_ind,parula(256));
imwrite(rgb,'sfit_rgb.png')
Does that help, or did I misunderstand the question?
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Max el 13 de En. de 2016
You've understood my question perfectly, and this is exactly the advice I needed. Thanks!

Iniciar sesión para comentar.

### Categorías

Más información sobre Interpolation en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by