Storing points into an array

조회 수: 18 (최근 30일)
Shane
Shane 2014년 9월 8일
편집: Andy L 2014년 9월 10일
I have a Hyper-spectral image that is 760 X 520 X 361 which is also known as a data cube. I know if i want to find the value of a single pixel I would say Let p be the value/point and img be the image so therefore
p = img('75,104,361');
it should return a 1X1X361 matrix but instead i get a 1x10 what am i doing wrong? My other problem is I have a text file we will call "listp.txt" with 12 different points in it (i.e.75,104,361)( I tried in the below code to call list). How do i create a loop to call this list to p so that they can be stored as an array?
old=cd('C:\Users\Blarg\Desktop\Hal');
%%Get Full Image Data
% ENVI Import Cube and Register images
datafile = 'image_FlatField';
hdrfile = 'image_FlatField.hdr';
%%Read ENVI Files
[im, hdr] = enviread([old '\' datafile],[old '\' hdrfile]);
img = imrotate(im,90, 'nearest');
figure; imshow(img(:,:,361));
%%Reshape .txt into 12x1 list with each coordinate read in a columns as
% | 1 | 2 ...
%1| '342,212,361' |
%2| '313,147,361' |
%3| '295,212,361' |
%4 ...
d = reshape(textread('listp.txt', '%s'),1,12)';
  댓글 수: 2
Andy L
Andy L 2014년 9월 8일
How is your text file laid out - my assumption is each line is a set of co-ordinates? Are these then separated by commas, spaces? etc!
Shane
Shane 2014년 9월 8일
they are laid out in the text file like this with a space between them
232,255,361 334,421,361 ...and so on
I have another .txt laid out as
x y z
232 255 361
334 421 361
... ... ...
I do not know which way I should go with this so any help would be appreciated. Thank you

댓글을 달려면 로그인하십시오.

채택된 답변

Andy L
Andy L 2014년 9월 8일
편집: Andy L 2014년 9월 10일
For the first question I think that if you change the following line of code
p = img('75,104,361');
to
p = img(75,104,:); % for the full vector at Z.
this should solve your indexing issue. It seems no coincidence to me that your input is 10 characters long and you are getting a 1x10 output...
Based on your response to my comment above, if you have control over how the text file is laid out I would go with the second option (line by line). If you always want the full vector z at (x,y) then the z column in the text file is not necessary either.
[x , y, z] = textread('textExample.txt', '%u %u %u');
Returns column vectors for x y and z assuming the layout below
x y z
232 255 361
334 421 361
It's worth noting that you don't need to type x y and z in the text file - this may confuse things.
You can then use the following to extract the vector z at each coordinate:
for m = 1 : length(x)
p(i,:) = img(x(i),y(i),:); % Store vector z in row i of p.
end
  댓글 수: 2
Shane
Shane 2014년 9월 8일
편집: Shane 2014년 9월 8일
when i do this it gives me a single cell with a low value of 0.0067. So with the image, I have a x, y and z coordinate and all I want is the data on z vector of all 361 points at location x and y which I figure out I can get this by
p = img(75,104,:);
which gives me the 1X1X361 matrix i am looking for.
Thanks you
Andy L
Andy L 2014년 9월 10일
Check updated answer

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Iain
Iain 2014년 9월 8일
p = img(75, 104,:);

카테고리

Help CenterFile Exchange에서 Display Point Clouds에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by