How to know if a file is supported by imageJ without preloading?

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

How to know if a file is supported by imageJ without preloading?

Juanjo Vega
Hello everybody,

I'm developing a new plugin and I need a way to know when a file is
supported by imageJ.

I'm implementing a browser with a preview and the idea is to know when a
file is supported or not to show one or another icon. The main idea is
to use something like: "isASupportedFileType(): boolean", so new file
types will return "true" when a new plugin will be added.

Right now I'm filtering items by their extension and that's not cool at
all =P

Sincerelly,

Juanjo.

--
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.csic.es

+34 91 585 4510


"Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Glen MacDonald-2
Hi Juanjo,
I was recently in a similar situation writing a macro to open multiplei image file formats and did not want to have to rely on extensions.  However, as explained by Curtis Rueden, there are only a few formats that declare their identities their headers.  As far as file type support by ImageJ, using the Bio-formats library directly or through the LOCI plugin greatly expands the number of formats that can be opened.  If you have a few specific types of interest, you might be able to parse distinguishing characteristics in the header or metadata, but that might also be cumbersome.  

Good luck,
Glen
Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923  USA
(206) 616-4156
[hidden email]








On Feb 8, 2010, at 6:37 AM, Juanjo Vega wrote:

> Hello everybody,
>
> I'm developing a new plugin and I need a way to know when a file is supported by imageJ.
>
> I'm implementing a browser with a preview and the idea is to know when a file is supported or not to show one or another icon. The main idea is to use something like: "isASupportedFileType(): boolean", so new file types will return "true" when a new plugin will be added.
>
> Right now I'm filtering items by their extension and that's not cool at all =P
>
> Sincerelly,
>
> Juanjo.
>
> --
> Juanjo Vega ([hidden email])
>
> Unidad de Biocomputación. Laboratorio B-13.
> Centro Nacional de Biotecnología. CNB-CSIC.
> C\ Darwin, 3. Campus de Cantoblanco.
> Universidad Autónoma de Madrid.
> 28049, Madrid, Spain.
>
> http://www.cnb.csic.es
> http://www.biocomp.cnb.csic.es
>
> +34 91 585 4510
>
>
> "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Juanjo Vega
On Feb 8, 2010, at 9:37 AM, Juanjo Vega wrote:

> Hello everybody,
>
> I'm developing a new plugin and I need a way to know when
> a file is supported by imageJ.
>
> I'm implementing a browser with a preview and the idea is to know
> when a file is supported or not to show one or another icon. The main
> idea is to to use something like: "isASupportedFileType(): boolean",  
> so new file types will return "true" when a new plugin will be added.
>
> Right now I'm filtering items by their extension and that's not
> cool at all =P

You can use the getFileType() method in the Opener class to determine if a file is directly supported by ImageJ. It returns Opener.UNKNOWN if the file is not supported or if it  was not found. I am sure the Bio-Formats plugin has a similar method for determining if a particular file is supported. Here is a JavaScript example that shows how to use getFileType():

   od = new OpenDialog("Open", "");
   path = od.getDirectory()+od.getFileName();
   type = (new Opener()).getFileType(path);
   if (type==Opener.UNKNOWN)
     print(path+" is not in a supported format or it was not found");
   else
      print(path+" is a "+Opener.types[type]+" file");

It requires the 1.43p12 daily build, which makes the Opener.types String array public.

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

ctrueden
Hi Juanjo,

> I am sure the Bio-Formats plugin has a similar method
> for determining if a particular file is supported.

If you use Bio-Formats, right now you can do:

import loci.formats.ImageReader;
...
String filename = "/path/to/myData.zvi";
ImageReader r = new ImageReader();
boolean supported =  r.isThisType(filename);
System.out.println("File is supported? " + (supported ? "yes" : "no"));
// or:
String format = r.getFormat(filename);
System.out.println("File format is: " + format);

HTH,
Curtis

On Mon, Feb 8, 2010 at 3:32 PM, Rasband, Wayne (NIH/NIMH) [E]
<[hidden email]> wrote:

