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

1 次查看(过去 30 天)
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,

采纳的回答

Iain
Iain 2013-5-22
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 个评论
photoon
photoon 2013-5-22
It looks cool. Sounds like I need to use linear indexing. Let me look at this solution carefully.
Thanks Doogie

请先登录,再进行评论。

更多回答(1 个)

photoon
photoon 2013-5-23
编辑:photoon 2013-5-23
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 个评论
Iain
Iain 2013-5-23
If xyLI was a vector of the linear indices, you would not need to have the loop.
xyLI = row_number + (col_number-1)*rows;

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by