How to convert 2D data to logical 3D array?

11 visualizzazioni (ultimi 30 giorni)
Hello everyone!
I have cancer cell data collected from Atomic Force Microscopy (bascially it's a scanning technique that allow to measure height in 3 dimension), where it gives me 512x512 pixels. For each pixel, there is a value correlated to the height on the cell. So I have 262144 different values as expected.
How can I convert it to 512x512x512 in 3D with the height being filled with number 1. (1 for filled space and 0 for blank space). So that at the end, my array is a logical array with only 0 and 1
Thank you so much

Risposta accettata

Walter Roberson
Walter Roberson il 17 Mar 2021
Modificato: Walter Roberson il 17 Mar 2021
idx = floor(double(Force) ./ maxForceReading * 511) + 1;
Force3d = reshape(1:512,1,1,[]) == idx;
untested.
  3 Commenti
Dang Nguyen
Dang Nguyen il 17 Mar 2021
Modificato: Dang Nguyen il 17 Mar 2021
It works now after your edit, thank for your help
Walter Roberson
Walter Roberson il 17 Mar 2021
minForce = SEE DISCUSSION
maxForce = SEE DISCUSSION
maxScaledZ = 512;
dataAFM = double(test_1);
dataAFM(512*512+1:end) = []; %get rid of any extra beyond 512 x 512
dataAFM(end+1:512*512) = minForce; %pad in case of short data
dataAFM = round(dataAFM - minForce);
rgbimg = reshape(dataAFM, 512, 512).'; %vector elements are to go ACROSS first
ForceRange = maxForce - minForce;
idx = floor(rgbimg ./ ForceRange * (maxScaledZ-1)) + 1;
Force3d = reshape(1:maxScaledZ, 1, 1[]) == idx;
Now, in the above, minForce should not be min(dataAFM): it should instead be the smallest value that can be returned by the AFM. Likewise, maxForce should not be max() of the data: it should instead be the largest value that can be returned by the AFM.
The point is that when you are building your 3D shape, you want it to reflect some kind of absolute size, not some kind of relative size. If one experiment is a square with a round disk in the center that is a certain height, and another experiment is a square with a round disk in the center that is twice the height of the first experiment, you probably do not want the two to give the same output: you probably want an output for the second one which is about twice the Z height as the first.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by