How to implement a nonlinear grid into an image?
10 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Mike Garrity
2016-1-21
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!