Bug in Background Subtracter

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

Bug in Background Subtracter

Koen van dijken
While finalising a new plugin I discovered a bug in Background Subtracter.
In my own plugin I encounter a similar problem and do not know how to fix
it. To reproduce the bug in Background Subtracter take the following steps:

Bug in Background subtracter:

1: Load a tiff with three (double) channels
2: Image -> Color -> Split channels
3: for each slice (R, G and B): Image -> Type -> 32 bit
4: Image -> Color -> Merge channels
5: Process -> Subtract background

You can also download this sample file from my dropbox:

https://www.dropbox.com/s/r0wbvft0xh6wucr/merge32-1.tif?dl=0

, load it into ImageJ and proceed with step 5.

Now two of the three resulting channels will show black. They have sensible
data but probably some min and max are off and so do not show properly.

I noticed that by doing Image -> Adjust -> Window/Level -> Reset on the
defective slice the image springs back and shows. I traced through the
source of ij.plugin.frame.ContrastAdjuster.reset(ImagePlus, ImageProcessor)
but did not succeed in taking similar steps in my own plugin to get the
same result.

Does anybody know how to reset a stack of 32-bit images to show properly
after the values of the images have changed so much they fall outside their
previous bounds? I suspect some series of ip.resetMinAndMax() but just that
does not do.

Greetings from Holland,

Koen

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Gabriel Landini
On Sunday 17 Jul 2016 10:53:48 Koen van dijken <[hidden email]>
wrote:

> Now two of the three resulting channels will show black. They have sensible
> data but probably some min and max are off and so do not show properly.

Is this because you did not un-tick "Create Composite"? I think that the
Background subtract operates on images, not on composites.

> Does anybody know how to reset a stack of 32-bit images to show properly
> after the values of the images have changed so much they fall outside their
> previous bounds?

If you converted from 8bit to 32bit, you might want to set setMinAndMax(0,
255); but if you then processed the 32bit image, you are changing the range to
some unknown values that might not to be represented in the original 8bit
space. (for example if the image has negative values).

You probably need to decide what to do with those new values out of bound in
the intended greyscale target space: keep them (so the new image will preserve
a version of the whole histogram but its parameters will now be different) or
ignore them (and that will will cut the information at the greyscale bounds
resulting in a "saturated" histogram).

Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Herbie
In reply to this post by Koen van dijken
Dear Koen van Dijken,

I can't confirm your finding ("two of the three resulting channels will
show black"), when using ("load it into ImageJ and proceed with step 5")
the nice 326x491 32bit image (what does it show?). You didn't mention
your setting of "Subtract background". I use all options unchecked or
"Light background" checked and the default radius 50.

Best

Herbie

:::::::::::::::::::::::::::::::::::::::::::::
Am 17.07.16 um 10:53 schrieb Koen van dijken:

> While finalising a new plugin I discovered a bug in Background Subtracter.
> In my own plugin I encounter a similar problem and do not know how to fix
> it. To reproduce the bug in Background Subtracter take the following steps:
>
> Bug in Background subtracter:
>
> 1: Load a tiff with three (double) channels
> 2: Image -> Color -> Split channels
> 3: for each slice (R, G and B): Image -> Type -> 32 bit
> 4: Image -> Color -> Merge channels
> 5: Process -> Subtract background
>
> You can also download this sample file from my dropbox:
>
> https://www.dropbox.com/s/r0wbvft0xh6wucr/merge32-1.tif?dl=0
>
> , load it into ImageJ and proceed with step 5.
>
> Now two of the three resulting channels will show black. They have sensible
> data but probably some min and max are off and so do not show properly.
>
> I noticed that by doing Image -> Adjust -> Window/Level -> Reset on the
> defective slice the image springs back and shows. I traced through the
> source of ij.plugin.frame.ContrastAdjuster.reset(ImagePlus, ImageProcessor)
> but did not succeed in taking similar steps in my own plugin to get the
> same result.
>
> Does anybody know how to reset a stack of 32-bit images to show properly
> after the values of the images have changed so much they fall outside their
> previous bounds? I suspect some series of ip.resetMinAndMax() but just that
> does not do.
>
> Greetings from Holland,
>
> Koen
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Koen van dijken
That is strange that you get expected results and I do not.
What is also strange is when I run Background Subtracter I see a red image
(only the red channel). When I save it and open it again I only see three
black slices in this tiff.

