MATLAB: Set opacity to M x N x P grayscale matrix

3dimage processingImage Processing ToolboxMATLABmatrix

I have a matrix define as data = rand(M,N,P) where M = 262, N = 359, P = 562. Each element in the matrix gets assigned an intensity value for 0 – 255 depending on input scan data.
E.g. data(200,220,232) = 32 or data(200,220,233) = 156
How can i assign transparency to each element in the matrix based on the intensity value. For example: all intensities below 128 have 0.8 transparency, and every value between 128-255 has linear opacity from 0.1-0.4
This is all in Matlab.
Thank you

Best Answer

Logical operations can divide the elements, here is the starting point :
M=rand(262,359,562);
Threshold=0.45; % an example
E=M ;% matrix of transparency
E(E<Threshold)=0.8;
E(E>Threshold)=0.4;
Related Question