> On Feb 8, 2010, at 9:37 AM, Juanjo Vega wrote:
>
>> Hello everybody,
>>
>> I'm developing a new plugin and I need a way to know when
>> a file is supported by imageJ.
>>
>> I'm implementing a browser with a preview and the idea is to know
>> when a file is supported or not to show one or another icon. The main
>> idea is to to use something like: "isASupportedFileType(): boolean",
>> so new file types will return "true" when a new plugin will be added.
>>
>> Right now I'm filtering items by their extension and that's not
>> cool at all =P
>
> You can use the getFileType() method in the Opener class to determine if a file is directly supported by ImageJ. It returns Opener.UNKNOWN if the file is not supported or if it  was not found. I am sure the Bio-Formats plugin has a similar method for determining if a particular file is supported. Here is a JavaScript example that shows how to use getFileType():
>
>   od = new OpenDialog("Open", "");
>   path = od.getDirectory()+od.getFileName();
>   type = (new Opener()).getFileType(path);
>   if (type==Opener.UNKNOWN)
>     print(path+" is not in a supported format or it was not found");
>   else
>      print(path+" is a "+Opener.types[type]+" file");
>
> It requires the 1.43p12 daily build, which makes the Opener.types String array public.
>
> -wayne
>
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

simon andrews (BI)
In reply to this post by Juanjo Vega
On 08/02/2010 14:37, Juanjo Vega wrote:

> Hello everybody,
>
> I'm developing a new plugin and I need a way to know when a file is
> supported by imageJ.
>
> I'm implementing a browser with a preview and the idea is to know when a
> file is supported or not to show one or another icon. The main idea is
> to use something like: "isASupportedFileType(): boolean", so new file
> types will return "true" when a new plugin will be added.
>
> Right now I'm filtering items by their extension and that's not cool at
> all =P

That may not be cool but actually it's the only practical way to do it.
  I went through this when I was developing our image browser.  As
others have pointed out there are methods in both ImageJ and BioFormats
to determine whether a file can be read, the problem is that they have
to read the files to determine this, and in some cases they can take a
long time to return.  I found that big compressed archive files could
take tens of seconds to return, which is unusably long if you're only
trying to decide what icon to use.

If you wanted to go that way you could set a timer on the call and have
an 'unknown' icon if it look too long to determine perhaps?

Simon.
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

ctrueden
Hi everyone,

As others have pointed out there are methods in both ImageJ and BioFormats
> to determine whether a file can be read, the problem is that they have to
> read the files to determine this, and in some cases they can take a long
> time to return.  I found that big compressed archive files could take tens
> of seconds to return, which is unusably long if you're only trying to decide
> what icon to use.
>

It is worth mentioning that we have since improved the Bio-Formats file type
recognition. You can now choose whether to allow Bio-Formats to examine the
file's contents or not.

If speed is paramount, call with the open flag set to false:
boolean supported =  r.isThisType(filename, false);

This will decide based solely on filename and possibly directory structure.

If accuracy is more important, call with the default (open=true):
boolean supported =  r.isThisType(filename);

This will decide based on filename if possible, but examine the file
contents as needed, which as Simon mentions can take more time (though we
have made an effort to keep the time requirements as minimal as possible).

-Curtis

On Thu, Feb 11, 2010 at 6:32 AM, Simon Andrews <[hidden email]>wrote:

> On 08/02/2010 14:37, Juanjo Vega wrote:
>
>> Hello everybody,
>>
>> I'm developing a new plugin and I need a way to know when a file is
>> supported by imageJ.
>>
>> I'm implementing a browser with a preview and the idea is to know when a
>> file is supported or not to show one or another icon. The main idea is
>> to use something like: "isASupportedFileType(): boolean", so new file
>> types will return "true" when a new plugin will be added.
>>
>> Right now I'm filtering items by their extension and that's not cool at
>> all =P
>>
>
> That may not be cool but actually it's the only practical way to do it.  I
> went through this when I was developing our image browser.  As others have
> pointed out there are methods in both ImageJ and BioFormats to determine
> whether a file can be read, the problem is that they have to read the files
> to determine this, and in some cases they can take a long time to return.  I
> found that big compressed archive files could take tens of seconds to
> return, which is unusably long if you're only trying to decide what icon to
> use.
>
> If you wanted to go that way you could set a timer on the call and have an
> 'unknown' icon if it look too long to determine perhaps?
>
> Simon.
>
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Juanjo Vega
In reply to this post by Glen MacDonald-2
Thank you all,

