Azzera filtri
Azzera filtri

accessing data in multiple pixels (x,y) in 3D matrix (t,x,y)

1 visualizzazione (ultimi 30 giorni)
Hi,
I am a beginner in Matlab. I am trying to average time series (t) of selected multiple pixels in 3D matrix (t,x,y). I could obtain two 1D vectors for x and y indexes, but have problems when accessing 1D time series data for all the selected pixels in 3D matrix. Would someone know how to do that without using loop?
Best,

Risposta accettata

Iain
Iain il 22 Mag 2013
Matrix_2D = reshape(Matrix_3D,[timesamples numberofpixels]);
Determine the pixel numbers you want (1 = top left, 2 = 1 below that... etc.) and put them in a vector. "V"
Selected_pixel_timeseries = Matrix_2D(:,V);
You can then simply take the mean of each row to get the average of each frame.
  1 Commento
photoon
photoon il 22 Mag 2013
It looks cool. Sounds like I need to use linear indexing. Let me look at this solution carefully.
Thanks Doogie

Accedi per commentare.

Più risposte (1)

photoon
photoon il 23 Mag 2013
Modificato: photoon il 23 Mag 2013
Hi, Iain
I could finish the code based on your suggestion.
Here, I put it.
cm = ones(1,21,21);
chconv3 = convn(ch,cm,'same');
sumch2 = squeeze(sum(chconv3));
sumch2mean = mean2(sumch2);
sumch2thre = sumch2;
sumch2thre(sumch2thre < sumch2mean) = 0;
[cellx,celly] = find(sumch2thre);
cellxy = [cellx,celly];
v1 = [243,376]; v2 = [280,126];
dismat = zeros(length(cellxy),1);
for ii = 1:length(cellxy)
dismat(ii) = point_to_line(cellxy(ii,1:2),v1,v2);
end
chmean = zeros(256,floor(max(dismat)));
for jj = 1:max(dismat)
LI = (jj > dismat) & (dismat >= (jj-1));
xLI = cellx(LI); yLI = celly(LI);
xyLI = sub2ind(size(sumch2),xLI,yLI);
chconv2 = reshape(chconv3,256,[]);
chmean(:,jj) = mean(chconv2(:,xyLI),2);
end
There is ch 3D matrix (t,x,y). At first, I bin data of each pixel with neighboring pixels (In this case, with 10 cells around). Then, choose the pixels of higher intensity. In the first for loop, the distances of the pixels from the line defined by two points (v1 and v2) is calculated. In the second for loop, The pixels are grouped based on the distance and time series of intensity are averaged for each group. I think this code can be more concise. If you have better idea, please let me know.
Thanks
Doogie
  1 Commento
Iain
Iain il 23 Mag 2013
If xyLI was a vector of the linear indices, you would not need to have the loop.
xyLI = row_number + (col_number-1)*rows;

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by