Storing points into an array
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shane
el 8 de Sept. de 2014
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 comentarios
Andy L
el 8 de Sept. de 2014
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!
Respuesta aceptada
Andy L
el 8 de Sept. de 2014
Editada: Andy L
el 10 de Sept. de 2014
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 comentarios
Más respuestas (1)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!