% An example of how to use the dcm4che toolkit from matlab for file
% reading or other dicom functions.
% Step 1 is to download the toolkit from www.dcm4che.org. Select the
% dcm4che2 tookit 'bin' archive, and unzip it.
% Then add the java libraries to your path
checkjava = which('org.dcm4che2.io.DicomInputStream');
if isempty(checkjava)
libpath = 'c:\your_path_here\dcm4che2lib\';
javaaddpath([libpath 'dcm4che-core-2.0.12.jar']);
javaaddpath([libpath 'dcm4che-image-2.0.12.jar']);
javaaddpath([libpath 'dcm4che-imageio-2.0.12.jar']);
javaaddpath([libpath 'dcm4che-iod-2.0.12.jar']);
javaaddpath([libpath 'slf4j-api-1.4.3.jar']);
javaaddpath([libpath 'slf4j-api-1.4.3.jar']);
javaaddpath([libpath 'slf4j-log4j12-1.4.3.jar']);
javaaddpath([libpath 'log4j-1.2.13.jar']);
end
% Now create a reader as follows (other examples on dcm4che wiki)
testfile = [matlabroot '\toolbox\images\imdemos\CT-MONO2-16-ankle.dcm'];
dcm = org.dcm4che2.data.BasicDicomObject;
din = org.dcm4che2.io.DicomInputStream(...
java.io.BufferedInputStream(java.io.FileInputStream(testfile)));
din.readDicomObject(dcm, -1);
% You can access the fields like this:
%width = dcm.getInt(org.dcm4che2.data.Tag.Width)
rows = dcm.getInt(org.dcm4che2.data.Tag.Rows);
cols = dcm.getInt(org.dcm4che2.data.Tag.Columns);
pixeldata = dcm.getInts(org.dcm4che2.data.Tag.PixelData);
img = reshape(pixeldata, rows,cols);
imagesc(img);