# How to implement a nonlinear grid into an image?

11 visualizaciones (últimos 30 días)
Mathieu Mivelle el 21 de En. de 2016
Editada: Mathieu Mivelle el 22 de En. de 2016
Dear all,
I have an image from a matrix that I want to plot with pcolor.
My problem is that each pixel in my image should not have the same size, my grid should be non-linear.
But it is not the usual non linearity that you can define in x then in y and finally plot your image as pcolor(x, y, M).
I place in copy my matrix, named M, and the grid it should fit into, named G (if you plot imagesc(G) you can see the non-linearity with cylindrical symmetry I’d like to have in M).
Would someone know how to do that?
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Mike Garrity el 21 de En. de 2016
The image object won't do that. It does linear interpolation between the coordinates of its corners. You need to use a graphics object that has coordinates for each pixel.
The pcolor function is designed to do this sort of job.
The one issue with pcolor is that it only supports colormapped images. If you've got a true color image, it won't work. But you can do the same thing that pcolor does. What it's doing is creating a surface with the ZData set to 0's. So you can replicate that with a truecolor image like so:
w = size(img,2);
h = size(img,1);
x = sin(linspace(-pi/2,pi/2,w)).^3;
y = (w/h)*sin(linspace(-pi/2,pi/2,h)).^3;
h = surf(x,y,zeros(h,w),img,'EdgeColor','none');
view(2)
axis ij
Just replace the X & Y with your grid.
##### 2 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Mathieu Mivelle el 21 de En. de 2016
It actually doesn't solve my problem ether, my nonlinearity has cymetrical symetry which can not be solv by using x and y nonlinear grid like you did..It actually doesn't solve my problem ether, my nonlinearity has a cylindrical symmetry which cannot be solve by using x and y nonlinear grid like you did.. But thanks anyway for the effort.
But thanks anyway for the effort.

Iniciar sesión para comentar.

### Categorías

Más información sobre Surface and Mesh Plots 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