I'm not using bio-formats, and the way that Wayne proposed doesn't work
for some formats which are opened through plugins. Also Jarek Sacha
proposed another way, something like:

        try {
            final ImageInputStream iis =
ImageIO.createImageInputStream(file);
            final Iterator readers = ImageIO.getImageReaders(iis);

            if (readers.hasNext()) {
                IJ.write(file.getName()+" is supported by imageJ.");
            }
        } catch (Exception ex) {
        }

It works just for images, so I think I could mix both ways, Wayne's and
Jarek's, to get all the supported files.

Sincerelly,

Juanjo.

Glen MacDonald escribió:

> Hi Juanjo,
> I was recently in a similar situation writing a macro to open multiplei image file formats and did not want to have to rely on extensions.  However, as explained by Curtis Rueden, there are only a few formats that declare their identities their headers.  As far as file type support by ImageJ, using the Bio-formats library directly or through the LOCI plugin greatly expands the number of formats that can be opened.  If you have a few specific types of interest, you might be able to parse distinguishing characteristics in the header or metadata, but that might also be cumbersome.  
>
> Good luck,
> Glen
> Glen MacDonald
> Core for Communication Research
> Virginia Merrill Bloedel Hearing Research Center
> Box 357923
> University of Washington
> Seattle, WA 98195-7923  USA
> (206) 616-4156
> [hidden email]
>
>
>
>
>
>
>
>
> On Feb 8, 2010, at 6:37 AM, Juanjo Vega wrote:
>
>  
>> Hello everybody,
>>
>> I'm developing a new plugin and I need a way to know when a file is supported by imageJ.
>>
>> I'm implementing a browser with a preview and the idea is to know when a file is supported or not to show one or another icon. The main idea is to use something like: "isASupportedFileType(): boolean", so new file types will return "true" when a new plugin will be added.
>>
>> Right now I'm filtering items by their extension and that's not cool at all =P
>>
>> Sincerelly,
>>
>> Juanjo.
>>
>> --
>> Juanjo Vega ([hidden email])
>>
>> Unidad de Biocomputación. Laboratorio B-13.
>> Centro Nacional de Biotecnología. CNB-CSIC.
>> C\ Darwin, 3. Campus de Cantoblanco.
>> Universidad Autónoma de Madrid.
>> 28049, Madrid, Spain.
>>
>> http://www.cnb.csic.es
>> http://www.biocomp.cnb.csic.es
>>
>> +34 91 585 4510
>>
>>
>> "Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.
>>    

--
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.csic.es

+34 91 585 4510


"Las mejores almas son capaces de los mayores vicios como de las mayores virtudes, y aquellos que caminan despacio por el camino recto pueden llegar más lejos que los que corren pero se apartan de él." - Discurso del Método, René Descartes.
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

simon andrews (BI)
In reply to this post by ctrueden
On 11/02/2010 17:38, Curtis Rueden wrote:

> Hi everyone,
>
> As others have pointed out there are methods in both ImageJ and BioFormats
>> to determine whether a file can be read, the problem is that they have to
>> read the files to determine this, and in some cases they can take a long
>> time to return.  I found that big compressed archive files could take tens
>> of seconds to return, which is unusably long if you're only trying to decide
>> what icon to use.
>>
>
> It is worth mentioning that we have since improved the Bio-Formats file type
> recognition. You can now choose whether to allow Bio-Formats to examine the
> file's contents or not.
>
> If speed is paramount, call with the open flag set to false:
> boolean supported =  r.isThisType(filename, false);
>
> This will decide based solely on filename and possibly directory structure.
>
> If accuracy is more important, call with the default (open=true):
> boolean supported =  r.isThisType(filename);
>
> This will decide based on filename if possible, but examine the file
> contents as needed, which as Simon mentions can take more time (though we
> have made an effort to keep the time requirements as minimal as possible).

Curtis,

Thanks for pointing that out.  I'll move our code over to using that
rather than our somewhat hacked solution.

I should also point out that for the most part the old method worked
fine.  It's just that there were some corner cases where it could take a
really long time to return.  These were not your typical image files
though (multi-gigabyte compressed data).

I'll look into the new features available...

Cheers

Simon.
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Bill Mohler
In reply to this post by ctrueden
Great move!

Are these supported in the macro language?


Thanks,
Bill

Curtis Rueden wrote:

