Filter löschen
Filter löschen

Troubles with Plotting Across 3rd Dimension of a 3D Matrix

10 Ansichten (letzte 30 Tage)
I have a stack of images read into matlab as a double of size 256x256x17. Within each image, there's only a couple hundred pixels that actually contain data while the rest of the pixels are zeros. I want to plot the value of one pixel across the 17 time points (slices) to see how their values change over time.
I'm not sure what the best approach is to do this with minimal computation time as I'll have to repeat the process for 4 different stacks of images for 120 different sets of data (480 stacks of 256x256xn image arrays).
I can think of two different ways to do this, but I'm not sure how exactly to implement them or which would be best:
  1. Converting all zero values to Nans, then writing a for loop to loop through the time series so that a temporary variable "temp" will end up as a 1x17 double containing pixel data for one pixel across third dimension (time) then plot "temp" followed by "hold on" within the loop to get through all 65,536 (256*256 = 65,536) pixels within the loop since the plot function would handle the nans as invisible in the plot
  2. Use an if statement to test if the first pixel value in the series is 0 and then only build temp arrays for the 100-200 pixels that contain data using a for loop as described in (1).
I'm having a hard time getting my indexing right to do either option, and I'm not certain how computationally expensive the first option is vs the second as I don't want to wait five minutes per plot just to visualize my data.
If someone could help me out with a for loop that indexes this correctly or advise on which is easier for matlab to handle without having to code both options and time test each, I would really appreciate it.
Here's some background in case its necessary - these stacks of images were originally DICOM images that were read in with dicomread and then linearly transformed based on their encoding values read-in from their DICOM headers. These "images" (3D doubles) have displacement data in [cm] for each pixel describing displacement in the eularien description. Each DICOM started as a brain MRI but where masked to create 4 different ROIs to investigate local displacement in the brain across the cardiac cycle (this is why my arrays are 256x256xn, where n is the time point in the cardiac cycle as well as why there are mostly zero values in each ROI "image stack"). The plot I'm trying to produce here is to visualize the displacement over time of each pixel within an ROI so that I can eliminate pixels that represent fluid (CSF) instead of tissue because pixels that cover fluid will have significantly more displacement than tissue based on physiology.
Thank you in advance.

Akzeptierte Antwort

Matt J
Matt J am 2 Dez. 2021
Bearbeitet: Matt J am 2 Dez. 2021
I would do it this way.
A=permute(yourStack,[3,1,2]);
A=A(: , any( A(:,:) , 1) );
plot(A)
  1 Kommentar
Gwendolyn Williams
Gwendolyn Williams am 2 Dez. 2021
That worked perfectly and without any loops or if statements, thank you! I did end up getting a somewhat complicated solution to work using my idea from (1) but it took very long to plot and mostly froze my computer which made it hard to use. This is much better! Thank you!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by