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