问题
I am new to ImageJ and I am seeking to add grain (as defined here: http://en.wikipedia.org/wiki/Film_grain) to an image using the programmatic API of ImageJ.
- Is it possible? If so how?
- Where is the relevant documentation/Javadocs regarding adding grain to an image using ImageJ?
回答1:
I'd start in Process > Noise
, described in ImageJ User Guide: §29.6 Noise. You'll have to decide if the existing implementations can be made to meet your requirements.
Where I can find documentation on how to achieve this using the actual API instead of the UI.
As discussed in ImageJ Macro Language, one easy way is to start Plugin > Macros > Record
and then operate the desired GUI command. This reveals the macro command name and any settings, for example:
run("Add Noise");
run("Add Specified Noise...", "standard=16");
You can apply such a macro to multiple files using the -batch
command line option.
If you want to use a feature directly from Java, see ImageJ programming tutorials.
回答2:
I saw that there was no language tag so I choose to write an example in Scala. The code below would read twice the lena.png image, and create two ImagePlus objects and add noise to one of them.
I am kind of guessing that the API comment is related to the software library ImageJ instead of the graphical user interface/program ImageJ.
An ImagePlus has a processor (of type ij.process.ImageProcessor) that you can get a reference to with the method getProcessor()
(getProcessor() is a method here that acts on the object lenaWithNoise and returns a reference to the current ImageProcessor (attached to lenaWithNose)).
The method noise acts on the image that the ImageProcessor handles, and has no return value (void method or in scala unit)
import ij._
object Noise {
def main(args: Array[String]): Unit = {
val lenaNoiseFree:ImagePlus = IJ.openImage("src/test/scala/images/lena.png")
val lenaWithNoise:ImagePlus = IJ.openImage("src/test/scala/images/lena.png")
lenaNoiseFree.show()
lenaWithNoise.getProcessor().noise(10.0)
lenaWithNoise.show()
}
}
来源:https://stackoverflow.com/questions/12462040/how-do-i-add-grain-to-an-image-using-the-imagej-api