0
votes

I am modifying dicom images by replacing the actual pixel values with fixed numbers. Here is one line of my script (below).

image_list=dir('*.dcm');

for i=1:40
img=dicomread(image_list(i).name);
imgHdr = dicominfo(image_list(i).name);
%Bone 
img(1:410,1:410) = 3000*uint16(img(1:410,1:410)>1590 & img(1:410,1:410)   <=3000)+uint16(img(1:410,1:410)<=1590 | img(1:410,1:410)>2000).*img(1:410,1:410);

dicomwrite(img, ['N' num2str(i) '.dcm'], imgHdr,'CreateMode','Copy')
end

Then, I am trying to add random numbers (between 1 and 100) to these fixed values, i.e. 3000 (as shown in the script) so it will be between 3000 and 3100. How can I do that ?

Any assistance would be appreciated, thanks.

1
what does not work exactly?Benoit_11
the line is working fine but I don't know how to add random numbers in my scriptsTurki

1 Answers

0
votes

If you want to add random integers uniformly distributed, you should go for randi

so for example this code:

img(1:410,1:410)= img(1:410,1:410) +randi([3000 3100],410,410);

would add to the existing image pseudorandom uniformly distributed integers from 3000 to 3100.