How do I add grain to an image using the ImageJ API

半城伤御伤魂 提交于 2019-12-02 06:53:24

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.

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()
 }
} 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!