Mac vs Windows VirtualStack behaviour

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

Mac vs Windows VirtualStack behaviour

otills
 I am using a Python script to load a list of .tif files from a .txt list and
to display these as a Virtual Stack.

for f in filtFiles:
  if vs is None:
  imp = IJ.openImage(f)
                vs = VirtualStack(imp.width, imp.height, None,"/")
        vs.addSlice(f)
imPlus = ImagePlus("Stack from subdirectories", vs)
print imPlus
imPlus.show()

I know that the file list import part of the code is working fine as the
following successfully opens and displays an image:
imp = IJ.openImage(filtFiles[0])
imp.show()

The really strange thing here is that on Macs this same script works
absolutely without issue. However, on PCs I get a blank stack loaded with
the text 'File not found: ....' on each frame. The file path appears fine as
IJ.openImage with precisely the same file path works.

What am I missing?

Thanks!



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Mac vs Windows VirtualStack behaviour

John Minter
Oliver, I think your problem is the line:

vs = VirtualStack(imp.width, imp.height, None,"/")

The VirtualStack class lists the constructor you used as

VirtualStack(int width, int height, java.awt.image.ColorModel cm,
java.lang.String path)

"/" is not a valid path in Windows

Best Regards,
John

On Tue, Jun 25, 2019 at 5:58 PM otills <[hidden email]> wrote:

>
>  I am using a Python script to load a list of .tif files from a .txt list and
> to display these as a Virtual Stack.
>
> for f in filtFiles:
>         if vs is None:
>                 imp = IJ.openImage(f)
>                 vs = VirtualStack(imp.width, imp.height, None,"/")
>         vs.addSlice(f)
> imPlus = ImagePlus("Stack from subdirectories", vs)
> print imPlus
> imPlus.show()
>
> I know that the file list import part of the code is working fine as the
> following successfully opens and displays an image:
> imp = IJ.openImage(filtFiles[0])
> imp.show()
>
> The really strange thing here is that on Macs this same script works
> absolutely without issue. However, on PCs I get a blank stack loaded with
> the text 'File not found: ....' on each frame. The file path appears fine as
> IJ.openImage with precisely the same file path works.
>
> What am I missing?
>
> Thanks!
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: Mac vs Windows VirtualStack behaviour

otills
Thank you for this pointer John.

I have tried replacing '/' in that line with 'D:/parentFolder/' and then
modifying the relative file paths in the file list being used to reference
file accordingly (to account from starting from a different position in the
file system). This did not work. Where am I going wrong?



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Mac vs Windows VirtualStack behaviour

John Minter
I can't get it to work on Windows either.

lines 30-37 in
https://github.com/imagej/imagej1/blob/master/ij/VirtualStack.java
shows us what is supposed to happen. It is not clear to me what the
lsdy path should be.
I tried a directory and a full name for a tiff stack file. No joy.

/** Creates an empty virtual stack. */
public VirtualStack(int width, int height, ColorModel cm, String path) {
super(width, height, cm);
this.path = path;
names = new String[INITIAL_SIZE];
labels = new String[INITIAL_SIZE];
//IJ.log("VirtualStack: "+path);

Perhaps Wayne could help us with a minimal reproducible example.
I tried a full pathname for the stack and that didn't work. Sorry I
cannot be of more help.
I'll probably do a Homer Simpson "Doh!" when Wayne explains it to us...

John

}

On Tue, Jun 25, 2019 at 6:35 PM otills <[hidden email]> wrote:

>
> Thank you for this pointer John.
>
> I have tried replacing '/' in that line with 'D:/parentFolder/' and then
> modifying the relative file paths in the file list being used to reference
> file accordingly (to account from starting from a different position in the
> file system). This did not work. Where am I going wrong?
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: Mac vs Windows VirtualStack behaviour

Philip Ershler-2
Have you tried the backward slashes \  \  \  \ like these.

Phil

