开发者

I want to display a blurred image in imageJ. Why doesn't this work?

开发者 https://www.devze.com 2023-03-29 21:59 出处:网络
I\'m very very new to imageJ but know a little Java. Essentially I want to open a file from an OpenDialog display the image, then blur the image and display the resulting blurred image. My program co

I'm very very new to imageJ but know a little Java.

Essentially I want to open a file from an OpenDialog display the image, then blur the image and display the resulting blurred image. My program compiles, however the two images look the same. Can anybody help? How do I make the program display a blurred and unblurred image?

import ij.*;
import ij.io.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
import java.util.*;
import java.io.*;


public class opens_ implements PlugIn {

    ImagePlus imp;

    public void run(String arg){
    OpenDialog od = new OpenDialog("Open.....", arg);
    Opener op = new Opener();
    String directory = od.getDirectory();
    String filename = od.getFileName();
    if (filename==null) return ;
    imp =  op.openImage(directory, filename);
    imp.show(); 

    ImageProcessor improc = imp.getProcessor();
    improc.smooth();

    ImagePlus alter = new ImagePlus("alter", improc) ;
    alter.show();


    }

}
开发者_开发技巧

Thanks

Bateman


When you call .smooth() on improc, that call alters the image data contained by the ImageProcessor, which is being displayed by the original ImagePlus. Then you create a new ImagePlus based on the same ImageProcessor, so of course it's the blurred image rather than the original. If you don't want the original to be altered, then you can duplicate the ImageProcessor before smoothing, for example by changing the line:

ImageProcessor improc = imp.getProcessor();

... to:

ImageProcessor improc = imp.getProcessor().duplicate();

Update: when I tested your code, I saw both images as blurred. If you still see the original images, try adding the following to the end of your run method:

imp.updateAndDraw()
alter.updateAndDraw()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号