why I fully lose dicom image after adding noise to it?
Show older comments
Dear all,
I am trying to add both Gaussian and salt & pepper noise to a dicom image using imnoise() but in any densities I completely lose the image it becomes fully black with white spots in it.
I would be glad if someone could help me.
The below is my image and my code.
img = dicomread('1.dcm');
density = 0.01;
%img = imnoise(img,'gaussian',density);
img = imnoise(img,'salt & pepper',density);
Accepted Answer
More Answers (2)
Walter Roberson
on 1 Mar 2022
0 votes
class() has probably changed.
im2double(img) and imnoise() the results and im2uint8 or as appropriate to return to the original type.
There is a possibility that your image is int16 with signed data, especially if it is CT, and it might take a slight bit more work to get back to signed
5 Comments
khwaja mustafa siddiqi
on 1 Mar 2022
Walter Roberson
on 1 Mar 2022
Edited: Walter Roberson
on 1 Mar 2022
salt and pepper noise sets pixels to either their minimum or their maximum. Suppose that your useful data is in the range 4000 to 12000, but you add noise that is either 0 or 65535, then if you use imagesc() or imshow() with the [] option to rescale your image, then instead of the plot being based omn 12000-4000 = 8000 values, it is suddenly based on 65536 values, and the useful data would get washed out.
img = sort(sort(randi([1000 2000], 48, 64, 'uint16'),1),2);
density = 0.01;
%img = imnoise(img,'gaussian',density);
img2 = imnoise(img,'salt & pepper',density);
whos
[min(img(:)), min(img2(:))]
[max(img(:)), max(img2(:))]
imshow(img)
imshow(img2)
khwaja mustafa siddiqi
on 1 Mar 2022
Image Analyst
on 1 Mar 2022
Since your images are in the range 0-256, I'd just immediately cast them to uint8 right after you read them in
img = dicomread('1.dcm');
img = uint8(img);
After that, everything should be fine.
khwaja mustafa siddiqi
on 1 Mar 2022
Edited: khwaja mustafa siddiqi
on 1 Mar 2022
Image Analyst
on 1 Mar 2022
Try this:
img = dicomread('1.dcm');
subplot(2, 2, 1);
imshow(img, []);
subplot(2, 2, 2);
imhist(img);
% Show min and max are 0 and 256,
% nowhere close to the uint16 range of 0 to 65,535.
min(img(:))
max(img(:))
density = 0.01;
%img = imnoise(img,'gaussian',density);
noisyImage = imnoise(img,'salt & pepper',density);
whos noisyImage
subplot(2, 2, 3);
imshow(noisyImage, [])
% Now rescale
noisyImage = imnoise(mat2gray(img),'salt & pepper',density);
subplot(2, 2, 4);
imshow(noisyImage, [])

1 Comment
khwaja mustafa siddiqi
on 1 Mar 2022
Categories
Find more on DICOM Format in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


