필터 지우기
필터 지우기

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