3D data non-transparent presentation

조회 수: 3 (최근 30일)
Valeriy
Valeriy 2020년 10월 23일
댓글: Valeriy 2020년 11월 5일
There is a X,Y,Z rectangular matrix M partly filled by the non-zero numerical data. There is a direction of view, along X, or, Y, Z direction.
It is simple to calculate projection of the matrix on view direction, Z in following case, as a mean(M(:,:,1)), median(M(:,:,1)), max(M(:,:,1)), etc.
Is there a simple method how to find such projection, when each corresponding projection's value equal to the first non-zero element along direction of projection? It is similar to the case, when each non-zero M element is "non-transparent", shadowing all other elements behind it.
Of course, it is possible to organize 2D loops to calculate such element, but it will be very time consuming operation.
Thanks for proposals and help

채택된 답변

Tim
Tim 2020년 10월 31일
One way to do this is to make a binary matrix that is 1 for all values greater than your threshold (zero, for example), and zero elsewhere, then compute the max-operation on the binary matrix along the desired projection dimension. For duplicate values, the MAX operation returns the minimum index, which is what you are looking for. Then you can grab the 3D matrix values corresponding to the max indices as a 2D array to form your projection.
Here is an example for a projection of the type you want along dimension 2, with the caveat that how I am computing the indices is kind of ugly. There is probably a better/simpler solution for that. You will have to modify the indexing according to the dimension you want to project along.
% Example for finding the "first-index-above-threshold projection"
% Example volume containing some >0 values:
tst = rand(5, 5, 5);
tst(tst < 0.5) = 0;
% Make binary mask:
threshold = 0; % Insert threshold here: using 0
bmask = zeros(size(tst));
bmask(tst > threshold) = 1;
% Example for dimension 2:
% - Modify the following code for performing this operation in dimensions 1
% or 3.
% Find indices of first non-zero values in dimension 2:
[~, mxi] = max(bmask, [], 2);
% Get associated indices in dimensions 1 and 3:
idx1 = repmat((1:size(tst, 1))', [1, 1, size(tst, 3)]);
idx3 = repmat(permute((1:size(tst, 3)), [3, 1, 2]), [size(tst, 1), 1, 1]);
% Convert to matrix index value:
inds = sub2ind(size(tst), idx1, mxi, idx3);
% Grab from original matrix:
proj = tst(inds);
% Show:
imagesc(squeeze(proj))
  댓글 수: 1
Valeriy
Valeriy 2020년 11월 5일
Hi Tim,
Excellent solution, thank you very much!
And thanks for very useful applicaton expamples of <max> and <sub2ind> functions
Best regards
Valeriy

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by