필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
photoon
photoon 2013년 5월 22일
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