How do I create a cylinder in the given matrix?

1 view (last 30 days)
Hello,
I'm relatively new to Matlab and I'm trying to implement a cylinder(dimensions radius=31.75 height =8.128) (instead of the shape of a flattening filter for radiotherapy) in another person' code. This is to model a volume for something compared to a field of view on the volume. But for the interpolation function there are more unique values needed. And there is just the one value of a certain height(8.128) and a certain radius(31.75). If I create a cylinder myself the dimensions of the matrix of the Field Of View (defined as
if true
% Define the volume, it is the same size as the volume that contains ffilter
FOV = zeros(size(ffilter));
% volume = zeros([((2*maxx)+1),((2*maxy)+1),maxz]);
FOV = logical(FOV); end
Do not match the dimensions of the flattening filter. Does anyone have an idea to solve this problem. I can see if it is difficult to understand the problem. But if someone could help me it would be absolutely brilliant! PS the given dimension for the radius and height in the code below, are the dimensions for the Flattening filter.
if true
%%Creation of flattening filter matrix:
% Creating an empty 3D array based on the size of the flattening filter
r = [0.00, 0.635, 1.27, 1.905, 2.54, 3.81, 5.08, 6.35, 7.62, 8.89, 10.16, 12.7, 15.24, 17.78, 20.32, 22.86, 25.4, 27.94, 30.607,33.02];
h = [22.1742, 21.8948, 21.6154, 21.2344, 20.828, 20.0914, 18.7452, 17.653, 16.5608, 15.4432, 14.9098, 12.319, 10.414, 8.5596, 6.8834, 5.334, 3.9116, 2.6162, 1.397, 1.651];
maxx = round((max(r) + 10)); % Size of the volume (X-direction); maximum value of flattening filter radius is used.
% + 10 is to create more space, to have a volume sure big enough.
maxy = round((max(r) + 10)); % Size of the volume (Y-direction); Idem.
maxz = round((max(h) + 10)); % Size of the volume (Z-direction); maximum value of flattening filter height is used. Idem.
XmatrixFF = (2*maxx)+1; % Volume with variable size. The + 1 statement is for creating a centre point.
YmatrixFF = (2*maxy)+1; % The centre point is de collimator axis. Imagine the square field with a cross in it.
Rmax = ceil(sqrt(maxx.^2 + maxy.^2)); % creation of the radius, Rmax = srqt(x^2 + y^2)
R = (0:Rmax)'; % R = kolom vector van 0 tot Rmax
if energy == 1||2
H = interp1(r,h,R,'linear') % Connects the height points linearly, to find the corresponding height of radius ri.
[~,~,z] = meshgrid(1:XmatrixFF,1:YmatrixFF,1:maxz);
[xi, yi, ~] = meshgrid(-maxx:maxx, -maxy:maxy, 1:maxz);
ri = round(sqrt(xi.^2 + yi.^2)); % The radius depends on the xi and yi from the meshgrid created above
ffilter = z < H(ri+1); % ffilter is the volume when the value of z is smaller than the height that corresponds to (ri+1)
% The +1 is used to avoid the working with a radius of zero
end

Accepted Answer

Eeshan Mitra
Eeshan Mitra on 16 May 2018
Hello David,
If we leave out the specifics of the filter and focus on the matrix sizes, it is not quite clear from the attached code as to where the potential issue is. If you comment out the line that references the variable energy, and the last line in the second code snippet, then both variables FOV and volume have the same matrix size as ffilter.
If you are looking to altering the radius and height vector in the second code segment, you can use the linspace function to create a uniformly spaced linear vector, e.g:
r = linspace(r_min,r_max,20);
h = linspace(h_max,h_min,20);
, where the subscripts min and max refer to minimum and maximum values of radius and height
  1 Comment
David van Nederpelt
David van Nederpelt on 23 May 2018
Thank you for your help,
So instead of
if true
if energy == 1||2
H = interp1(r,h,R,'linear') % Connects the height points linearly, to find the corresponding height of radius ri.
end
and
if true
ffilter = z < H(ri+1); % ffilter is the volume when the value of z is smaller than the height that corresponds to (ri+1)
% The +1 is used to avoid the working with a radius of zero
end
You'd suggest to define ffilter in the meshgrid of
if true
[~,~,z] = meshgrid(1:XmatrixFF,1:YmatrixFF,1:maxz);
[xi, yi, ~] = meshgrid(-maxx:maxx, -maxy:maxy, 1:maxz);
ri = round(sqrt(xi.^2 + yi.^2)); % The radius depends on the xi and yi from the meshgrid created above
end
Maybe I misunderstood you completely...

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!