Meshgrid

13 次查看(过去 30 天)
Charles
Charles 2011-1-27
Hi,
I have 3 vectors x,y,z; with x and y representing co-ordinates and z their values. Picture this as an image matrix that has been decomposed into vectors of x & y and pixel intensity z. Now I want to get back my picture. Here is what I did and where I got stuck:
[x1 y1] = meshgrid(-a:a) % -a:a defining the square image.
Now the problem is how to assign values (z) at the appropriate co-ordinates. Suggestions would be appreciated.
Charles

采纳的回答

Andrew Newell
Andrew Newell 2011-1-27
I assume that x and y have the same values as x1 and y1, but in a different order. You could do a search for each pair (x1,y1), but it's faster to sort the coordinates and then reshape Z. Here is an example with an actual image to give you the idea:
%%Set up the problem
load mandrill
Z = X; %rename image
nrows = size(Z,1); ncols = size(Z,2);
[x1,y1] = meshgrid(1:nrows,1:ncols);
x = x1(:); y = y1(:); Z = Z(:);
% Scramble the elements.
index = randperm(numel(Z));
x = x(index); y = y(index); Z = Z(index);
%%Now the problem is set up, unscramble x and y and then reshape Z.
xy = [x y];
[~,index] = sortrows(xy,[1 2]);
x = x(index); y = y(index); Z = Z(index);
Z = reshape(Z,nrows,ncols);
image(Z)
Of course, if x and y were originally obtained from a process like that in the previous cell, you won't need to sort.

更多回答(1 个)

Ashish Uthama
Ashish Uthama 2011-1-27
Either use interp2, griddata or if you have a newer version, triscatteredinterpclass. The doc pages have examples to get you started.

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by