> Hi everyone,
>
> As others have pointed out there are methods in both ImageJ and BioFormats
>  
>> to determine whether a file can be read, the problem is that they have to
>> read the files to determine this, and in some cases they can take a long
>> time to return.  I found that big compressed archive files could take tens
>> of seconds to return, which is unusably long if you're only trying to decide
>> what icon to use.
>>
>>    
>
> It is worth mentioning that we have since improved the Bio-Formats file type
> recognition. You can now choose whether to allow Bio-Formats to examine the
> file's contents or not.
>
> If speed is paramount, call with the open flag set to false:
> boolean supported =  r.isThisType(filename, false);
>
> This will decide based solely on filename and possibly directory structure.
>
> If accuracy is more important, call with the default (open=true):
> boolean supported =  r.isThisType(filename);
>
> This will decide based on filename if possible, but examine the file
> contents as needed, which as Simon mentions can take more time (though we
> have made an effort to keep the time requirements as minimal as possible).
>
> -Curtis
>
> On Thu, Feb 11, 2010 at 6:32 AM, Simon Andrews <[hidden email]>wrote:
>
>  
>> On 08/02/2010 14:37, Juanjo Vega wrote:
>>
>>    
>>> Hello everybody,
>>>
>>> I'm developing a new plugin and I need a way to know when a file is
>>> supported by imageJ.
>>>
>>> I'm implementing a browser with a preview and the idea is to know when a
>>> file is supported or not to show one or another icon. The main idea is
>>> to use something like: "isASupportedFileType(): boolean", so new file
>>> types will return "true" when a new plugin will be added.
>>>
>>> Right now I'm filtering items by their extension and that's not cool at
>>> all =P
>>>
>>>      
>> That may not be cool but actually it's the only practical way to do it.  I
>> went through this when I was developing our image browser.  As others have
>> pointed out there are methods in both ImageJ and BioFormats to determine
>> whether a file can be read, the problem is that they have to read the files
>> to determine this, and in some cases they can take a long time to return.  I
>> found that big compressed archive files could take tens of seconds to
>> return, which is unusably long if you're only trying to decide what icon to
>> use.
>>
>> If you wanted to go that way you could set a timer on the call and have an
>> 'unknown' icon if it look too long to determine perhaps?
>>
>> Simon.
>>
>>    
> .
>
>  

--
William A. Mohler
Associate Professor
Dept. of Genetics and Developmental Biology
University of Connecticut Health Center
MC-3301
263 Farmington Ave.
Farmington, CT   06030-3301

[hidden email]
*Mobile: (860) 985-2719*
alt. mobile: (860) 331-8514
skype: wmohler

Office: (860) 679-1833, room E2029
Lab: (860) 679-1834, room E2032
Fax: (314) 689-1833

G&DB dept. ofc.: (860) 679-8350
G&DB dept. fax : (860) 679-8345
http://genetics.uchc.edu/Faculty/Mohler/Mohler.html
P Think before you print
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

ctrueden
Hi Bill,

Are these supported in the macro language?
>

The latest trunk build of the LOCI Tools (r5910) adds an "isThisTypeFast"
macro function for calling isThisType with open set to false. Here is a
macro demonstrating usage:

run("Bio-Formats Macro Extensions");
name = "/Users/curtis/data/101"; // an extensionless QuickTime movie
Ext.isThisType(name, thisType);
Ext.isThisTypeFast(name, thisTypeFast);
print("name = " + name);
print("thisType = " + thisType); // will print "thisType = true"
print("thisTypeFast = " + thisTypeFast); // will print "thisTypeFast =
false"

-Curtis

On Fri, Feb 12, 2010 at 11:54 AM, Bill Mohler <[hidden email]>wrote:

