필터 지우기
필터 지우기

How can speed up the program while reshaping 600 projections

조회 수: 7 (최근 30일)
Rami
Rami 2011년 11월 11일
Hi,
For CT reconstruction, I am reshaping each projection (600 projections) as row matrices. The program is really slow as I am using loop to read the Data(proj,row,col) and pickup row and column for each projection and reshape it.
for N_proj = 1:600 %NumProj,
proj(N_proj).sector = squeeze(Data(N_proj,:,:)); %%retrieval of projection data N x N matrix
proj(N_proj).sector = reshape(proj(N_proj).sector, 1, N_col*N_row); %%row matrix
new_proj = zeros(N_proj,N_col,N_row);
end
This is working, but little slow. Is there possibility to improve the program.

채택된 답변

Walter Roberson
Walter Roberson 2011년 11월 11일
squeeze() does not change the data order, just the indexing.
reshape() to a row vector does not change the data order, just the indexing.
Therefore, your code can be rewritten as either
proj(N_proj).sector = reshape(Data(N_proj,:,:), 1, N_col*N_row);
or as
t = Data(N_proj,:,:);
proj(N_proj).secdtor = t(:).';
  댓글 수: 3
Walter Roberson
Walter Roberson 2011년 11월 14일
You would be able to achieve better performance if your Data had N_proj as its _last_ index instead of its first.
Walter Roberson
Walter Roberson 2011년 11월 14일
Indeed, if your Data had the projection number as the last index, then no reshaping would be necessary: it would all be indexing of consecutive bits of memory. Not only that, but the whole operation could probably be coded as a cell2struct(mat2cell()) call... though it is not clear that that would be any faster than a for loop.
Do you have enough free memory to experiment with a permute() of Data? let me think, [2 3 1] I guess would be the permutation. I am not certain that doing that followed by indexing along the third dimension would necessarily be faster than what you have now -- but if you could consistently store and index the data with the projection number last, that would likely speed up your entire program.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Rami
Rami 2011년 11월 11일
Please find following as command lines as in original question it was not clear format
for N_proj = 1:600
proj(N_proj).sector = squeeze(Data(N_proj,:,:)); %% retrieval of projection data N x N matrix
proj(N_proj).sector = reshape(proj(N_proj).sector, 1, N_col*N_row);
end
Thanks, Rami

카테고리

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