function main() %MAIN Summary of this function goes here % Detailed explanation goes here % files=dir('*.dcm'); % clear all clc close all threedarray=NaN; %Records when numbered keys are pressed curx=1; cury=1; curz=1; %The three dimensional array given by the DICOM files [P Q R]=size(threedarray); %The cross sections of the current images axvert=NaN; axhorz=NaN; sagvert=NaN; saghorz=NaN; corvert=NaN; corhorz=NaN; %For zooming funtionality xthickness=NaN; ythickness=NaN; zthickness=NaN; % three axes handles axial = axes('Position',[0.02 0.1 0.3 0.9],'DataAspectRatio',[1 1 1],'XTick',[],'YTick',[],'Box','on'); sagittal = axes('Position',[0.35 0.1 0.3 0.9],'DataAspectRatio',[1 1 1],'XTick',[],'YTick',[],'Box','on'); coronal = axes('Position',[0.68 0.1 0.3 0.9],'DataAspectRatio',[1 1 1],'XTick',[],'YTick',[],'Box','on'); lookfordicom(); function lookfordicom() try folder=uigetdir('*.','Please select a directory'); w=cd;cd(folder); catch return end threedarray = NaN; try [threedarray xthickness ythickness zthickness] = gatherImages(folder); catch disp('You selected a folder that does not contain .dcm images'); threedarray = NaN; xthickness = NaN; ythickness = NaN; zthickness = NaN; cd(w); return end cd(w); [P Q R]=size(threedarray); axvert = 1:P; sagvert = 1:P; corvert = 1:Q; axhorz = 1:Q; saghorz = 1:R; corhorz = 1:R; curx = ceil(P/2); cury = ceil(Q/2); curz = ceil(R/2); dispIm(curx,cury,curz); end %GATHERIMAGES looks through a folder,gets all DICOM files and assembles %them into a viewable 3d foramt function [threedarray xthickness ythickness zthickness]=gatherImages(folder) d=sortDirectory(folder); topimage = dicomread(d(1,:)); metadata = dicominfo(d(1,:)); [group1 element1] = dicomlookup('PixelSpacing'); [group2 element2] = dicomlookup('SliceThickness'); resolution = metadata.(dicomlookup(group1,element1)); xthickness = resolution(1); ythickness = resolution(2); zthickness=metadata.(dicomlookup(group2,element2)); threedarray = zeros(size(topimage,1),size(topimage,2),size(d,1)); threedarray(:,:,1) = topimage; for i=2:size(d,1) threedarray(:,:,i)=dicomread(d(i,:)); end end%end gatherImages(folder) %SORTDIRECTORY SORTS BASED ON INSETANCE NUMBER function d=sortDirectory(folder) cd(folder); d=ls('*.dcm'); m=size(d,1); [group,element]=dicomlookup('InstanceNumber'); sdata(m)=struct('imagename','','instance',0); for i=1:m metadata = dicominfo(d(i,:)); position = metadata.(dicomlookup(group,element)); sdata(i) = struct('imagename',d(i,:),'instance',position); end [unused order]=sort([sdata(:).instance],'ascend'); sorted=sdata(order).'; for i=1:m d(i,:)=sorted(i).imagename; end end%end sortDirectory(dir) % show all three images function dispIm(x,y,z) dispZ(z); dispY(y); dispX(x); end %show image along Z axis function dispZ(z) axes(axial) im = double(squeeze(threedarray(1:P,1:Q,z))); im=imadjust(im/max(im(:)),[0,1],[0,1]); imshow(im);axis square; end %show image along y axis function dispY(y) axes(sagittal); im = double(squeeze(threedarray(1:P,y,1:R))); im=imadjust(im.'/max(im(:)),[0,1],[0,1]); imshow(im);axis square; end %show image along x axis function dispX(x) axes(coronal); im = double(squeeze(threedarray(x,1:Q,1:R))); im = imadjust(im.'/max(im(:)),[0 1],[0 1]); imshow(im); axis square; end end