> Great move!
>
> Are these supported in the macro language?
>
>
> Thanks,
> Bill
>
> Curtis Rueden wrote:
>
>> Hi everyone,
>>
>> As others have pointed out there are methods in both ImageJ and BioFormats
>>
>>
>>> to determine whether a file can be read, the problem is that they have to
>>> read the files to determine this, and in some cases they can take a long
>>> time to return.  I found that big compressed archive files could take
>>> tens
>>> of seconds to return, which is unusably long if you're only trying to
>>> decide
>>> what icon to use.
>>>
>>>
>>>
>>
>> It is worth mentioning that we have since improved the Bio-Formats file
>> type
>> recognition. You can now choose whether to allow Bio-Formats to examine
>> the
>> file's contents or not.
>>
>> If speed is paramount, call with the open flag set to false:
>> boolean supported =  r.isThisType(filename, false);
>>
>> This will decide based solely on filename and possibly directory
>> structure.
>>
>> If accuracy is more important, call with the default (open=true):
>> boolean supported =  r.isThisType(filename);
>>
>> This will decide based on filename if possible, but examine the file
>> contents as needed, which as Simon mentions can take more time (though we
>> have made an effort to keep the time requirements as minimal as possible).
>>
>> -Curtis
>>
>> On Thu, Feb 11, 2010 at 6:32 AM, Simon Andrews <[hidden email]
>> >wrote:
>>
>>
>>
>>> On 08/02/2010 14:37, Juanjo Vega wrote:
>>>
>>>
>>>
>>>> Hello everybody,
>>>>
>>>> I'm developing a new plugin and I need a way to know when a file is
>>>> supported by imageJ.
>>>>
>>>> I'm implementing a browser with a preview and the idea is to know when a
>>>> file is supported or not to show one or another icon. The main idea is
>>>> to use something like: "isASupportedFileType(): boolean", so new file
>>>> types will return "true" when a new plugin will be added.
>>>>
>>>> Right now I'm filtering items by their extension and that's not cool at
>>>> all =P
>>>>
>>>>
>>>>
>>> That may not be cool but actually it's the only practical way to do it.
>>>  I
>>> went through this when I was developing our image browser.  As others
>>> have
>>> pointed out there are methods in both ImageJ and BioFormats to determine
>>> whether a file can be read, the problem is that they have to read the
>>> files
>>> to determine this, and in some cases they can take a long time to return.
>>>  I
>>> found that big compressed archive files could take tens of seconds to
>>> return, which is unusably long if you're only trying to decide what icon
>>> to
>>> use.
>>>
>>> If you wanted to go that way you could set a timer on the call and have
>>> an
>>> 'unknown' icon if it look too long to determine perhaps?
>>>
>>> Simon.
>>>
>>>
>>>
>> .
>>
>>
>>
>
> --
> William A. Mohler
> Associate Professor
> Dept. of Genetics and Developmental Biology
> University of Connecticut Health Center
> MC-3301
> 263 Farmington Ave.
> Farmington, CT   06030-3301
>
> [hidden email]
> *Mobile: (860) 985-2719*
> alt. mobile: (860) 331-8514
> skype: wmohler
>
> Office: (860) 679-1833, room E2029
> Lab: (860) 679-1834, room E2032
> Fax: (314) 689-1833
>
> G&DB dept. ofc.: (860) 679-8350
> G&DB dept. fax : (860) 679-8345
> http://genetics.uchc.edu/Faculty/Mohler/Mohler.html
> P Think before you print
>
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Bill Mohler
Very cool.  Thanks!

Curtis Rueden wrote:

