Re: Background Subtractor makes Image black

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Background Subtractor makes Image black

Michael Schmid
Hi Steven,

the following seems to work; it does not create a black image for me (I tried with the 'Blobs' sample):

import ij.plugin.PlugIn;
import ij.plugin.filter.*;
import ij.*;
import ij.process.*;

public class Test_Background implements PlugIn {

    public void run(String arg) {
        ImagePlus imp = WindowManager.getCurrentImage();
        ImagePlus copy = new ImagePlus("title",(ImageProcessor)imp.getProcessor().duplicate());

//alternatively, the following also works:
//ImagePlus copy = imp.duplicate();

        double rad= 10;
        ImageProcessor ip = copy.getProcessor();
        BackgroundSubtracter bs =new BackgroundSubtracter();
        bs.rollingBallBackground(ip, rad , false, false, false, false, false);
        //bs.run(ip);
        copy.updateAndDraw();
        copy.show();
    }
}

Maybe your image is very smooth, so that 'Subtract Background' with a radius of 10 takes the image data as a background, and nothing remains after subtraction?

Michael
________________________________________________________________
On May 11, 2014, at 20:40, [hidden email] wrote:

> Hello Michael,
>
> thanks for your response and excuse my more than just delayed one. I've really treid the time to work the error out. I changed the.clone() with the duplicate() as you suggested and I tried copying the imp instead of the processor.
> Have you tried to use the Background Subtracter itself as a programming object? Because all my possible options end in a black image.
>
> Best regards Steve
>
>
>
> <quote author='Michael Schmid-3'>
> Hi Steve,
>
> there is one problem: You should not use clone() but duplicate().
> clone() is just a shallow clone, i.e., all objects of the cloned
> ImageProcessor are the same as those of the original. So the copy gets the
> same array of pixels, and modification of the image data will modify the
> original data.
>
> You won't see that the original got modified, however, until you zoom in or
> out on the original image, so its display has to be refreshed on the screen.
> Maybe that explains your problem?
>
> (You might also duplicate the ImagePlus, then it will inherit the
> calibration and more properties from the original).
>
>
> Michael
> ________________________________________________________________
> On Mar 14, 2014, at 11:52, Influenza wrote:
>
>> Hello everyone,
>>
>> I postede this question a few months ago, but couldn't get any help until
>> now and didn't find a similiar thread, so I just try again:
>>
>> I'm trying to use the BackgroundSubtracter class in a PlugIn without
>> calling
>> the IJ.command.
>> I tried to do the following:
>>
>>
>>               ImagePlus imp = WindowManager.getCurrentImage();
>>               ImagePlus copy = new
>> ImagePlus("title",(ImageProcessor)imp.getProcessor().clone());
>>               double rad= 10;
>>               ImageProcessor ip = copy.getProcessor();
>>
>>               BackgroundSubtracter bs =new BackgroundSubtracter();
>>               bs.rollingBallBackground(ip, rad , false, false, false,
>> false, false);
>>               //bs.run(ip);
>>               copy.updateAndDraw();
>>               copy.show();
>>
>> But equal to whether I use the .run() or the .rolingBallbackground()
>> method,
>> both outcoming images are just plain black.
>> Can anyone help me wiht the correct use, or find my mistake?
>>
>> Best regards
>> Steve
>>
>>
>>
>> --
>> View this message in context:
>> http://imagej.1557.x6.nabble.com/Background-Subtractor-makes-Image-black-tp5006912.html
>> Sent from the ImageJ mailing list archive at Nabble.com.
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> </quote>
> Quoted from:
> http://imagej.1557.x6.nabble.com/Background-Subtractor-makes-Image-black-tp5006912p5006913.html
>
>
> _____________________________________
> Sent from http://imagej.1557.x6.nabble.com
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html