How to implement a nonlinear grid into an image?
13 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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 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.
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!