Showing progress bar when opening images

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

Showing progress bar when opening images

Ignacio Garcia-Gonzalez
I am developing a plugin I would like to use for operations on very big
images. Therefore, it would be ideal for the user to see the progress
bar when reading the image from file. However, I do not find the way to
do it, or even to update the information in the status bar that the
image is loading.

I first tried with the standard options ImagePlus
imp=IJ.openImage(filename), and later I also tried other roundabouts like:

Opener fo=new Opener();
fo.setSilentMode(false);
ImagePlus imp=fo.openImage(filename)

I would be grateful on any suggestion.

Kind regards,

Ignacio.

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

Re: Showing progress bar when opening images

Wayne Rasband-2
> On Mar 20, 2017, at 1:13 PM, Ignacio García González <[hidden email]> wrote:
>
> I am developing a plugin I would like to use for operations on very big images. Therefore, it would be ideal for the user to see the progress bar when reading the image from file. However, I do not find the way to do it, or even to update the information in the status bar that the image is loading.

ImageJ automatically displays a progress bar as needed when reading and writing TIFF images and stacks.

-wayne

> I first tried with the standard options ImagePlus imp=IJ.openImage(filename), and later I also tried other roundabouts like:
>
> Opener fo=new Opener();
> fo.setSilentMode(false);
> ImagePlus imp=fo.openImage(filename)
>
> I would be grateful on any suggestion.
>
> Kind regards,
>
> Ignacio.

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

Re: Showing progress bar when opening images

Ignacio Garcia-Gonzalez
> ImageJ automatically displays a progress bar as needed when reading and writing TIFF images and stacks.
>
> -wayne
Thank you for your quick reply. However, my concern is that I cannot see
this progress bar when opening the image from another frame, and I do
not find the way to do it. I even looked through the source code to try
to understand how the ProgressBar works.

The following piece of code opens an image, but the bar is not displayed
(running under Windows 10 with 64 bit Java 1.8.0_121). I was opening 200
Mb files, which displayed the progress bar when opening directly from
ImageJ.

import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import java.awt.event.*;
import ij.plugin.*;
import ij.plugin.frame.PlugInFrame;
import java.io.File;
import java.io.*;

public class Test1_ extends PlugInFrame implements ActionListener {

     static private Button btnOpen=new Button("Open");

     public Test1_() {
         super("Open file test");
         btnOpen.addActionListener(this);
         add(btnOpen);
         setResizable(false);
         pack();
         GUI.center(this);
         setVisible(true);
     }

     public void actionPerformed(ActionEvent e) {
         Object source=e.getSource();
         if (source==btnOpen) {
             ImagePlus imp=IJ.openImage(filename);
             imp.show();
         }
     }
}

Greetings,

Ignacio.

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

Re: Showing progress bar when opening images

Wayne Rasband-2
> On Mar 21, 2017, at 5:22 AM, Ignacio García González <[hidden email]> wrote:
>
>> ImageJ automatically displays a progress bar as needed when reading and writing TIFF images and stacks.
>>
>> -wayne
> Thank you for your quick reply. However, my concern is that I cannot see this progress bar when opening the image from another frame, and I do not find the way to do it. I even looked through the source code to try to understand how the ProgressBar works.

You have to open the images in the background using a separate thread, as in the following example.

-wayne


import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import java.awt.event.*;
import ij.plugin.*;
import ij.plugin.frame.PlugInFrame;
import java.io.File;
import java.io.*;

public class Separate_Thread extends PlugInFrame implements ActionListener, Runnable {

   static private Button btnOpen=new Button("Open");

   public Separate_Thread() {
       super("Open file test");
       btnOpen.addActionListener(this);
       add(btnOpen);
       setResizable(false);
       pack();
       GUI.center(this);
       setVisible(true);
   }

   public void actionPerformed(ActionEvent e) {
       Object source = e.getSource();
       if (source==btnOpen) {
          Thread thread = new Thread(this, "Open Image");
          thread.start();
       }
   }

