1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| clear, close all
d = dir('*.dcm');
volume_data = zeros(256, 256, 224);
slice_thickness = zeros(1,224);
for i=1:numel(d)
file_name = strcat('IM',num2str(i),'.dcm');
dicom_info = dicominfo(file_name);
anatomical_location_of_dicom_image = dicom_info.InstanceNumber;
dicom_image = dicomread(file_name);
dicom_image_resized = imresize(dicom_image, [256 256]);
slice_thickness(anatomical_location_of_dicom_image) = dicom_info.SliceThickness;
volume_data(:,:,anatomical_location_of_dicom_image) = dicom_image_resized;
end
high_res_volume = volume_data(:,:,1:75);
low_res_volume = volume_data(:,:,76:224);
[X, Y, Z] = meshgrid(1:256, 1:256, linspace(1,75,56));
resized_volume_data = interp3(high_res_volume,X,Y,Z);
uniform_volume = cat(3, resized_volume_data, low_res_volume);
[X, Y, Z] = meshgrid(1:256, 1:256, 1:224);
cylinder_mask = (X - 128).^2+(Y - 128).^2 < 90.^2 ;
% The line above creates a cyclinder in which the interior region is 1 and the rest is 0
%-------------HINT----------------------
% And here you have to make a ELEMENT BY ELEMENT multiplication; however what you try below is a MATRIX multiplication
% that is why it doesn't work
new_volume = uniform_volume.*cylinder_mask;
smooth_new_volume = smooth3(new_volume); |