I am running ImageJ 1.151 on OSX 10.11.5.

I tried again, and my resulting image is attached to this mail (hope that's
possible through this listserver). A link to the resulting file on my
dropbox is

https://www.dropbox.com/s/3ipgqn0johoyg8d/subtract%20background%20merge32-1.tif?dl=0

The image shows part of the (internal) female genitals of Coleophora
flavipennella, a small micromoth.

Koen



On Sun, Jul 17, 2016 at 2:58 PM, Herbie <[hidden email]> wrote:

> Dear Koen van Dijken,
>
> I can't confirm your finding ("two of the three resulting channels will
> show black"), when using ("load it into ImageJ and proceed with step 5")
> the nice 326x491 32bit image (what does it show?). You didn't mention your
> setting of "Subtract background". I use all options unchecked or "Light
> background" checked and the default radius 50.
>
> Best
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::::::
> Am 17.07.16 um 10:53 schrieb Koen van dijken:
>
>> While finalising a new plugin I discovered a bug in Background Subtracter.
>> In my own plugin I encounter a similar problem and do not know how to fix
>> it. To reproduce the bug in Background Subtracter take the following
>> steps:
>>
>> Bug in Background subtracter:
>>
>> 1: Load a tiff with three (double) channels
>> 2: Image -> Color -> Split channels
>> 3: for each slice (R, G and B): Image -> Type -> 32 bit
>> 4: Image -> Color -> Merge channels
>> 5: Process -> Subtract background
>>
>> You can also download this sample file from my dropbox:
>>
>> https://www.dropbox.com/s/r0wbvft0xh6wucr/merge32-1.tif?dl=0
>>
>> , load it into ImageJ and proceed with step 5.
>>
>> Now two of the three resulting channels will show black. They have
>> sensible
>> data but probably some min and max are off and so do not show properly.
>>
>> I noticed that by doing Image -> Adjust -> Window/Level -> Reset on the
>> defective slice the image springs back and shows. I traced through the
>> source of ij.plugin.frame.ContrastAdjuster.reset(ImagePlus,
>> ImageProcessor)
>> but did not succeed in taking similar steps in my own plugin to get the
>> same result.
>>
>> Does anybody know how to reset a stack of 32-bit images to show properly
>> after the values of the images have changed so much they fall outside
>> their
>> previous bounds? I suspect some series of ip.resetMinAndMax() but just
>> that
>> does not do.
>>
>> Greetings from Holland,
>>
>> Koen
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