   public void run() {
      ImagePlus imp=IJ.openImage("");
      imp.show();
   }

}


> The following piece of code opens an image, but the bar is not displayed (running under Windows 10 with 64 bit Java 1.8.0_121). I was opening 200 Mb files, which displayed the progress bar when opening directly from ImageJ.
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import java.awt.event.*;
> import ij.plugin.*;
> import ij.plugin.frame.PlugInFrame;
> import java.io.File;
> import java.io.*;
>
> public class Test1_ extends PlugInFrame implements ActionListener {
>
>    static private Button btnOpen=new Button("Open");
>
>    public Test1_() {
>        super("Open file test");
>        btnOpen.addActionListener(this);
>        add(btnOpen);
>        setResizable(false);
>        pack();
>        GUI.center(this);
>        setVisible(true);
>    }
>
>    public void actionPerformed(ActionEvent e) {
>        Object source=e.getSource();
>        if (source==btnOpen) {
>            ImagePlus imp=IJ.openImage(filename);
>            imp.show();
>        }
>    }
> }
>
> Greetings,
>
> Ignacio.

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

Re: Showing progress bar when opening images

Ignacio Garcia-Gonzalez
Thank you very much for your answer. Although I have no experience
dealing with threads, I found it easy to adapt to two plugins without
much effort.

Greetings,

Ignacio.


El 21/03/2017 a las 18:28, Wayne Rasband escribió:

>> On Mar 21, 2017, at 5:22 AM, Ignacio García González <[hidden email]> wrote:
>>
>>> ImageJ automatically displays a progress bar as needed when reading and writing TIFF images and stacks.
>>>
>>> -wayne
>> Thank you for your quick reply. However, my concern is that I cannot see this progress bar when opening the image from another frame, and I do not find the way to do it. I even looked through the source code to try to understand how the ProgressBar works.
> You have to open the images in the background using a separate thread, as in the following example.
>
> -wayne
>
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import java.awt.event.*;
> import ij.plugin.*;
> import ij.plugin.frame.PlugInFrame;
> import java.io.File;
> import java.io.*;
>
> public class Separate_Thread extends PlugInFrame implements ActionListener, Runnable {
>
>     static private Button btnOpen=new Button("Open");
>
>     public Separate_Thread() {
>         super("Open file test");
>         btnOpen.addActionListener(this);
>         add(btnOpen);
>         setResizable(false);
>         pack();
>         GUI.center(this);
>         setVisible(true);
>     }
>
>     public void actionPerformed(ActionEvent e) {
>         Object source = e.getSource();
>         if (source==btnOpen) {
>            Thread thread = new Thread(this, "Open Image");
>            thread.start();
>         }
>     }
>
>     public void run() {
>        ImagePlus imp=IJ.openImage("");
>        imp.show();
>     }
>
> }
>
>
>> The following piece of code opens an image, but the bar is not displayed (running under Windows 10 with 64 bit Java 1.8.0_121). I was opening 200 Mb files, which displayed the progress bar when opening directly from ImageJ.
>>
>> import ij.*;
>> import ij.process.*;
>> import ij.gui.*;
>> import java.awt.*;
>> import java.awt.event.*;
>> import ij.plugin.*;
>> import ij.plugin.frame.PlugInFrame;
>> import java.io.File;
>> import java.io.*;
>>
>> public class Test1_ extends PlugInFrame implements ActionListener {
>>
>>     static private Button btnOpen=new Button("Open");
>>
>>     public Test1_() {
>>         super("Open file test");
>>         btnOpen.addActionListener(this);
>>         add(btnOpen);
>>         setResizable(false);
>>         pack();
>>         GUI.center(this);
>>         setVisible(true);
>>     }
>>
>>     public void actionPerformed(ActionEvent e) {
>>         Object source=e.getSource();
>>         if (source==btnOpen) {
>>             ImagePlus imp=IJ.openImage(filename);
>>             imp.show();
>>         }
>>     }
>> }
>>
>> Greetings,
>>
>> Ignacio.
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> .
>

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