Question

I am trying to change the CT numbers (or Hounsfield unit, HU) in DICOM images using MATLAB, i.e. interpolate CT number from -1000 to -500 to one value (-750).

Any help would be appreciated.

Was it helpful?

Solution

First read in the image data, and the header:

fileName = 'image000.dcm';
img = dicomread(fileName);
imgHdr = dicominfo(fileName);

Patch the intensities:

img(img>=-1000 & img<=-500) = -750;

Save new file:

[~,base,ext] = fileparts(fileName);
dicomwrite(img,[base '_patched.dcm'],imgHdr,'CreateMode','Copy')

Say you have several ranges to patch:

upperVals = [-500     0  500];
lowerVals = [-1000 -500    0];
newVals =   [-750  -250  250];

You can use bsxfun with the less-than or equal and greater-than or equal operators:

masks = bsxfun(@ge,img(:),lowerVals(:).') & bsxfun(@le,img(:),upperVals(:).');
for i=1:numel(newVals), img(find(masks(:,i))) = newVals(i); end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top