Use ProcessAviStack.Java

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

Use ProcessAviStack.Java

Jprada
Hello I am using the ProcessAviStack.java in order to read a video file and process it in R. This part works just fine but my problem is that I would like to be able to process the video file only as a first step and then use the result on some other part of my project but I don't seem to find a way to do such thing. When I click play it goes over the whole code, is there a way to process the video file and then do something different? I hope my post is clear enough.

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

Re: Use ProcessAviStack.Java

Marcel
Dear Juan,

do you mean you want to execute an action if one frame is transferred to R or do you want to invoke an action after all frames have been transferred?

In the following example below all available frames of a stack are transferred when you press the setup button (instead of the start button!). Here I use the setup button to trigger an available setup method which triggers in the following example the transfer!

If a Java class in Bio7 extends the com.eco.bio7.compile.Model class some default methods are availabe and can be overridden, like, e.g.,: setup, run, close.

If you overwrite the setup method (like below) the method can be triggered
by the Bio7 setup button.

If you overwrite the run method a thread invokes continously your implemented run method if started by the Bio7 Play/Pause button.


But you can add simply other Java methods and R calls to this example. You can even built your
your own GUI interface for you method if you like (SWT and JavaFX supported) and create it on the fly.

Do you want to execute another R method after the image transfer then simply add another Rserve call
after the while loop in the example below (you can even put it in another Java class if you like)

However if you describe more in detail what you would like to do I can certainly give you a more
detailed help.

Cheers

Marcel

Example:

/****************************************************/
import com.eco.bio7.image.ImageMethods;
import com.eco.bio7.rbridge.RServe;

import ij.IJ;

/*
 This example demonstrates how to process image stacks or *.avi files
 with ImageJ and R. Please load a stack or *.avi file (which ImageJ can open!).
 After the compilation press the setup button to execute the setup method.
 all frames of the stack are processed and analysed with R.
 */
public class ProcessAviStack extends com.eco.bio7.compile.Model {

        public void setup() {
                int slice = 1;
                double timeOut;
                long time;
                time = System.currentTimeMillis();
                /* Get the size of the stack! */
                int size = IJ.getImage().getImageStackSize();
                /* Loop over the stack! */
                while (slice <= size) {
                        IJ.run("Set Slice...", "slice=" + slice);
                        /* Transfer as integer! ->0=double, 1=integer, 2=byte, 3=RGB */
                        ImageMethods.imageToR("current", false, 1, null);
                        System.out.println("Mean: ");
                        RServe.print("mean(as.integer(current))");
                        // RServe.print("mean(fft(as.integer(current)))");
                        System.out.println();
                        timeOut = (double) (System.currentTimeMillis() - time) / 1000;
                        System.out.println("Time: (seconds) " + timeOut + " Fps: " + 1
                                        / timeOut);
                        System.out.println("Slice number: " + slice);
                        slice++;
                }
             
        }
}

Reply | Threaded
Open this post in threaded view
|

Re: Use ProcessAviStack.Java

Jprada
Thanks, I adjusted the code and it works fine.