Java code for redirecting to original image under set measurements

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

Java code for redirecting to original image under set measurements

Rohitesh Gupta
Hi Guys,

I am struggling to find out how to write a java code for setting original image in "redirect to" under the "set measurements" tab. Basically, I want to create a plugin using this code. Could anyone help in this direction ? The original Java code I recorded using "Record Macro" on imagej but that creates a code for specific image file. I want to create a generic code which can run on any image file. Hoping that i am making sense here, please let me know.

Thanks,
Rohitesh

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

Re: Java code for redirecting to original image under set measurements

Ziqiang Huang-2
Please study this code:
https://github.com/imagej/imagej1/blob/master/ij/plugin/filter/Analyzer.java

“ImagePlus redirectImage”
 is what you are looking for.

Good luck.

On Fri, 10 May 2019 at 05:17, Rohitesh Gupta <[hidden email]>
wrote:

> Hi Guys,
>
> I am struggling to find out how to write a java code for setting original
> image in "redirect to" under the "set measurements" tab. Basically, I want
> to create a plugin using this code. Could anyone help in this direction ?
> The original Java code I recorded using "Record Macro" on imagej but that
> creates a code for specific image file. I want to create a generic code
> which can run on any image file. Hoping that i am making sense here, please
> let me know.
>
> Thanks,
> Rohitesh
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
Ziqiang Huang

Bioimage Analyst of Light Microscopy Facility
CRUK Cambridge Institute
Li Ka Shing Centre
Robinson Way
Cambridge, UK
CB2 0RE
01223-769538
email: [hidden email] <[hidden email]>

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

Re: Java code for redirecting to original image under set measurements

Rohitesh Gupta
In reply to this post by Rohitesh Gupta
Thanks for your email. But, is there a better way to do this ? Any more suggestions.

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

Re: Java code for redirecting to original image under set measurements