> Hi Bill,
>
> Are these supported in the macro language?
>  
>
> The latest trunk build of the LOCI Tools (r5910) adds an "isThisTypeFast"
> macro function for calling isThisType with open set to false. Here is a
> macro demonstrating usage:
>
> run("Bio-Formats Macro Extensions");
> name = "/Users/curtis/data/101"; // an extensionless QuickTime movie
> Ext.isThisType(name, thisType);
> Ext.isThisTypeFast(name, thisTypeFast);
> print("name = " + name);
> print("thisType = " + thisType); // will print "thisType = true"
> print("thisTypeFast = " + thisTypeFast); // will print "thisTypeFast =
> false"
>
> -Curtis
>
> On Fri, Feb 12, 2010 at 11:54 AM, Bill Mohler <[hidden email]>wrote:
>
>  
>> Great move!
>>
>> Are these supported in the macro language?
>>
>>
>> Thanks,
>> Bill
>>
>> Curtis Rueden wrote:
>>
>>    
>>> Hi everyone,
>>>
>>> As others have pointed out there are methods in both ImageJ and BioFormats
>>>
>>>
>>>      
>>>> to determine whether a file can be read, the problem is that they have to
>>>> read the files to determine this, and in some cases they can take a long
>>>> time to return.  I found that big compressed archive files could take
>>>> tens
>>>> of seconds to return, which is unusably long if you're only trying to
>>>> decide
>>>> what icon to use.
>>>>
>>>>
>>>>
>>>>        
>>> It is worth mentioning that we have since improved the Bio-Formats file
>>> type
>>> recognition. You can now choose whether to allow Bio-Formats to examine
>>> the
>>> file's contents or not.
>>>
>>> If speed is paramount, call with the open flag set to false:
>>> boolean supported =  r.isThisType(filename, false);
>>>
>>> This will decide based solely on filename and possibly directory
>>> structure.
>>>
>>> If accuracy is more important, call with the default (open=true):
>>> boolean supported =  r.isThisType(filename);
>>>
>>> This will decide based on filename if possible, but examine the file
>>> contents as needed, which as Simon mentions can take more time (though we
>>> have made an effort to keep the time requirements as minimal as possible).
>>>
>>> -Curtis
>>>
>>> On Thu, Feb 11, 2010 at 6:32 AM, Simon Andrews <[hidden email]
>>>      
>>>> wrote:
>>>>        
>>>
>>>      
>>>> On 08/02/2010 14:37, Juanjo Vega wrote:
>>>>
>>>>
>>>>
>>>>        
>>>>> Hello everybody,
>>>>>
>>>>> I'm developing a new plugin and I need a way to know when a file is
>>>>> supported by imageJ.
>>>>>
>>>>> I'm implementing a browser with a preview and the idea is to know when a
>>>>> file is supported or not to show one or another icon. The main idea is
>>>>> to use something like: "isASupportedFileType(): boolean", so new file
>>>>> types will return "true" when a new plugin will be added.
>>>>>
>>>>> Right now I'm filtering items by their extension and that's not cool at
>>>>> all =P
>>>>>
>>>>>
>>>>>
>>>>>          
>>>> That may not be cool but actually it's the only practical way to do it.
>>>>  I
>>>> went through this when I was developing our image browser.  As others
>>>> have
>>>> pointed out there are methods in both ImageJ and BioFormats to determine
>>>> whether a file can be read, the problem is that they have to read the
>>>> files
>>>> to determine this, and in some cases they can take a long time to return.
>>>>  I
>>>> found that big compressed archive files could take tens of seconds to
>>>> return, which is unusably long if you're only trying to decide what icon
>>>> to
>>>> use.
>>>>
>>>> If you wanted to go that way you could set a timer on the call and have
>>>> an
>>>> 'unknown' icon if it look too long to determine perhaps?
>>>>
>>>> Simon.
>>>>
>>>>
>>>>
>>>>        
>>> .
>>>
>>>
>>>
>>>      
>> --
>> William A. Mohler
>> Associate Professor
>> Dept. of Genetics and Developmental Biology
>> University of Connecticut Health Center
>> MC-3301
>> 263 Farmington Ave.
>> Farmington, CT   06030-3301
>>
>> [hidden email]
>> *Mobile: (860) 985-2719*
>> alt. mobile: (860) 331-8514
>> skype: wmohler
>>
>> Office: (860) 679-1833, room E2029
>> Lab: (860) 679-1834, room E2032
>> Fax: (314) 689-1833
>>
>> G&DB dept. ofc.: (860) 679-8350
>> G&DB dept. fax : (860) 679-8345
>> http://genetics.uchc.edu/Faculty/Mohler/Mohler.html
>> P Think before you print
>>
>>    
> .
>
>  

--
William A. Mohler
Associate Professor
Dept. of Genetics and Developmental Biology
University of Connecticut Health Center
MC-3301
263 Farmington Ave.
Farmington, CT   06030-3301

[hidden email]
*Mobile: (860) 985-2719*
alt. mobile: (860) 331-8514
skype: wmohler

Office: (860) 679-1833, room E2029
Lab: (860) 679-1834, room E2032
Fax: (314) 689-1833

G&DB dept. ofc.: (860) 679-8350
G&DB dept. fax : (860) 679-8345
http://genetics.uchc.edu/Faculty/Mohler/Mohler.html
P Think before you print
Reply | Threaded
Open this post in threaded view
|

Re: How to know if a file is supported by imageJ without preloading?

Glen MacDonald-2
In reply to this post by ctrueden
Thanks for this capability.  
Glen

Glen MacDonald
Core for Communication Research
Virginia Merrill Bloedel Hearing Research Center
Box 357923
University of Washington
Seattle, WA 98195-7923  USA
(206) 616-4156
[hidden email]








On Feb 12, 2010, at 1:30 PM, Curtis Rueden wrote:

