Gradient in stack - how to fix?

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

Gradient in stack - how to fix?

ckthomps
I have a stack of 256 images that have a light/dark gradient from right to left that I would like to flatten. I've tried reslicing the stack, so that each slice in the stack could be adjusted for contrast/brightness. In other words, the brightest image is at the top of the stack and the darkest at the bottom. The problem is that each slice needs to be treated differently. Auto adjust seems to do a fine job for whichever slice I'm looking at, but it is too dark before that slice and too bright after that slice. Is there a way to get ImageJ to run auto adjust on each slice in the stack individually? I'm sure there is some batch-processing trick I could do, but I'm a novice and can't figure that out on my own.

Thanks,

CKT
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

Michael Schmid
Hi CKT,

what about fitting a gradient (1st-order polynomial) to each slice?
   http://imagejdocu.tudor.lu/doku.php?
id=plugin:filter:fit_polynomial:start

You could have a selection to exclude foreground objects when fitting  
the polynomial, e.g. threshold the image to get only the background  
and use Edit>Selection>Create Selection.

If you want to subtract the same gradient from all, you can create a  
single background image from one of the slices and use Process>Image  
Calculator to subtract it from the stack.

It works best with 32-bit (float) images:  With floats, you can't run  
into overflow of pixel values when subtracting.

Michael
________________________________________________________________

On 1 Dec 2011, at 19:45, ckthomps wrote:

> I have a stack of 256 images that have a light/dark gradient from  
> right to
> left that I would like to flatten. I've tried reslicing the stack,  
> so that
> each slice in the stack could be adjusted for contrast/brightness.  
> In other
> words, the brightest image is at the top of the stack and the  
> darkest at the
> bottom. The problem is that each slice needs to be treated  
> differently. Auto
> adjust seems to do a fine job for whichever slice I'm looking at,  
> but it is
> too dark before that slice and too bright after that slice. Is  
> there a way
> to get ImageJ to run auto adjust on each slice in the stack  
> individually?
> I'm sure there is some batch-processing trick I could do, but I'm a  
> novice
> and can't figure that out on my own.
>
> Thanks,
>
> CKT
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

Aryeh Weiss
In reply to this post by ckthomps
On 12/1/11 8:45 PM, ckthomps wrote:

> I have a stack of 256 images that have a light/dark gradient from right to
> left that I would like to flatten. I've tried reslicing the stack, so that
> each slice in the stack could be adjusted for contrast/brightness. In other
> words, the brightest image is at the top of the stack and the darkest at the
> bottom. The problem is that each slice needs to be treated differently. Auto
> adjust seems to do a fine job for whichever slice I'm looking at, but it is
> too dark before that slice and too bright after that slice. Is there a way
> to get ImageJ to run auto adjust on each slice in the stack individually?
> I'm sure there is some batch-processing trick I could do, but I'm a novice
> and can't figure that out on my own.
>

Try using the Nonuniform Background Removal plugin
http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:nonuniform_background_removal:start

It can create a background estimate of each image in the stack (this is
a stack of backgrounds corresponding to your stack). You can then use
this to correct the stack in whatever way is appropriate.

This will work if you can define a set of ROIs on the background from
which a plane of cubic spline can be fit.  It is well suited for the
case where a single ROI set can be used to define the background of all
of the slices in the stack.

--aryeh
--
Aryeh Weiss
School of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

Joel Sheffield
In reply to this post by ckthomps
Aother possibility would be to use the bandpass filter in the FFT menu.  In
principle, you can consider a dark to light gradient to be a portion of a
very large period sinusoid, so if you ask the bandpass filter to exclude
such large periods, you will flatten the image. Set the maximum value at
40-100 to start, and the min to 0.  There is an option to process an entire
stack.   There is also an option to normalize the resulting contrast range.

Best of luck,

Joel


On Thu, Dec 1, 2011 at 1:45 PM, ckthomps <[hidden email]> wrote:

> I have a stack of 256 images that have a light/dark gradient from right to
> left that I would like to flatten. I've tried reslicing the stack, so that
> each slice in the stack could be adjusted for contrast/brightness. In other
> words, the brightest image is at the top of the stack and the darkest at
> the
> bottom. The problem is that each slice needs to be treated differently.
> Auto
> adjust seems to do a fine job for whichever slice I'm looking at, but it is
> too dark before that slice and too bright after that slice. Is there a way
> to get ImageJ to run auto adjust on each slice in the stack individually?
> I'm sure there is some batch-processing trick I could do, but I'm a novice
> and can't figure that out on my own.
>
> Thanks,
>
> CKT
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/Gradient-in-stack-how-to-fix-tp7051603p7051603.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>



--


Joel B. Sheffield, Ph.D
Department of Biology
Temple University
Philadelphia, PA 19122
Voice: 215 204 8839
e-mail: [hidden email]
URL:  http://astro.temple.edu/~jbs
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

Robert Dougherty
In reply to this post by Aryeh Weiss
Another plugin to try is Polynomial Shading Corrector on the OptiNav site.  It scales the image instead of subtracting something.

Bob

On Dec 1, 2011, at 12:37 PM, Aryeh Weiss wrote:

> On 12/1/11 8:45 PM, ckthomps wrote:
>> I have a stack of 256 images that have a light/dark gradient from right to
>> left that I would like to flatten. I've tried reslicing the stack, so that
>> each slice in the stack could be adjusted for contrast/brightness. In other
>> words, the brightest image is at the top of the stack and the darkest at the
>> bottom. The problem is that each slice needs to be treated differently. Auto
>> adjust seems to do a fine job for whichever slice I'm looking at, but it is
>> too dark before that slice and too bright after that slice. Is there a way
>> to get ImageJ to run auto adjust on each slice in the stack individually?
>> I'm sure there is some batch-processing trick I could do, but I'm a novice
>> and can't figure that out on my own.
>>
>
> Try using the Nonuniform Background Removal plugin
> http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:nonuniform_background_removal:start
>
> It can create a background estimate of each image in the stack (this is a stack of backgrounds corresponding to your stack). You can then use this to correct the stack in whatever way is appropriate.
>
> This will work if you can define a set of ROIs on the background from which a plane of cubic spline can be fit.  It is well suited for the case where a single ROI set can be used to define the background of all of the slices in the stack.
>
> --aryeh
> --
> Aryeh Weiss
> School of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051

Robert Dougherty, Ph.D.
President, OptiNav, Inc.
1414 127th Place NE #106
Bellevue, WA 98005
Tel. (425)891-4883
FAX (425)467-1119
www.optinav.com
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

Thomas Eschner
In reply to this post by ckthomps
Hi,

there already were several suggestions; here's another one: Make a copy of the stack and run a broad Gaussian filter smoothing the features. Then take an average of all those images.
If the shading is persistent and the images are not too similar, this could give a sufficiently good background estimate.
Use the image calculator to subtract it from the original stack adding an appropriate shift of e.g. 64 or 128.

Regards,
Thomas

-------- Original-Nachricht --------
> Datum: Thu, 1 Dec 2011 10:45:52 -0800
> Von: ckthomps <[hidden email]>
> An: [hidden email]
> Betreff: Gradient in stack - how to fix?

> I have a stack of 256 images that have a light/dark gradient from right to
> left that I would like to flatten. I've tried reslicing the stack, so that
> each slice in the stack could be adjusted for contrast/brightness. In
> other
> words, the brightest image is at the top of the stack and the darkest at
> the
> bottom. The problem is that each slice needs to be treated differently.
> Auto
> adjust seems to do a fine job for whichever slice I'm looking at, but it
> is
> too dark before that slice and too bright after that slice. Is there a way
> to get ImageJ to run auto adjust on each slice in the stack individually?
> I'm sure there is some batch-processing trick I could do, but I'm a novice
> and can't figure that out on my own.
>
> Thanks,
>
> CKT
>
> --
> View this message in context:
> http://imagej.588099.n2.nabble.com/Gradient-in-stack-how-to-fix-tp7051603p7051603.html
> Sent from the ImageJ mailing list archive at Nabble.com.

--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
Reply | Threaded
Open this post in threaded view
|

Re: Gradient in stack - how to fix?

ckthomps
Hi all-

Thanks for the many suggestions. I wasn't able to try all of them, so
I can't say for sure that others would work. I was able to come up
with a solution on my own. The problem with some solutions offered
(Gaussian, FFT, single-order polynomial) was that various parts of the
background has pixel-intensity values that correspond to values in my
object of interest. Thus these solutions were washing out my object.

Anyway, what I ended up doing is something along the lines of what I
initially suggested.  I resliced my stack so that the gradient
followed the z-axis. I saved the stack as an image sequence. Then I
generated this macro to process all images in the folder:

*********************************************
 origen = getDirectory("Images to process");
 destino = getDirectory("Results");
 lista = getFileList(origen);
 setBatchMode(true);
 for (i=0; i<lista.length; i++) {
  showProgress(i+1, lista.length);
  open(origen+lista[i]);
  nombre = lista[i];
        run("Enhance Contrast", "saturated=0.35");
  saveAs(".tiff", destino + nombre);
  close();
  }
*************************************************
Then I opened the image sequence back up as a stack and resliced it
back to it's original orientation. It's not prefect, because the
gradient is pretty bad (almost from pure black to pure white). Thus
it's a little grainy at the edges. But it's good enough!

Thanks for the help.

CKT

Then all im
On Thu, Dec 1, 2011 at 2:41 PM, Thomas Eschner <[hidden email]> wrote:

> Hi,
>
> there already were several suggestions; here's another one: Make a copy of the stack and run a broad Gaussian filter smoothing the features. Then take an average of all those images.
> If the shading is persistent and the images are not too similar, this could give a sufficiently good background estimate.
> Use the image calculator to subtract it from the original stack adding an appropriate shift of e.g. 64 or 128.
>
> Regards,
> Thomas
>
> -------- Original-Nachricht --------
>> Datum: Thu, 1 Dec 2011 10:45:52 -0800
>> Von: ckthomps <[hidden email]>
>> An: [hidden email]
>> Betreff: Gradient in stack - how to fix?
>
>> I have a stack of 256 images that have a light/dark gradient from right to
>> left that I would like to flatten. I've tried reslicing the stack, so that
>> each slice in the stack could be adjusted for contrast/brightness. In
>> other
>> words, the brightest image is at the top of the stack and the darkest at
>> the
>> bottom. The problem is that each slice needs to be treated differently.
>> Auto
>> adjust seems to do a fine job for whichever slice I'm looking at, but it
>> is
>> too dark before that slice and too bright after that slice. Is there a way
>> to get ImageJ to run auto adjust on each slice in the stack individually?
>> I'm sure there is some batch-processing trick I could do, but I'm a novice
>> and can't figure that out on my own.
>>
>> Thanks,
>>
>> CKT
>>
>> --
>> View this message in context:
>> http://imagej.588099.n2.nabble.com/Gradient-in-stack-how-to-fix-tp7051603p7051603.html
>> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de



--
CKT