> On Jun 25, 2019, at 6:55 PM, John Minter <[hidden email]> wrote:
>
> I can't get it to work on Windows either.
>
> lines 30-37 in
> https://github.com/imagej/imagej1/blob/master/ij/VirtualStack.java
> shows us what is supposed to happen. It is not clear to me what the
> lsdy path should be.
> I tried a directory and a full name for a tiff stack file. No joy.
>
> /** Creates an empty virtual stack. */
> public VirtualStack(int width, int height, ColorModel cm, String path) {
> super(width, height, cm);
> this.path = path;
> names = new String[INITIAL_SIZE];
> labels = new String[INITIAL_SIZE];
> //IJ.log("VirtualStack: "+path);
>
> Perhaps Wayne could help us with a minimal reproducible example.
> I tried a full pathname for the stack and that didn't work. Sorry I
> cannot be of more help.
> I'll probably do a Homer Simpson "Doh!" when Wayne explains it to us...
>
> John
>
> }
>
> On Tue, Jun 25, 2019 at 6:35 PM otills <[hidden email]> wrote:
>>
>> Thank you for this pointer John.
>>
>> I have tried replacing '/' in that line with 'D:/parentFolder/' and then
>> modifying the relative file paths in the file list being used to reference
>> file accordingly (to account from starting from a different position in the
>> file system). This did not work. Where am I going wrong?
>>
>>
>>
>> --
>> Sent from: http://imagej.1557.x6.nabble.com/
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: Mac vs Windows VirtualStack behaviour

John Minter
Yes, Phil.