> Hi Bill,
>
> Are these supported in the macro language?
>>
>
> The latest trunk build of the LOCI Tools (r5910) adds an "isThisTypeFast"
> macro function for calling isThisType with open set to false. Here is a
> macro demonstrating usage:
>
> run("Bio-Formats Macro Extensions");
> name = "/Users/curtis/data/101"; // an extensionless QuickTime movie
> Ext.isThisType(name, thisType);
> Ext.isThisTypeFast(name, thisTypeFast);
> print("name = " + name);
> print("thisType = " + thisType); // will print "thisType = true"
> print("thisTypeFast = " + thisTypeFast); // will print "thisTypeFast =
> false"
>
> -Curtis
>
> On Fri, Feb 12, 2010 at 11:54 AM, Bill Mohler <[hidden email]>wrote:
>
>> Great move!
>>
>> Are these supported in the macro language?
>>
>>
>> Thanks,
>> Bill
>>
>> Curtis Rueden wrote:
>>
>>> Hi everyone,
>>>
>>> As others have pointed out there are methods in both ImageJ and BioFormats
>>>
>>>
>>>> to determine whether a file can be read, the problem is that they have to
>>>> read the files to determine this, and in some cases they can take a long
>>>> time to return.  I found that big compressed archive files could take
>>>> tens
>>>> of seconds to return, which is unusably long if you're only trying to
>>>> decide
>>>> what icon to use.
>>>>
>>>>
>>>>
>>>
>>> It is worth mentioning that we have since improved the Bio-Formats file
>>> type
>>> recognition. You can now choose whether to allow Bio-Formats to examine
>>> the
>>> file's contents or not.
>>>
>>> If speed is paramount, call with the open flag set to false:
>>> boolean supported =  r.isThisType(filename, false);
>>>
>>> This will decide based solely on filename and possibly directory
>>> structure.
>>>
>>> If accuracy is more important, call with the default (open=true):
>>> boolean supported =  r.isThisType(filename);
>>>
>>> This will decide based on filename if possible, but examine the file
>>> contents as needed, which as Simon mentions can take more time (though we
>>> have made an effort to keep the time requirements as minimal as possible).
>>>
>>> -Curtis
>>>
>>> On Thu, Feb 11, 2010 at 6:32 AM, Simon Andrews <[hidden email]
>>>> wrote:
>>>
>>>
>>>
>>>> On 08/02/2010 14:37, Juanjo Vega wrote:
>>>>
>>>>
>>>>
>>>>> Hello everybody,
>>>>>
>>>>> I'm developing a new plugin and I need a way to know when a file is
>>>>> supported by imageJ.
>>>>>
>>>>> I'm implementing a browser with a preview and the idea is to know when a
>>>>> file is supported or not to show one or another icon. The main idea is
>>>>> to use something like: "isASupportedFileType(): boolean", so new file
>>>>> types will return "true" when a new plugin will be added.
>>>>>
>>>>> Right now I'm filtering items by their extension and that's not cool at
>>>>> all =P
>>>>>
>>>>>
>>>>>
>>>> That may not be cool but actually it's the only practical way to do it.
>>>> I
>>>> went through this when I was developing our image browser.  As others
>>>> have
>>>> pointed out there are methods in both ImageJ and BioFormats to determine
>>>> whether a file can be read, the problem is that they have to read the
>>>> files
>>>> to determine this, and in some cases they can take a long time to return.
>>>> I
>>>> found that big compressed archive files could take tens of seconds to
>>>> return, which is unusably long if you're only trying to decide what icon
>>>> to
>>>> use.
>>>>
>>>> If you wanted to go that way you could set a timer on the call and have
>>>> an
>>>> 'unknown' icon if it look too long to determine perhaps?
>>>>
>>>> Simon.
>>>>
>>>>
>>>>
>>> .
>>>
>>>
>>>
>>
>> --
>> William A. Mohler
>> Associate Professor
>> Dept. of Genetics and Developmental Biology
>> University of Connecticut Health Center
>> MC-3301
>> 263 Farmington Ave.
>> Farmington, CT   06030-3301
>>
>> [hidden email]
>> *Mobile: (860) 985-2719*
>> alt. mobile: (860) 331-8514
>> skype: wmohler
>>
>> Office: (860) 679-1833, room E2029
>> Lab: (860) 679-1834, room E2032
>> Fax: (314) 689-1833
>>
>> G&DB dept. ofc.: (860) 679-8350
>> G&DB dept. fax : (860) 679-8345
>> http://genetics.uchc.edu/Faculty/Mohler/Mohler.html
>> P Think before you print
>>