Non-Local means denoising Plugin makes all edges orange

java
plugin
Tags: #<Tag:0x00007fb882c2eb28> #<Tag:0x00007fb882c2e740>

#1

[JAVA] My code for running the ImageJ plugin is as follows:

import ij.IJ;
import ij.ImagePlus;
import ij.io.FileSaver;
import ij.plugin.PlugIn;


public class Test implements PlugIn {

  public static void main(String[] args) {

    Test test = new Test();
    test.run("Denoise.ijm");

  }

  @Override
    public void run(String arg0) {
      String directory = "C:\\Users\\Speedy Octopus\\Desktop\\10Cover Shots\\10.JPG";

      ImagePlus imp = IJ.openImage(directory);
      FileSaver fileSaver = new FileSaver(imp);

      System.setProperty("plugins.dir", "C:\\Users\\Speedy Octopus\\Downloads\\ij150-win-java8\\ImageJ\\plugins");
      IJ.run(imp, "Non-local Means Denoising", "sigma=5 smoothing_factor=1");
      fileSaver.saveAsJpeg("C:\\Users\\Speedy Octopus\\Desktop\\10Cover Shots\\10edited.JPG");
    }
}

After running the remove noise macro, all of the edges of my images are turned orange. how can I stop this from happening?

This also happens when I use the actual ImageJ.jar program

Starting image
Denoised image


#2

Welcome to the forum, @nexion21!

Firstly, just to clarify for other readers: the Non Local Means Denoise is part of the Biomedgroup update site.

I was able to reproduce the orangeification of the edges on my local machine by running the “Non-local Means Denoising” plugin on the image above.

Maybe @twagner has some insight into this phenomenon?

As a workaround, the problem does not occur if you first Split Channels, run the denoising on each of the R, G and B channels individually, and then Merge Channels again afterward.

(Unfortunately, there appears to be a bug if you Make Composite on the image and try running the denoising on that:

java.lang.ArrayIndexOutOfBoundsException: 1
	at de.biomedical_imaging.ij.nlMeansPlugin.NLMeansDenoising_.run(NLMeansDenoising_.java:114)
	at ij.plugin.filter.PlugInFilterRunner.processOneImage(PlugInFilterRunner.java:265)
	at ij.plugin.filter.PlugInFilterRunner.processStack(PlugInFilterRunner.java:196)
	at ij.plugin.filter.PlugInFilterRunner.<init>(PlugInFilterRunner.java:147)

)


#3

Thanks for your response! My knowledge with ImageJ is extremely limited so without your response I would have been outta luck, I really appreciate your help.

I ended up getting it working with the following code in my run method:

ImagePlus imp = IJ.openImage(directory);
FileSaver fileSaver = new FileSaver(imp);

System.setProperty("plugins.dir", LocalMethods.readFile("NonLocalMeansDir").get(0));

ImagePlus[] channels = ChannelSplitter.split(imp);
String[] channelTitles = new String[3];
for (int i = 0; i < channels.length; i++) {
  ImagePlus channel = channels[i];
  channelTitles[i] = channel.getTitle();
  IJ.run(channel, "Non-local Means Denoising", "sigma=5 smoothing_factor=1");
}
IJ.run(imp, "Merge Channels...", "c1=[" + imp.getTitle() +  " (" + channelTitles[0] + ") " + "] c2=[" + imp.getTitle() +  " (" + channelTitles[1] + ") " + "] c3=[" + imp.getTitle() +  " (" + channelTitles[2] + ") " + "] create");
IJ.saveAs("jpeg", directory);