Image processing Gaussian noise

조회 수: 17 (최근 30일)
Fatih Tunç
Fatih Tunç 2021년 11월 17일
댓글: DGM 2021년 11월 18일
I need to add gaussian noise on a gray image. But i need to do it without using library.
I will be glad if you help me.
  댓글 수: 1
Image Analyst
Image Analyst 2021년 11월 17일
Can you at least use randn()? Or if not, can you use rand()? Or do you have to write your own random number generator?

댓글을 달려면 로그인하십시오.

답변 (2개)

DGM
DGM 2021년 11월 18일
편집: DGM 2021년 11월 18일
Something like this:
% same as imnoise() defaults
gaumean = 0;
gauvar = 0.01;
inpict = imread('cameraman.tif');
outpict = im2uint8(im2double(inpict) + gaumean + sqrt(gauvar)*randn(size(inpict)));
montage({inpict,outpict})
Note that this example assumes that the intended output class is uint8. Adjust as needed.

yanqi liu
yanqi liu 2021년 11월 18일
clc;clear all;close all;
img = mat2gray(imread('rice.png'));
img2 = img+0.1*randn(size(img),'like',img);
figure;
subplot(1,2,1); imshow(mat2gray(img));
subplot(1,2,2); imshow(mat2gray(img2));
  댓글 수: 1
DGM
DGM 2021년 11월 18일
Using mat2gray() as a general tool for converting images to floating point alters the relative scaling of the information, whereas the intended tools (e.g. im2double) scale things with respect to the limits implied by the class (see getrangefromclass()). It increases contrast unnecessarily. It's easier to notice with a lower-contrast image:
img = imread('pout.tif'); % original image
imshow(img);
img2 = mat2gray(img); % this stretches the contrast
img2 = img2 + 0.1*randn(size(img2),'like',img2);
figure; imshow(img2);
img3 = im2double(img); % this doesn't change the contrast
img3 = img3 + 0.1*randn(size(img3),'like',img3);
figure; imshow(img3);

댓글을 달려면 로그인하십시오.

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by