Ziqiang Huang-2
I am not sure what you mean by “better”, but another way to check this is
through images api:
https://imagej.nih.gov/ij/developer/api/ij/plugin/filter/Analyzer.html#setRedirectImage-ij.ImagePlus-


   - setRedirectImage

   public static void setRedirectImage(ImagePlus
<https://imagej.nih.gov/ij/developer/api/ij/ImagePlus.html> imp)

   Set the "Redirect To" image. Pass 'null' as the argument to disable
   redirected sampling.

It’s quite clear and simple to use this function. Just assign the ImagePlus
instance of your original image as the input. Give it a try.

On a side note:
You didn’t share your code, and at least to me your description of the
problem was not clear. Therefore, help or suggestion can be limited. It’s
also not clear to me whether you want to create a plugin, a script, or a
macro. On one part you said you trying to make a plugin, and on another
part it seems like a macro. You didn’t mention which language you set the
macro recorder to, plus what code generated either. Purely guessing from
the context, a macro (in imagej macro language) should be sufficient to
fulfill what you want to achieve. Then you don’t even need to worry about
the java code .

Good luck.

On Fri, 10 May 2019 at 15:35, Rohitesh Gupta <[hidden email]>
wrote:

> Thanks for your email. But, is there a better way to do this ? Any more
> suggestions.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
--
Ziqiang Huang

Bioimage Analyst of Light Microscopy Facility
CRUK Cambridge Institute
Li Ka Shing Centre
Robinson Way
Cambridge, UK
CB2 0RE
01223-769538
email: [hidden email] <[hidden email]>

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

Re: Java code for redirecting to original image under set measurements

Rohitesh Gupta
Thanks for the help. I will try this in the code.
I am new to JAVA and so really don't understand the language that much. May be I will give it a shot and see if anything works out. Is there a way to check line by line execution of the code ?


-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Ziqiang Huang
Sent: Friday, May 10, 2019 10:22 AM
To: [hidden email]
Subject: Re: Java code for redirecting to original image under set measurements

 Non-UNMC email

I am not sure what you mean by “better”, but another way to check this is through images api:
https://urldefense.proofpoint.com/v2/url?u=https-3A__imagej.nih.gov_ij_developer_api_ij_plugin_filter_Analyzer.html-23setRedirectImage-2Dij.ImagePlus-2D&d=DwIFaQ&c=ZukO2fIan9e5E9v43wuy1w&r=34-TUupgH50lxe-gJRTc3Sa1yQ018sXW8kPlA42xqaE&m=s4-K_YIBKy5ajj6hpKezL1TMVodX05GulI7mDKOdfWs&s=abT0ilzi2ANzQ3TgATb5Bz2ns7KcZooONqFYT1QS8Wc&e=


   - setRedirectImage

   public static void setRedirectImage(ImagePlus <https://urldefense.proofpoint.com/v2/url?u=https-3A__imagej.nih.gov_ij_developer_api_ij_ImagePlus.html&d=DwIFaQ&c=ZukO2fIan9e5E9v43wuy1w&r=34-TUupgH50lxe-gJRTc3Sa1yQ018sXW8kPlA42xqaE&m=s4-K_YIBKy5ajj6hpKezL1TMVodX05GulI7mDKOdfWs&s=OFUw0G37CA89nLmJRpWTM0FJZJKOO_1f4Upbm1GgI-Q&e=> imp)

   Set the "Redirect To" image. Pass 'null' as the argument to disable
   redirected sampling.

It’s quite clear and simple to use this function. Just assign the ImagePlus instance of your original image as the input. Give it a try.

On a side note:
You didn’t share your code, and at least to me your description of the problem was not clear. Therefore, help or suggestion can be limited. It’s also not clear to me whether you want to create a plugin, a script, or a macro. On one part you said you trying to make a plugin, and on another part it seems like a macro. You didn’t mention which language you set the macro recorder to, plus what code generated either. Purely guessing from the context, a macro (in imagej macro language) should be sufficient to fulfill what you want to achieve. Then you don’t even need to worry about the java code .

Good luck.

On Fri, 10 May 2019 at 15:35, Rohitesh Gupta <[hidden email]>
wrote:

> Thanks for your email. But, is there a better way to do this ? Any
> more suggestions.
>
> --
> ImageJ mailing list:
> https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_
> list.html&d=DwIFaQ&c=ZukO2fIan9e5E9v43wuy1w&r=34-TUupgH50lxe-gJRTc3Sa1
> yQ018sXW8kPlA42xqaE&m=s4-K_YIBKy5ajj6hpKezL1TMVodX05GulI7mDKOdfWs&s=8f
> -LNu04E1doNDPq37tEQ52ZoNx5mU72k2_aCv-Ah2M&e=
>
--
Ziqiang Huang

Bioimage Analyst of Light Microscopy Facility CRUK Cambridge Institute Li Ka Shing Centre Robinson Way Cambridge, UK
CB2 0RE
01223-769538
email: [hidden email] <[hidden email]>

--
ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwIFaQ&c=ZukO2fIan9e5E9v43wuy1w&r=34-TUupgH50lxe-gJRTc3Sa1yQ018sXW8kPlA42xqaE&m=s4-K_YIBKy5ajj6hpKezL1TMVodX05GulI7mDKOdfWs&s=8f-LNu04E1doNDPq37tEQ52ZoNx5mU72k2_aCv-Ah2M&e=

The information in this e-mail may be privileged and confidential, intended only for the use of the addressee(s) above. Any unauthorized use or disclosure of this information is prohibited. If you have received this e-mail by mistake, please delete it and immediately contact the sender.

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

Re: Java code for redirecting to original image under set measurements

Rohitesh Gupta
In reply to this post by Rohitesh Gupta
I am attaching herein java code for your reference that was generated after recording macro.

If you could help in these aspects that will be really great:
1) Making ROI more flexible such that if there is a rectangular image then rectangular Roi covering the 95% of the image is selected. If there is circular image as in the case of agar plate, then Oval ROI covering 95% of the image can be selected.
2) Making redirect option more generic such that the grayscale image opened on imagej is selected in the redirect option.

I am new to java and plugin making process, so certainly will need help from the community in this regard. Thanks a lot Ziqiang Huang! Kudos!

Thanks a lot,
Rohitesh

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;

public class My_Plugin implements PlugIn {

        public void run(String arg) {
                ImagePlus imp = IJ.getImage();
                imp2 = imp.duplicate();
                //IJ.setTool("oval");
                imp.setRoi(new OvalRoi(203,34,172,377));
                imp.setRoi(new OvalRoi(40,34,335,377));
                imp.setRoi(new OvalRoi(40,34,374,377));
                imp.setRoi(new OvalRoi(40,34,374,389));
                IJ.setAutoThreshold(imp, "Default");
                Prefs.blackBackground = false;
                IJ.run(imp, "Convert to Mask", "");
                IJ.run("Close");
                IJ.run("Set Measurements...", "area mean integrated add redirect=colony.jpg decimal=3");
                IJ.run(imp, "Analyze Particles...", "  show=Outlines display exclude summarize");
        }

}

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