I'm trying to covert 2d DICOM MRI images to 3D using Matlab. I am able to get the images to the 3D space but it shows up flat in the z-axis.
    8 ビュー (過去 30 日間)
  
       古いコメントを表示
    
This is my code so far below 
%% SPECIFY DIRECTORY
clear all
close all
fileFolder = fullfile('/Users/anugrahsajan/Documents/capstone/matlab/digest_article');
files = dir(fullfile(fileFolder, '*.dcm'));
fileNames = {files.name};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMINE FILE HEADER
info = dicominfo(fullfile(fileFolder,fileNames{1}));
voxel_size = {info.PixelSpacing; info.SliceThickness};
numImages = length(fileNames);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% READ SLICE IMAGES AND POLULATE 3D MATRIX
hWaitBar = waitbar(0,'Reading Dicom Images');
% Preallocate the 256-by-256-by-1-by-20 image array.
mri = repmat(int16(0), [256 256 20]);
L = repmat(int16(0), [256 256 20]);
mrinew = repmat(int16(0), [256 256 20]);
% Read the series of images.
for i=1:20
    if i > 9
        fname = sprintf('/Users/anugrahsajan/Documents/capstone/Lab1 - BrainMRI1/brain_0%01d.dcm',i);
        mri(:,:,i) = uint16(dicomread(fname));
    else
        fname = sprintf('/Users/anugrahsajan/Documents/capstone/Lab1 - BrainMRI1/brain_00%1d.dcm',i);
        mri(:,:,i) = uint16(dicomread(fname));
    end
    waitbar(i/numImages)
end
delete(hWaitBar)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SEGMENT OUT THE REGION OF INTEREST (BRAIN)
% This section will take the mri images in the variable mri and try to segment out the
% skull and brain by running the images through regprop function
hWaitBar = waitbar(0,'Segmenting Dicom Images');
for i = 1:numImages
    L(:,:,i)=regprop(mri(:,:,i));
    mrinew(:,:,i) = mri(:,:,i).*L(:,:,i);
    waitbar(i/numImages)
end
delete(hWaitBar)
montage(mrinew,'DisplayRange',[])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% View one specific MRI image in the motage
% This section will take one image from the MRI images so I can analyze it
% further in the later code through imtool
im = mrinew(:,:,10);
max_level = double(max(im(:)));
imt = imtool(im,[0,max_level]);
% close the image tool
imtool close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Threshold based on intensities and row/columns
%isolate brain mass based on the intensities found in the imtool 
lb = 370; % set up lower bound value
ub = 580; % set up upper bound value
mriadjust = mrinew; % create a copy of the dataset
mriadjust(mriadjust <= lb) = 0; % segment out pixels w/ intensities lower than ub
mriadjust(mriadjust >= ub) = 0; % segment out pixels w/ intensities greater than lb
%mriadjust(1:70,:,:)= 0; % segment out pixels that are not in the rows 1-70
bw = logical(mriadjust); %binary conversion
figure
imshow(bw(:,:,10));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Morphological opening
% this section gets rid of the reminder of small islands and objects
% remaining
nhood = ones([7 7 3]);
bw = imopen(bw,nhood);
figure
imshow(bw(:,:,10))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ISOLATE THE LARGEST REGION 
% Use the regionprops MATLAB function to identify and isolate the largest
% remaining object in the image which should be the brain
L = bwlabeln(bw); %label the objects in the image
stats = regionprops(L,'Area','Perimeter'); %use the regionprops function to gather info on the objects
A = [stats.Area]; % copy the area informaton about the objects to the variable A
biggest = find(A == max(A)); % find the object with the largest area in the image
mriadjust(L ~= biggest) = 0; % any object that is not the largest object gets removed
imA = imadjust(mriadjust(:,:,10));
figure
imshow(imA);
bw = int16(bw); % covert the logical values to int values 
for i=1:20
    mrinew(:,:,i) = mrinew(:,:,i).*bw(:,:,i); % multiply the mrinew by the mask bw to get segmented image of the brain
end
montage(mrinew,'DisplayRange',[])
%% Export to 3D
M = isosurface(bw,1/2);
tr=triangulation(M.faces,M.vertices);
figure('color','w'), h=trimesh(tr); axis equal
% now write to STL
stlwrite(tr, 'spinalSegmentation.stl');
Regprop function
function [tumor] = regprop(img)
%This code will take the DICOM images fed into it through the variable 'y'
%and then segment out the region of interest.
bw = (img > 0.7*255);   %thresholded to remove background and white/gray matter
lbl = bwlabel(bw);      %labelled regions
props = regionprops(lbl, 'Solidity', 'Area');
% solidity is the percentage "filled" of an area. For the skull, 
%the solidity will be really low.
solidity = [props.Solidity];
area = [ props.Area];  
hiSolid= solidity > 0.2;  %get only high solidity objects
maxArea = max( area(hiSolid));  
tumorLabel = find( area==maxArea);  %label of tumor
tumor = ismember(lbl, tumorLabel);  %b/w image of tumor
%imshow(tumor);  %this isolates tumor
end
This is the dataset I am working with.

This how the dataset looks at the end of the program. I know I can segment it a little bit better but my main problem now is that it looks really flat in the 3D space. 


On volumeViewer I can play around with the X-axis values but it starts to look really pixelated and stretched out. 
Is there anything I can do to make sure that the 3D diagram does not come out flat or really pixelated/stretched when I vew it in volumeSegmenter?
4 件のコメント
  yanqi liu
      
 2022 年 2 月 18 日
				yes,sir,can you zip your folder “digest_article” and upload it,so we can analysis it
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