subtract background merge32-1.tif (2M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Herbie
Dear Koen van Dijken,

thanks for your reply!
The image is quite aesthetic but that's not the issue here...

Again I tried on the 326x491 32bit "merge32-1"-image:
  with no options checked I encounter no problems
  with "Light background" checked and moving through and especially
    _back_ the channels, I get black images that are restored by
    resetting B&C

Opening subtract the "background merge32-1"-image:
  all channels are displayed in black and the display is restored by
  resetting B&C

(ImageJ 1.51d, 64bit-Java 1.6.0_65, OSX 10.8.5)

Not sure what or whether there should be done something against...

Best

Herbie

:::::::::::::::::::::::::::::::::::::::::::::
Am 17.07.16 um 15:47 schrieb Koen van dijken:

> That is strange that you get expected results and I do not.
> What is also strange is when I run Background Subtracter I see a red image
> (only the red channel). When I save it and open it again I only see three
> black slices in this tiff.
>
> I am running ImageJ 1.151 on OSX 10.11.5.
>
> I tried again, and my resulting image is attached to this mail (hope that's
> possible through this listserver). A link to the resulting file on my
> dropbox is
>
> https://www.dropbox.com/s/3ipgqn0johoyg8d/subtract%20background%20merge32-1.tif?dl=0
>
> The image shows part of the (internal) female genitals of Coleophora
> flavipennella, a small micromoth.
>
> Koen
>
>
>
> On Sun, Jul 17, 2016 at 2:58 PM, Herbie <[hidden email]> wrote:
>
>> Dear Koen van Dijken,
>>
>> I can't confirm your finding ("two of the three resulting channels will
>> show black"), when using ("load it into ImageJ and proceed with step 5")
>> the nice 326x491 32bit image (what does it show?). You didn't mention your
>> setting of "Subtract background". I use all options unchecked or "Light
>> background" checked and the default radius 50.
>>
>> Best
>>
>> Herbie
>>
>> :::::::::::::::::::::::::::::::::::::::::::::
>> Am 17.07.16 um 10:53 schrieb Koen van dijken:
>>
>>> While finalising a new plugin I discovered a bug in Background Subtracter.
>>> In my own plugin I encounter a similar problem and do not know how to fix
>>> it. To reproduce the bug in Background Subtracter take the following
>>> steps:
>>>
>>> Bug in Background subtracter:
>>>
>>> 1: Load a tiff with three (double) channels
>>> 2: Image -> Color -> Split channels
>>> 3: for each slice (R, G and B): Image -> Type -> 32 bit
>>> 4: Image -> Color -> Merge channels
>>> 5: Process -> Subtract background
>>>
>>> You can also download this sample file from my dropbox:
>>>
>>> https://www.dropbox.com/s/r0wbvft0xh6wucr/merge32-1.tif?dl=0
>>>
>>> , load it into ImageJ and proceed with step 5.
>>>
>>> Now two of the three resulting channels will show black. They have
>>> sensible
>>> data but probably some min and max are off and so do not show properly.
>>>
>>> I noticed that by doing Image -> Adjust -> Window/Level -> Reset on the
>>> defective slice the image springs back and shows. I traced through the
>>> source of ij.plugin.frame.ContrastAdjuster.reset(ImagePlus,
>>> ImageProcessor)
>>> but did not succeed in taking similar steps in my own plugin to get the
>>> same result.
>>>
>>> Does anybody know how to reset a stack of 32-bit images to show properly
>>> after the values of the images have changed so much they fall outside
>>> their
>>> previous bounds? I suspect some series of ip.resetMinAndMax() but just
>>> that
>>> does not do.
>>>
>>> Greetings from Holland,
>>>
>>> Koen
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Gabriel Landini
In reply to this post by Koen van dijken
On Sunday 17 Jul 2016 15:47:01 Koen van dijken wrote:
> That is strange that you get expected results and I do not.
> What is also strange is when I run Background Subtracter I see a red image
> (only the red channel). When I save it and open it again I only see three
> black slices in this tiff.

This macro confirms what I suggested in my previous email, and how to avoid
the 'red image' (which is what happens when you process a single composite
channel).
To work with an RGB image, just uncomment the RGB line and delete the
following line.
 
If you want to process the composite in 32bit, I think you need to subtract
the background for each channel (so, select the next [green] channel, apply
background subtraction, and do the same for the third channel).

However that is not without further complications, as it gives a different
result than a processing the RGB image in one go because the composite
channels do not have the same predictable histogram ranges for display (see
that after subtracting the background the channels have lots of negative
values).
Not sure how you should re-scale those channels after the subtraction, sorry.

- - -
run("Lena (68K)");
run("Split Channels");

selectWindow("lena-std.tif (red)");
run("32-bit");
setMinAndMax(0, 255);
selectWindow("lena-std.tif (green)");
run("32-bit");
setMinAndMax(0, 255);
selectWindow("lena-std.tif (blue)");
run("32-bit");
setMinAndMax(0, 255);

//run("Merge Channels...", "c1=[lena-std.tif (red)] c2=[lena-std.tif (green)]
c3=[lena-std.tif (blue)] "); // RGB

run("Merge Channels...", "c1=[lena-std.tif (red)] c2=[lena-std.tif (green)]
c3=[lena-std.tif (blue)] create"); //composite

run("Subtract Background...", "rolling=50 light");
- - -

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Bug in Background Subtracter

Pablo Ingino
In reply to this post by Koen van dijken
Hey Koen,

I made a quick test on your example files and get the same results.
However this is only affecting the display of your data. Take a close
look on Fijis main window as you hover over the image. It will tell
you the coordinates  of your cursor and a value. That should tell
you that there is something, although it is currently not displayed
on screen. Simply go to brightnes&contrast and press the reset button for
every channel and you should see everything again!

Cheers
Pablo

On 7/17/2016 3:47 PM, Koen van dijken wrote:

> That is strange that you get expected results and I do not.
> What is also strange is when I run Background Subtracter I see a red image
> (only the red channel). When I save it and open it again I only see three
> black slices in this tiff.
>
> I am running ImageJ 1.151 on OSX 10.11.5.
>
> I tried again, and my resulting image is attached to this mail (hope that's
> possible through this listserver). A link to the resulting file on my
> dropbox is
>
> https://www.dropbox.com/s/3ipgqn0johoyg8d/subtract%20background%20merge32-1.tif?dl=0
>
> The image shows part of the (internal) female genitals of Coleophora
> flavipennella, a small micromoth.
>
> Koen
>
>
>
> On Sun, Jul 17, 2016 at 2:58 PM, Herbie <[hidden email]> wrote:
>
>> Dear Koen van Dijken,
>>
>> I can't confirm your finding ("two of the three resulting channels will
>> show black"), when using ("load it into ImageJ and proceed with step 5")
>> the nice 326x491 32bit image (what does it show?). You didn't mention your
>> setting of "Subtract background". I use all options unchecked or "Light
>> background" checked and the default radius 50.
>>
>> Best
>>
>> Herbie
>>
>> :::::::::::::::::::::::::::::::::::::::::::::
>> Am 17.07.16 um 10:53 schrieb Koen van dijken:
>>
>>> While finalising a new plugin I discovered a bug in Background Subtracter.
>>> In my own plugin I encounter a similar problem and do not know how to fix
>>> it. To reproduce the bug in Background Subtracter take the following
>>> steps:
>>>
>>> Bug in Background subtracter:
>>>
>>> 1: Load a tiff with three (double) channels
>>> 2: Image -> Color -> Split channels
>>> 3: for each slice (R, G and B): Image -> Type -> 32 bit
>>> 4: Image -> Color -> Merge channels
>>> 5: Process -> Subtract background
>>>
>>> You can also download this sample file from my dropbox:
>>>
>>> https://www.dropbox.com/s/r0wbvft0xh6wucr/merge32-1.tif?dl=0
>>>
>>> , load it into ImageJ and proceed with step 5.
>>>
>>> Now two of the three resulting channels will show black. They have
>>> sensible
>>> data but probably some min and max are off and so do not show properly.
>>>
>>> I noticed that by doing Image -> Adjust -> Window/Level -> Reset on the
>>> defective slice the image springs back and shows. I traced through the
>>> source of ij.plugin.frame.ContrastAdjuster.reset(ImagePlus,
>>> ImageProcessor)
>>> but did not succeed in taking similar steps in my own plugin to get the
>>> same result.
>>>
>>> Does anybody know how to reset a stack of 32-bit images to show properly
>>> after the values of the images have changed so much they fall outside
>>> their
>>> previous bounds? I suspect some series of ip.resetMinAndMax() but just
>>> that
>>> does not do.
>>>
>>> Greetings from Holland,
>>>
>>> Koen
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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