comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: How to add 5% possion noise for a image in IDL
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: How to add 5% possion noise for a image in IDL [message #83994] Fri, 12 April 2013 06:40 Go to previous message
dplatten is currently offline  dplatten
Messages: 32
Registered: December 2007
Member
I took what Wayne posted and adapted it a bit. The function below will add a user-provided % of noise to a uniform image, where I'm defining % noise as (stdev / mean) * 100.

It doesn't work for non-uniform images at the moment.

Regards,

David


Test code:
seed = 1001L
testImage = FINDGEN(100,100) * 0.0 + 1000.0
PRINT, "Mean and standard deviation of original image is: " + STRING(MEAN(testImage)) + ", " + STRING(STDDEV(testImage))

noisyImage = DJP_addNoise(testImage, 5.0, seed)
PRINT, "Mean and standard deviation of new image is " + STRING(MEAN(noisyImage)) + ", " + STRING(STDDEV(noisyImage))

cgWindow, 'cgImage', testImage, WTitle='Original image', /Keep_Aspect
cgWindow, 'cgImage', noisyImage, WTitle='Image with noise added', /Keep_Aspect



FUNCTION DJP_addNoise, image, percentNoise, seed
Compile_Opt IDL2

IF(N_ELEMENTS(image) GT 0) THEN BEGIN

; Return an image with each value replaced by a Poisson deviate
h = HISTOGRAM(image, MIN=0, REVERSE=rr)
noisyImage = image

FOR i = 0, N_ELEMENTS(h) - 1 DO BEGIN
IF h[i] NE 0 THEN BEGIN
sub = rr[rr[i]:rr[i+1]-1] ; Get subscripts
currentMean = i+1
noisyImage[sub] = RANDOMU(seed, N_ELEMENTS(sub), POISSON=currentMean)

newMean = SQRT(currentMean) / (percentNoise / 100.0)
noisyImage[sub] += newMean - currentMean ; this adjusts the standard deviation to the required level
noisyImage[sub] *= currentMean / newMean ; this adjusts the mean back to what it was to start with
ENDIF
ENDFOR

RETURN, noisyImage

ENDIF ELSE BEGIN

RETURN, 0

ENDELSE

END
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: plotting vertical lines
Next Topic: Spaces in Mac file names

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:52:20 PDT 2025

Total time taken to generate the page: 0.00403 seconds