Clear Filters
Clear Filters

How to implement a nonlinear grid into an image?

13 views (last 30 days)
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?
If you need more info, please let me know.
Thanks in advance.

Answers (1)

Mike Garrity
Mike Garrity on 21 Jan 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:
img = imread('street1.jpg');
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 Comments
Mathieu Mivelle
Mathieu Mivelle on 21 Jan 2016
Thanks, but when I try your code with the same image I have an error saying :
Warning: CData must be double or single unless it is used only as a texture data
And nothing appear on the surf plot...
Mathieu Mivelle
Mathieu Mivelle on 21 Jan 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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!