How to set the background value to the same value for a stack of images

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

How to set the background value to the same value for a stack of images

jklwp007
Hello everyone,

I am new here, and I have a question about set up background value of a stack of images. I got a lot time-lapse images (70 images for a stack). Due to the fluctuation of the illumination, I can not get a stable trace out of the stack. I want to set the background to a same value of all images of one stack. I can not find any macro or plugins that is helpful. Does anyone know how to solve this problem? I think the stupidest way is to subtract each single image to a same value of background, but it is too waste of time. I have too much images to deal with. I appreciate anyone that can help me out.

Thank you!
Reply | Threaded
Open this post in threaded view
|

Re: How to set the background value to the same value for a stack of images

Cammer, Michael
maybe this?


//===================================================================
//  This macro measures the same region of interest in each slice of a stack and subtracts the mean plus
//  specified standard deviation of the mean from each corresponding slice.  It is useful for situations where
//  there is background intensity changing over time due to something like a flickering light source and you
//  want the stack's background to be uniform.
//  To use, put a ROI over a region that is background in all slices.  (Choose the ROI on a maximum pixel
//  projection if features to assure only bg pixels are included.)  Run the macro.
//
macro 'Subtract background based on ROI'{
  n = 0;  // this is the number of standard deviations to add to the mean bg to subtract
  //checkCurrentVersion();
  image_to_process = getImageID();
  run("Set Measurements...", "  mean  standard  redirect=None decimal=5");
  run("Plot Z-axis Profile");    
  run("Close");
  selectImage(image_to_process);
  run("Select All");
  for (i=1; i<=nSlices; i++){
    bgmean=getResult("Mean",(i-1)) + n*getResult("StdDev",(i-1));
    run("Set Slice...", "slice="+i);
    run("Subtract...", "slice value="+bgmean);
  } // for loop
  run("Select None");
  run("Min...", "value=0 stack");  // if type was 32 bit
  resetMinAndMax();
} // Subtract background based on ROI
_________________________________________
Michael Cammer, Optical Microscopy Specialist
http://ocs.med.nyu.edu/microscopy
http://microscopynotes.com/
Cell: (914) 309-3270

________________________________________
From: ImageJ Interest Group [[hidden email]] on behalf of jklwp007 [[hidden email]]
Sent: Thursday, June 15, 2017 6:32 PM
To: [hidden email]
Subject: How to set the background value to the same value for a stack of images

Hello everyone,

I am new here, and I have a question about set up background value of a
stack of images. I got a lot time-lapse images (70 images for a stack). Due
to the fluctuation of the illumination, I can not get a stable trace out of
the stack. I want to set the background to a same value of all images of one
stack. I can not find any macro or plugins that is helpful. Does anyone know
how to solve this problem? I think the stupidest way is to subtract each
single image to a same value of background, but it is too waste of time. I
have too much images to deal with. I appreciate anyone that can help me out.

Thank you!




--
View this message in context: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.1557.x6.nabble.com_How-2Dto-2Dset-2Dthe-2Dbackground-2Dvalue-2Dto-2Dthe-2Dsame-2Dvalue-2Dfor-2Da-2Dstack-2Dof-2Dimages-2Dtp5018903.html&d=DQICAg&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=9qx9jEGKKHdLKqPoT3sLw5rgwn1FNzHhVsFf2ZwXqis&s=bbNSoWp7Hn5fPEE8dZxz68aV2FkA3g6b28wWQeRI8W0&e=
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DQICAg&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=9qx9jEGKKHdLKqPoT3sLw5rgwn1FNzHhVsFf2ZwXqis&s=qJQFpGcCOhFoqEQKC5bS1iZ5JIyH_sT8j220zzh47MI&e=

------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================

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

Re: How to set the background value to the same value for a stack of images

jklwp007
Hi,

Thank you for your quick replying. I tried this on a couple of my images, but it did not uniform the background. Should I change any parameter in that macro?
Reply | Threaded
Open this post in threaded view
|

Re: How to set the background value to the same value for a stack of images

Michael Schmid
Hi anonymous,

Michael's macro assumes that area and brightness of the foreground
objects are roughly the same for all stack slices and there is mostly
background in the image.

If this is not the case, for 8-bit images you could try using the Modal
Gray Value instead of the Mean. Omit the "n*getResult("StdDev",(i-1)".
Unfortunately, for 16-bit images the Modal Gray Value gives unreliable
results because of binning the pixel values to 256 bins; some bins
contain more 16-bit values than others. In that case, you have to
retrieve the 16-bit histogram and process it yourself.

You could also try using the Minimum or Maximum gray value (depends on
whether you have a dark or bright background) instead of the Mean, but
this is very sensitive to noise and outliers. A better alternative would
be creating a duplicate of the stack, smoothing it or filtering by a
median filter, and using the min or max gray value of this filtered stack.

Please also note that Michael's macro is for images without pixel value
calibration, and there should be no active selection (ROI) when it is
run - you might add 'run("Select None");' to ensure this is the case.

- Another Michael
________________________________________________________________
On 16/06/2017 19:16, jklwp007 wrote:
> Hi,
>
> Thank you for your quick replying. I tried this on a couple of my images,
> but it did not uniform the background. Should I change any parameter in that
> macro?
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/How-to-set-the-background-value-to-the-same-value-for-a-stack-of-images-tp5018903p5018910.html

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

Re: How to set the background value to the same value for a stack of images

Schebique
Hi.
Would Image>Adjust...>Bleach correction help?

Ondrej

Dne 16. 6. 2017 7:43 odp. napsal uživatel "Michael Schmid" <
[hidden email]>:

> Hi anonymous,
>
> Michael's macro assumes that area and brightness of the foreground objects
> are roughly the same for all stack slices and there is mostly background in
> the image.
>
> If this is not the case, for 8-bit images you could try using the Modal
> Gray Value instead of the Mean. Omit the "n*getResult("StdDev",(i-1)".
> Unfortunately, for 16-bit images the Modal Gray Value gives unreliable
> results because of binning the pixel values to 256 bins; some bins contain
> more 16-bit values than others. In that case, you have to retrieve the
> 16-bit histogram and process it yourself.
>
> You could also try using the Minimum or Maximum gray value (depends on
> whether you have a dark or bright background) instead of the Mean, but this
> is very sensitive to noise and outliers. A better alternative would be
> creating a duplicate of the stack, smoothing it or filtering by a median
> filter, and using the min or max gray value of this filtered stack.
>
> Please also note that Michael's macro is for images without pixel value
> calibration, and there should be no active selection (ROI) when it is run -
> you might add 'run("Select None");' to ensure this is the case.
>
> - Another Michael
> ________________________________________________________________
> On 16/06/2017 19:16, jklwp007 wrote:
>
>> Hi,
>>
>> Thank you for your quick replying. I tried this on a couple of my images,
>> but it did not uniform the background. Should I change any parameter in
>> that
>> macro?
>>
>>
>> --
>> View this message in context: http://imagej.1557.x6.nabble.c
>> om/How-to-set-the-background-value-to-the-same-value-for-a-s
>> tack-of-images-tp5018903p5018910.html
>>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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