1-D Gaussian multiplier/convolution function around line in image.

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

1-D Gaussian multiplier/convolution function around line in image.

Cohen, Ethan D

I have an image, where I want to vertically weight the intensity the pixels, by a 1-D Gaussian function around a horizontal line ROI in the image, so that the peak is 3X the original intensity, with a Gaussian ½ bandwidth of say 15 pixels in the Y direction.

Something like, v=3v* exp (-b*(y-y0)^2  -1*(y-y0));?

Or maybe ImageJ already has a feature for 1-D Gaussian weighting (not blur)?   I guess this is sort of a 1-D convolution.

Is there a function already in ImageJ to do this?
I suppose I could make some sort of weighting matrix, but it seems rather painful.

Ethan.


Ethan Cohen, Ph.D.
Div of Biomedical Physics, WO62 Rm 1204
Office of Science and Engineering Labs,
FDA Center for Devices and Radiological Health
White Oak Federal Res Ctr.
10903 New Hampshire Ave.
Silver Spring, MD 20993
Web: http://go.usa.gov/cegV3
Office: 301-796-2485
Lab:301-796-2762
Fax: 301-796-9927
Cell: 301-538-7544

[cid:image001.png@01D1C57E.DFA022A0]<http://www.fda.gov/>Excellent customer service is important to us. Please take a moment to provide feedback regarding the customer service you have received: https://www.research.net/s/cdrhcustomerservice?O=700&D=740&B=740&E=&S=E
"THIS MESSAGE FROM ETHAN COHEN IS INTENDED ONLY FOR THE USE OF THE PARTY TO WHOM IT IS ADDRESSED AND MAY CONTAIN INFORMATION THAT IS PRIVILEGED, CONFIDENTIAL, AND PROTECTED FROM DISCLOSURE UNDER LAW. If you are not the addressee, or a person authorized to deliver the document to the addressee, you are hereby notified that any review, disclosure, dissemination, copying, or other action based on the content of this communication is not authorized. If you have received this document in error, please immediately notify the sender immediately by e-mail or phone."
________________________________


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

