Adding noise to an image

In the Process dropdown menu is an option to add noise to an area of interest or to an entire image. I would like to encode that in a plugin such that I can define the area of interest then apply the noise to it, thus the image might 4 or 5 area, each with a different level of noise. When I try to dive down into the menu item for help, it takes me off to a separate web site that contains another jar that demonstrates different types of noise but does not show how to create the noise.`

Has anyone managed to develop an Add-Noise routine similar to the functions in the dropdown menu?


If you are referring to the ImageJ 1.x built-in function… you can find the source code for Add Noise here and for Salt and Pepper here.

I am not sure what is out there for ImageJ2… you can search ImageJ Ops for noise filters in that git repo.

Hope this helps a bit.

eta :slight_smile:


Thank you for replying to my inquiry. The link that you showed provided the source to the Menu Item for Process. So it includes calls to each item in the menu list: ‘invert’, ‘smooth’, ‘sharpen’, ‘edge’, ‘add’, ‘noise’ but it does not show how the filters are applied to the roi. The calls to the add noise filter is ip.noise(25.0) and the call to the custom noise filter is ip.noise(sd), where sd = a float with the default value of 25.0 in the ‘add’ option. It implies that this number is a standard deviation. So what I cannot understand is what Gaussian about this filter. Is it a spatial Gaussian (mean Intensity, std. deviation Intensity) only along the intensity axis or is there a Gaussian distribution in x,y as well? So what I would really like is the source for the filter ip.noise(x). So your post was a lot of help as I am now focused on a specific function in ImageJ 1.x

The ImageJ 1.x “Add noise” command is implemented separately for each bit depth (with some code duplication):

  • 8-bit: ByteProcessor:

  • 16-bit: ShortProcessor

  • 32-bit: FloatProcessor

  • RGB: ColorProcessor)

The javadoc comments hopefully answer your question regarding the Gaussian distribution?!

Specifically, there is the addNoise op that you can call as follows, e.g. from Groovy:

#@ OpService ops
#@ Img img

noiseOp = ops.op("addNoise", img.firstElement(), -1000.0, 1000.0, 100.0)"map", img, noiseOp)

The implementation is type agnostic and can be found here: