How can I convert my 3 columns data to a .raw image file so that I can read it as an image?

Dear users,
I am working on some simulations and output of the simulations are in 3D matrix but the data values are stored in .csv file, with voxel ID's. The voxel ID (iX, iY, and iZ): 0,0,0 is located at the corner of the 3D image as in nucler medicine images. Data is 10x10x10 matrix. Therefore, the center voxel of the 3D matrix is 5,5,5. See the data format in a sceenshot below:
....................................... up to 10, 10, 10 voxels.
I want to calculate the relationship of dose vs distance. So, I need to calculate the radial averaging of the dose as a function of radial distance as I put my sources at the center of the matrix. Could anyone of you help me by providing some clue on this? Any help would be greatly appreciated. I am thinking about converting it to the 3D image array so that I could easily manipulate it and plot the desired relationship.

Answers (1)

Let A be your matrix of three columns.
x = A(:,1) ; y = A(:,2) ; z = A(:,3) ;
%%structured
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
figure
pcolor(X,Y,Z)
shading interp
figure
imagesc(Z)

6 Comments

Thank you very much for the pointer but could not make a mesh grid, see below:
close all; clear; clc; workspace;
% Read .csv file
data = readtable('test_dose_11.csv');
% Read the columns
x = data(:, 1); % iX
y = data(:, 2); % iY
z = data(:, 3); % iZ
Dose = data(:, 4); % dose [Gy]
%%structured
xi = unique(x); yi = unique(y);
% As I want to make a meshgrid of 10x10x10, defining xi, yi using unique makes
% sense
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z, size(X)) ;
figure
pcolor(X,Y,Z)
shading interp
figure
imagesc(Z)
Error using meshgrid (line 59)
Subscripting into a table using one subscript (as in t(i)) or three or more subscripts (as
in t(i,j,k)) is not supported. Always specify a row subscript and a variable subscript, as
in t(rows,vars).
Error in dose_analysis (line 18)
[X,Y] = meshgrid(xi,yi) ;
Any help?
It seems you have data in table, you need to access them in a different way. Like T.(1), T.(2) etc. Attach your data if you are not able to solve your problem.
I have attached a .csv file herewith:
close all; clear; clc; workspace;
% Read .csv file
data = readtable('test_dose_11.csv');
% Read the columns
x = data(:, 1); % iX
y = data(:, 2); % iY
z = data(:, 3); % iZ
Dose = data(:, 4); % dose [Gy]
% using the "unique" function we can find out the unique values in the
% columns
xi = unique(x); yi = unique(y); zi = unique(z);
% I think I will need a 3D grid here
[X,Y,Z] = meshgrid(xi,yi,zi);
Error using tabular/reshape (line 216)
Undefined function 'reshape' for input arguments of type 'table'.
Error in meshgrid (line 77)
xx = reshape(full(x),[1 nx 1]); % Make sure x is a full row vector.
Error in analyze (line 17)
[X,Y,Z] = meshgrid(xi,yi,zi);
Not sure why this throws an error!! Any help would be appreciated.
% Read .csv file
data = readtable('C:\Users\KSSV\Downloads\test_dose_11.csv');
data = table2array(data) ;
% Read the columns
x = data(:, 1); % iX
y = data(:, 2); % iY
z = data(:, 3); % iZ
Dose = data(:, 4); % dose [Gy]
% using the "unique" function we can find out the unique values in the
% columns
xi = unique(x); yi = unique(y); zi = unique(z);
% I think I will need a 3D grid here
[X,Y,Z] = meshgrid(xi,yi,zi);
Thanks for this: table2array function.
Now, I have a meshgrid of desired matrix size. How could I assign the 4th column (i.e. data) into the respective voxels? Following line works for this, right?
Dose_matrix =reshape(Dose, size(X));

Sign in to comment.

Products

Release

R2020a

Asked:

on 24 Aug 2021

Commented:

on 24 Aug 2021

Community Treasure Hunt

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

Start Hunting!