필터 지우기
필터 지우기

Adding Specific Ratio of Noise to an Image

조회 수: 1 (최근 30일)
Mohammed Abdul Wadood
Mohammed Abdul Wadood 2022년 7월 25일
편집: Mohammed Abdul Wadood 2022년 7월 28일
How can I adding a noise (e.g 75% of gaussian noise) to an Image?
In (imnoise) function there is only the (mean & variance), I dont want to add (e.g gaussian noise with m = 0 & standard deviation of 75%), I want to add (e.g 75% of image or elements have noise and 25% don't). how can I do that?

채택된 답변

DGM
DGM 2022년 7월 25일
편집: DGM 2022년 7월 25일
The 'salt & pepper' option is the only option with a density parameter. Salt & Pepper noise will affect a specified fraction of the pixels in the image by slamming them to black/white.
inpict = imread('cameraman.tif');
outpict = imnoise(inpict,'salt & pepper',0.75);
imshow(outpict)
If you're trying to restrict some other type of noise by using a density parameter, then you'll have to write that yourself For example, if you wanted gaussian noise with a restricted density:
inpict = imread('cameraman.tif'); % a grayscale image
density = 0.75; % density
gaumean = 0; % mean
gauvar = 0.01; % variance
s0 = size(inpict);
inpict = im2double(inpict);
gnpict = inpict + gaumean + sqrt(gauvar)*randn(s0);
noisemask = rand(s0)<density;
nnz(noisemask)/numel(noisemask) % check the density
ans = 0.7504
outpict = inpict;
outpict(noisemask) = gnpict(noisemask);
imshow(outpict)
Bear in mind that doing this density restriction alters the noise variance. If you want to specify the final variance instead of the variance of the image prior to sampling, you'll have to take that into account.
% adjust variance to compensate for density
gnpict = inpict + gaumean + sqrt(gauvar/density)*randn(s0);
  댓글 수: 4
Mohammed Abdul Wadood
Mohammed Abdul Wadood 2022년 7월 26일
편집: Mohammed Abdul Wadood 2022년 7월 28일
I tried it, thank you
Before asking my question here, I had already tried this method on the attached image
clc
clear all
close all
A = imread('Jupiter1.jpg');
figure
imshow(A)
A = im2double(A);
figure
imshow(A)
v = (0.75*std(A(:)))^2;
noisy_image = imnoise(A, 'gaussian', 0, v);
figure
imshow(noisy_image)
But I was confused, is this method correct or not?
DGM
DGM 2022년 7월 26일
I'm not really sure how you're trying to do this. If you're working with integer images, you could indeed pick a variance that would result in an approximate fraction of pixels being unaffected without the need for masking:
inpict = imread('cameraman.tif');
v = 0.000038;
outpict = imnoise(inpict,'gaussian',0,v);
nnz(outpict~=inpict)/numel(inpict) % fraction of altered pixels
ans = 0.7510
imshow(outpict)
This only really works because the image is quantized. Noise is still applied to every pixel during the process; it's just that (in this example) ~25% of the time, the noise is smaller than 1 LSB, so those pixels don't change. If this is the desired method, then the amount of achievable noise will be very small, and will be dependent on the image class.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by