Transfer particles from ImageJ to R as matrix/data frame only?

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

Transfer particles from ImageJ to R as matrix/data frame only?

emudrak
Is there a way to transfer particle measurements to R as only a data frame, without cluttering the workspace with individual variables?
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
Hello,

in principle this is possible but Rserve crashed in the past when the variables were deleted directly after
the transfer (after the creation of the dataframe - i didn't analyze it further).

However the transferred measurements can be deleted easily by selecting all variables (Shift+click first and last variable) in the R-Shell and by deselecting the "Particles" matrix (Strg+click).Then press "Remove" to delete all variables but the "Particles" matrix.

I hope this information helps.
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
In reply to this post by emudrak
Hello,

for the next release i have improved the particle transfer. With Bio7 1.7 the single variables are deleted
if you create a matrix (the label vector is omitted in the numeric matrix as in Bio7 1.6).

In addition i improved the transfer mode. After a measurement the values can be transferred to R
(or the Points panel) multiple times and will not be deleted after a transfer to R. As a consequence a new measurement will now regard the default ImageJ options (Analyze->Analyze Particles->Clear results). Only if "Clear Results" is deselected measures will be added to the afore measured values.

At the moment (Bio7 1.6) particle values are only deleted after a transfer to R. If you measure particles multiple time with ImageJ without a transfer to R the values will be added to the afore measured values.

Note: If you need more geometrical descriptions in Analyze->Set Measurements don't select "Stack positions" because it adds an extra line to the measurements with meaningless data.

Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Jprada
Hello Bio7

I want to know how to transfer measurements from ImageJ to R but using code and not the
Bio7-Toolbar. I am using a Java script so I checked the class Rserve but I don not see any method which allows that.
Thanks

Best
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
Hello,

you can find an Java example (it's full Java and not a script) under:

Bio7_Java_Examples->src->r->ParticleAnalysis

(or: https://github.com/Bio7/Bio7/blob/master/Bio7_Java_Examples/src/r/ParticleAnalysis.java)

Threshold the image before and open the Rserve connection!

This example automatically transfers the Particle measurements to R (the 'Particle' variable serves as a temporary container) from a thresholded image using a easy to use Bio7 API function:

 IJTranserResultsTable.runParticleAnalysis(RConnection c, IJ macro)

The second argument is an ImageJ macro which can be changed or extended for example to open and threshold images automatically.

In addition if you invoke the 'run' method the Particle analysis is transfered in the defined time intervalls with an increasing signature (Particles0,Particles1.....) as a dataframe to R (in this example it simply transfers the data of the currently opened and thresholded image).

This is handy if you transfer simulation results automatically to R or if you would like to open and analyze a folder of images or a stack (you only need the setup method to, e.g., iterate over the stack).

I hope this info helps

Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Jprada
Hello, thank you very much for your help. I opened the example but the compiler shows an error on it. In the line "if (WindowManager.getCurrentImage() != null) {----
                        RConnection c = RServe.getConnection();"
it shows an error that says: Invalid argument to operation ++/--
and later this error:   Multiple markers at this line
                                    - ';' expected
                                    - Syntax error, insert ";" to complete BlockStatements
                                    - RConnection cannot be resolved to a variable
                                    - Syntax error, insert ":: IdentifierOrNew" to complete
                                      ReferenceExpression
                                    - c cannot be resolved to a variable
                                    - c cannot be resolved to a variable

I paste also the code of the example as I have it in case the problem is that I changed something and saved it without noticing.  

Thanks a lot.
Bye



package r;

/*An example to transfer Particle measurements dynamically!*/
import javax.swing.SwingUtilities;

import ij.WindowManager;

import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
import com.eco.bio7.image.r.IJTranserResultsTable;
import com.eco.bio7.rbridge.RServe;

public class ParticleAnalysis extends com.eco.bio7.compile.Model {
        int count = 0;

        public void setup() {
                /*SWT GUI action needs to be on the Swing thread!*/
                SwingUtilities.invokeLater(new Runnable() {
                        // !!
                        public void run() {
                                count = 0;
                                analyze();
                        }
                });

        }

        public void run() {
                count++;
                analyze();

        }

        private void analyze() {
                if (WindowManager.getCurrentImage() != null) {----
                        RConnection c = RServe.getConnection();
                        if (c != null) {
                                /* Special method to reuse the GUI method! */
                                 IJTranserResultsTable.runParticleAnalysis(c, "run(\"Analyze Particles...\", \"size=0-Infinity circularity=0.00-1.00 show=Nothing display clear\")");

                                try {
                                        c.eval("assign(paste0('Particles'," + count + ",sep=''),Particles)");
                                } catch (RserveException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                        }
                }
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
Hello,

I pasted you code and could reproduce your error.

It's in line 35 where you find this (enable the line numbering in the context menu of the ruler or the preferences!):

 if (WindowManager.getCurrentImage() != null) {----

Simply delete the following wrong characters: ----

Save and recompile then the errors are gone (you have to recompile because then the runtime compiler errors will disappear!)



Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Jprada
Hi

Thanks a lot for your help, now it is working. I have one last question, I hope is not too lame, where can I find documentation for the language employed in Bio7? and I don mean Java but the implemented classes and everything. For example the command "RServe.getConnection()" from the Rserve class. I haven't been able to find something like that.

Thanks
Juan
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
Administrator
You can find the sources of Bio7 here:

https://bitbucket.org/maustenfeld/bio7-new

There are several locations (plugins) involved. But at the following locations you find some useful resources:

https://bitbucket.org/maustenfeld/bio7-new/src/b2bcea839df9ed8a321b3182d5e6e2fcc32d53e2/com.eco.bio7/src/com/eco/bio7/rbridge/?at=master

https://bitbucket.org/maustenfeld/bio7-new/src/b2bcea839df9ed8a321b3182d5e6e2fcc32d53e2/com.eco.bio7/src/com/eco/bio7/compile/?at=master

I hope this info helps. If you have some suggestions or improvements let me know
Reply | Threaded
Open this post in threaded view
|

Re: Transfer particles from ImageJ to R as matrix/data frame only?

Bio7
Administrator
In reply to this post by Jprada
The current Java API's can be found in Bio7:

Help->Help Contents->Bio7 Content->Bio7 API

(e.g. com.eco.bio7.rbridge)

In addition the Help browser with nice links to R and ImageJ resources:

Help->Bio7 Internet