image001.gif (1K) Download Attachment
image002.png (11K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: 1-D Gaussian multiplier/convolution function around line in image.

Herbie
Good day Ethan,

you may use the ImageJ-functionality that is accessible from "Process >>
Math >> Macro..."

Enter the following code to the Code-line:

b=0.001; v=v*3*exp(-b*(y-h*0.5)*(y-h*0.5));

This Image-Math macro works for 32bit images and the Gauss-width is
defined by variable b.

The Gauss-width should *not* be called bandwidth if your image isn't a
Fourier-spectral signal.

Of course, the Gauss-function acts as a weighting window, i.e. it does
*not* perform a convolution!

Regards

Herbie

::::::::::::::::::::::::::::::::::::::::::::
Am 26.01.19 um 02:36 schrieb Cohen, Ethan D:

>
> I have an image, where I want to vertically weight the intensity the pixels, by a 1-D Gaussian function around a horizontal line ROI in the image, so that the peak is 3X the original intensity, with a Gaussian ½ bandwidth of say 15 pixels in the Y direction.
>
> Something like, v=3v* exp (-b*(y-y0)^2  -1*(y-y0));?
>
> Or maybe ImageJ already has a feature for 1-D Gaussian weighting (not blur)?   I guess this is sort of a 1-D convolution.
>
> Is there a function already in ImageJ to do this?
> I suppose I could make some sort of weighting matrix, but it seems rather painful.
>
> Ethan.
>
>
> Ethan Cohen, Ph.D.
> Div of Biomedical Physics, WO62 Rm 1204
> Office of Science and Engineering Labs,
> FDA Center for Devices and Radiological Health
> White Oak Federal Res Ctr.
> 10903 New Hampshire Ave.
> Silver Spring, MD 20993
> Web: http://go.usa.gov/cegV3
> Office: 301-796-2485
> Lab:301-796-2762
> Fax: 301-796-9927
> Cell: 301-538-7544
>
> [cid:image001.png@01D1C57E.DFA022A0]<http://www.fda.gov/>Excellent customer service is important to us. Please take a moment to provide feedback regarding the customer service you have received: https://www.research.net/s/cdrhcustomerservice?O=700&D=740&B=740&E=&S=E
> "THIS MESSAGE FROM ETHAN COHEN IS INTENDED ONLY FOR THE USE OF THE PARTY TO WHOM IT IS ADDRESSED AND MAY CONTAIN INFORMATION THAT IS PRIVILEGED, CONFIDENTIAL, AND PROTECTED FROM DISCLOSURE UNDER LAW. If you are not the addressee, or a person authorized to deliver the document to the addressee, you are hereby notified that any review, disclosure, dissemination, copying, or other action based on the content of this communication is not authorized. If you have received this document in error, please immediately notify the sender immediately by e-mail or phone."
> ________________________________
>
>
> --
> 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: 1-D Gaussian multiplier/convolution function around line in image.

Michael Schmid-3
In reply to this post by Cohen, Ethan D
Hi Ethan,

is it right that you want the weighted *sum* over the pixels at fixed x?

Then, even if you don't need a convolution, the easiest might be doing
the 1D convolution and then selecting the value at the y position of
choice.

ImageJ has the possibility to do a 1D Gaussian blur (because 2D Gaussian
blur is done by blurring successively in x and y), but there is
currently no function in the user interface for it.

You can access it via Java or JavaScript:

   ip = IJ.getImage().getProcessor();
   g = new GaussianBlur();
   g.blurGaussian(ip, 0.0, 6.37, 0.001);
   IJ.getImage().updateAndDraw();

The four parameters of blurGaussian are the ImageProcessor, the sigma in
x, the sigma in y, and the accuracy of the kernel (the latter must be
less than 0.02; recommended values are 0.002 for 8-bit or RGB and and
0.00001 - 0.0002 for 16-bit or floating-point images.

Sigma is the length in pixels where the kernel decays from the maximum
(1) to 1/sqrt(e); the value of 6.37 gives you a FWHM (full width at half
maximum) of 15.

Note that the convolution is scaled such that if you have a constant
pixel value, his value is preserved after the convolution. In your
suggested equation, the sum would increase with the width of the
Gaussian, which is proportional to 1/sqrt(b).

Of course, you can also write a macro for it, or use Herbie's
Process>Math>macro and then add up all the pixels along a vertical line
(e.g., 'select all' and 'plot profile' will give you the average over
the pixel columns; multiply them with the image height to get the sum.)


Michael
________________________________________________________________




On 2019-01-26 02:36, Cohen, Ethan D wrote:

> I have an image, where I want to vertically weight the intensity the
> pixels, by a 1-D Gaussian function around a horizontal line ROI in the
> image, so that the peak is 3X the original intensity, with a Gaussian
> ½ bandwidth of say 15 pixels in the Y direction.
>
> Something like, v=3v* exp (-b*(y-y0)^2  -1*(y-y0));?
>
> Or maybe ImageJ already has a feature for 1-D Gaussian weighting (not
> blur)?   I guess this is sort of a 1-D convolution.
>
> Is there a function already in ImageJ to do this?
> I suppose I could make some sort of weighting matrix, but it seems
> rather painful.
>
> Ethan.
>
>
> Ethan Cohen, Ph.D.
> Div of Biomedical Physics, WO62 Rm 1204
> Office of Science and Engineering Labs,
> FDA Center for Devices and Radiological Health
> White Oak Federal Res Ctr.
> 10903 New Hampshire Ave.
> Silver Spring, MD 20993
> Web: http://go.usa.gov/cegV3
> Office: 301-796-2485
> Lab:301-796-2762
> Fax: 301-796-9927
> Cell: 301-538-7544
>
> [cid:image001.png@01D1C57E.DFA022A0]<http://www.fda.gov/>Excellent
> customer service is important to us. Please take a moment to provide
> feedback regarding the customer service you have received:
> https://www.research.net/s/cdrhcustomerservice?O=700&D=740&B=740&E=&S=E
> "THIS MESSAGE FROM ETHAN COHEN IS INTENDED ONLY FOR THE USE OF THE
> PARTY TO WHOM IT IS ADDRESSED AND MAY CONTAIN INFORMATION THAT IS
> PRIVILEGED, CONFIDENTIAL, AND PROTECTED FROM DISCLOSURE UNDER LAW. If
> you are not the addressee, or a person authorized to deliver the
> document to the addressee, you are hereby notified that any review,
> disclosure, dissemination, copying, or other action based on the
> content of this communication is not authorized. If you have received
> this document in error, please immediately notify the sender
> immediately by e-mail or phone."
> ________________________________
>
>
> --
> 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: 1-D Gaussian multiplier/convolution function around line in image.

Cohen, Ethan D
In reply to this post by Cohen, Ethan D
Thanks Herbie:
That worked.  b=0.001; v=v*3*exp(-b*(y-h*0.5)*(y-h*0.5));
Nice.

So I am trying to make a macro using  to feed in the cursor Y level value using your code to modify an image stack.

Say the image is w=500, h = 1000.


So I look at https://imagej.nih.gov/ij/macros/examples/MathMacroDemo.txt demo

I see on the comment line:

// All built-in variables and functions of the IJ macro language can be used in
// the specified formula

So my macro collects the cursor Y value, which I call Ylevel.

run("Macro...", "code=[b=0.001; v=v*3*exp(-b*(y-Ylevel)*(y-Ylevel))] stack");

But this does not run, because Ylevel is not a "Built-in variable in ImageJ".
but if I manually put a number instead of Y level it works.

How to fix?

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

Re: 1-D Gaussian multiplier/convolution function around line in image.

Herbie
good day Cohen,

please try to familiarize with the macro language:
<https://imagej.nih.gov/ij/developer/macro/macros.html>
<https://imagej.nih.gov/ij/developer/macro/functions.html>

This works for me:

Ylevel = 164;
run("Macro...", "code=[a="+Ylevel+"; b=0.001; v=v*3*exp(-b*(y-a)*(y-a))]");

Please watch out for unwanted line breaks!

Regards

Herbie

:::::::::::::::::::::::::::::::::::::::::
Am 30.01.19 um 00:30 schrieb Ethan Cohen:

> Thanks Herbie:
> That worked.  b=0.001; v=v*3*exp(-b*(y-h*0.5)*(y-h*0.5));
> Nice.
>
> So I am trying to make a macro using  to feed in the cursor Y level value using your code to modify an image stack.
>
> Say the image is w=500, h = 1000.
>
>
> So I look at https://imagej.nih.gov/ij/macros/examples/MathMacroDemo.txt demo
>
> I see on the comment line:
>
> // All built-in variables and functions of the IJ macro language can be used in
> // the specified formula
>
> So my macro collects the cursor Y value, which I call Ylevel.
>
> run("Macro...", "code=[b=0.001; v=v*3*exp(-b*(y-Ylevel)*(y-Ylevel))] stack");
>
> But this does not run, because Ylevel is not a "Built-in variable in ImageJ".
> but if I manually put a number instead of Y level it works.
>
> How to fix?
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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