If Oliver wants to pursue this further, may I suggest we move the
discussion to the ImageJ Forum (https://forum.image.sc/) where we can
post code and upload images for a reproducible example and all the
information will be in one place and will be easily seatchable.

John

On Tue, Jun 25, 2019 at 8:59 PM Philip Ershler <[hidden email]> wrote:

>
> Have you tried the backward slashes \  \  \  \ like these.
>
> Phil
>
> > On Jun 25, 2019, at 6:55 PM, John Minter <[hidden email]> wrote:
> >
> > I can't get it to work on Windows either.
> >
> > lines 30-37 in
> > https://github.com/imagej/imagej1/blob/master/ij/VirtualStack.java
> > shows us what is supposed to happen. It is not clear to me what the
> > lsdy path should be.
> > I tried a directory and a full name for a tiff stack file. No joy.
> >
> > /** Creates an empty virtual stack. */
> > public VirtualStack(int width, int height, ColorModel cm, String path) {
> > super(width, height, cm);
> > this.path = path;
> > names = new String[INITIAL_SIZE];
> > labels = new String[INITIAL_SIZE];
> > //IJ.log("VirtualStack: "+path);
> >
> > Perhaps Wayne could help us with a minimal reproducible example.
> > I tried a full pathname for the stack and that didn't work. Sorry I
> > cannot be of more help.
> > I'll probably do a Homer Simpson "Doh!" when Wayne explains it to us...
> >
> > John
> >
> > }
> >
> > On Tue, Jun 25, 2019 at 6:35 PM otills <[hidden email]> wrote:
> >>
> >> Thank you for this pointer John.
> >>
> >> I have tried replacing '/' in that line with 'D:/parentFolder/' and then
> >> modifying the relative file paths in the file list being used to reference
> >> file accordingly (to account from starting from a different position in the
> >> file system). This did not work. Where am I going wrong?
> >>
> >>
> >>
> >> --
> >> Sent from: http://imagej.1557.x6.nabble.com/
> >>
> >> --
> >> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: Mac vs Windows VirtualStack behaviour

Wayne Rasband-2
In reply to this post by otills
> On Jun 25, 2019, at 5:56 PM, otills <[hidden email]> wrote:
>
> I am using a Python script to load a list of .tif files from a .txt list and
> to display these as a Virtual Stack.

Have you tried using the File>Import>Stack From List command? With one line of code you can load files from a list and display them as a virtual stack.

   IJ.run("Stack From List...", "open=/path/to/List.txt use”);

-wayne


>
> for f in filtFiles:
>   if vs is None:
>   imp = IJ.openImage(f)
> vs = VirtualStack(imp.width, imp.height, None,"/")
> vs.addSlice(f)
> imPlus = ImagePlus("Stack from subdirectories", vs)
> print imPlus
> imPlus.show()
>
> I know that the file list import part of the code is working fine as the
> following successfully opens and displays an image:
> imp = IJ.openImage(filtFiles[0])
> imp.show()
>
> The really strange thing here is that on Macs this same script works
> absolutely without issue. However, on PCs I get a blank stack loaded with
> the text 'File not found: ....' on each frame. The file path appears fine as
> IJ.openImage with precisely the same file path works.
>
> What am I missing?
>
> Thanks!

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

Re: Mac vs Windows VirtualStack behaviour

otills
I have tried backslashes in the VirtualStack function, but all to no avail.

Wayne, thanks for flagging IJ.run("Stack From List...",
"open=/path/to/List.txt use”); .

This does allow me to easily open these images from file list as a
VirtualStack. The only thing missing is that I was filtering images using
regular expression on the basis of treatment, individual etc and I cannot
see a way of doing this with that solution (other than performing this
filtering and saving a version of the fileList for each combination either
upfront or on the fly). Are you able to advise on what the path should be in
the VirtualStack on Windows as it appears from John's tests above that he
cannot get this working either?

Thanks!



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Mac vs Windows VirtualStack behaviour

Wayne Rasband-2
In reply to this post by otills
> On Jun 25, 2019, at 5:56 PM, otills <[hidden email]> wrote:
>
> I am using a Python script to load a list of .tif files from a .txt list and
> to display these as a Virtual Stack.

The following JavaScript example opens a folder of images as a virtual stack. To get the width and height, it opens the last image in the folder. It does this because on macOS the first file may be ".DS_Store". An easier, but less flexible, way to open a folder of images is to use:
    img = FolderOpener.open(dir,"virtual”).

-wayne

  dir = “C:/Users/rasba/stack/";
  f = new File(dir);
  list = f.list();
  n = list.length;
  img = IJ.openImage(dir+list[n-1]);
  stack = new VirtualStack(img.getWidth(),img.getHeight(),null,dir);
  for (i=0; i<n; i++)
     stack.addSlice(list[i]);
  img2 = new ImagePlus(""+dir,stack);
  img2.show();


> for f in filtFiles:
>   if vs is None:
>   imp = IJ.openImage(f)
> vs = VirtualStack(imp.width, imp.height, None,"/")
> vs.addSlice(f)
> imPlus = ImagePlus("Stack from subdirectories", vs)
> print imPlus
> imPlus.show()
>
> I know that the file list import part of the code is working fine as the
> following successfully opens and displays an image:
> imp = IJ.openImage(filtFiles[0])
> imp.show()
>
> The really strange thing here is that on Macs this same script works
> absolutely without issue. However, on PCs I get a blank stack loaded with
> the text 'File not found: ....' on each frame. The file path appears fine as
> IJ.openImage with precisely the same file path works.
>
> What am I missing?
>
> Thanks!

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

Re: Mac vs Windows VirtualStack behaviour

otills
Thanks Wayne.

The second approach of looping over a list seems most appropriate in this
instance. However, if each image in the list is from a different directory
how should we deal with this for the 'dir' argument in the VirtualStack
constructor? On OSX just specifying '/' and then providing the full file
path for each image works, but we have not been able to get anything
comparable working for Windows.



--
Sent from: http://imagej.1557.x6.nabble.com/

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

Re: Mac vs Windows VirtualStack behaviour

Michael Schmid-3
Hi Oliver,

you can have a list of absolute paths in Windows, e.g. like this:
   C:\users\oliver\Documents\images\sample01\image001.png
   C:\users\oliver\Documents\images\sample08\image015.png

I am not at a Windows computer to try, but I guess that the ImageJ
getDirectory macro function will give you the directory like this.
   https://imagej.nih.gov/ij/developer/macro/functions.html#getDirectory

When using a script langage, IJ.getDirectory("string_argument") does the
same.
   https://github.com/imagej/imagej1/blob/master/ij/IJ.java#L1647

Michael
________________________________________________________________
On 27.06.19 10:19, otills wrote:

> Thanks Wayne.
>
> The second approach of looping over a list seems most appropriate in this
> instance. However, if each image in the list is from a different directory
> how should we deal with this for the 'dir' argument in the VirtualStack
> constructor? On OSX just specifying '/' and then providing the full file
> path for each image works, but we have not been able to get anything
> comparable working for Windows.
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

Re: Mac vs Windows VirtualStack behaviour

Wayne Rasband-2
In reply to this post by otills
> On Jun 27, 2019, at 4:19 AM, otills <[hidden email]> wrote:
>
> Thanks Wayne.
>
> The second approach of looping over a list seems most appropriate in this
> instance. However, if each image in the list is from a different directory
> how should we deal with this for the 'dir' argument in the VirtualStack
> constructor?

The following JavaScript example opens images in different directories as a virtual stack. It requires the ImageJ 1.52q3 daily build, which fixes a bug that caused the images to not open if the ‘path’ argument in the VirtualStack constructor was an empty string.

-wayne

  list = [
     "C:/Users/rasba/images/dir1/image.tif",
     "C:/Users/rasba/images/dir2/image.tif",
     "C:/Users/rasba/images/dir3/image.tif"
  ]
  img = IJ.openImage(list[0]);
  stack = new VirtualStack(img.getWidth(),img.getHeight(),null,"");
  for (i=0; i<list.length; i++)
     stack.addSlice(list[i]);
  vstack = new ImagePlus("Virtual Stack",stack);
  vstack.show();

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