I’m a total beginner to matlab and I’m currently writing a script for extracting data from a thermographic video.
Firstly the video is cut in separate frames. The first frame is opened as a sample picture to define the coordinates of sampling points. The goal is then to select the rgb values of those defined coordinates from a set of frames and save them into a matrix.
Now I have a problem separating the matrix to n smaller matrices.
e.g I’m defining the number of points to be selected to n=2 , with a picture count of 31. Now it returns a matrix stating the rgb codes for 31 pictures, each at 2 points, in a 62×3 double matrix…
Now I want to extract the 1st, 3rd, 5th….etc… row to a new matrix…this should be done in a loop, according to the number of n points…e.g 5 points on each picture equals 5 matrices, containing values of 31 pictures….
this is an extract of my code to analyse the pictures, it returns the matrix ‘values’
files = dir('*.jpg');
num_files = numel(files);
images = cell(1, num_files);
cal=imread(files(1).name);
n = input('number of selection points?: ');
imshow(cal);
[x,y] = ginput(n);
eval(get(1,'CloseRequestFcn'))
%# x = input('x-value?: '); manual x selection
%# y = input('y-value?: '); manual y selection
for k = 1:num_files
images{k} = imread(files(k).name);
end
matrix=cell2mat(images);
count=(0:size(matrix,1):size(matrix,1)*num_files);
for k = 1:num_files
a(k)= mat2cell(impixel(matrix,x+count(k),y));
end
values = cat(1,a{:})
Easy fix
Do you mean that if you have:
you want it to become
This can be easily done with:
Better fix
Of course it’s also possible to just reshape your data matrix and use that instead of the smaller matrices: (continuing with my sample data ^^)
Good practice
Or, my preferred choice: save the data immediately in an easy to access way. Here I think it will be an matrix of size: [num_files x num_points x 3]
If you want all the first points:
only the red channel of those points:
and so on.
I think this is possible with this:
But I don’t understand the complete meaning of your code (eg: why
matrix=cell2mat(images)??? and then of course:is just
count=0:num_files;so I’m not sure what would come out of
impixel(matrix,x+count(k),y)and I used images{k} 🙂