selectWindow does not work

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

selectWindow does not work

kefe
Dear everyone,

I want to write a mini macro to -more or less- analyse my pictures
automatically. I recorded what I want to do with the according plugin and
now just needed to generalise the image name. I think that part worked but
somehow now the selectWindow command does not work anymore. (However, if I
run the command with the specific name as I recorded it, it works.)
The debug window says a ")" is missing in the selectWindow line.

Here is my "code":

imageTitle=File.nameWithoutExtension

run("Stack to Images");

selectWindow("c:2/3 - "imageTitle" ");

setAutoThreshold("Default");
//run("Threshold...");
setThreshold(150, 65535);
setThreshold(150, 65535);
setOption("BlackBackground", false);
run("Convert to Mask");
run("Watershed");
run("Set Measurements...", "area mean min integrated redirect=[c:1/3 -
"imageTitle" ] decimal=3");
run("Analyze Particles...", "size=50-Infinity display exclude clear");

Thanks for your help!

Cheers



--
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: selectWindow does not work

Herbie
Good day,

there are several parts of your macro that are not perfectly correct but
first of all you should tell us how the file name really looks like.

What does "c:2/3 - "imageTitle" " mean?

imageTitle=File.nameWithoutExtension (missing semicolon)

This

setAutoThreshold("Default"); // automatic threshold
setThreshold(150, 65535); // fixed threshold

doesn't make sense because either you use the automatic threshold
"Default" or you set it to fixed values. The former is the way to go
because fixed thresholds don't generalize. If you are not happy with the
automatic "Default"-scheme, then you should use one of the other
options. In any case stay away from manually set thresholds.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 27.10.19 um 17:40 schrieb kefe:

> imageTitle=File.nameWithoutExtension
>
> run("Stack to Images");
>
> selectWindow("c:2/3 - "imageTitle" ");
>
> setAutoThreshold("Default");
> //run("Threshold...");
> setThreshold(150, 65535);
> setThreshold(150, 65535);
> setOption("BlackBackground", false);
> run("Convert to Mask");
> run("Watershed");
> run("Set Measurements...", "area mean min integrated redirect=[c:1/3 -
> "imageTitle" ] decimal=3");
> run("Analyze Particles...", "size=50-Infinity display exclude clear");

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

Re: selectWindow does not work

kefe
Thanks for the fast reply!

I added the semicolon though I am not sure if that changed anything ;)

Sorry, I copied the wrong version of the line. It is:

selectWindow("c:2/3 - " + imageTitle );

Somehow it does not give me the error anymore. (I had it like this before as
well)

I thought I have to use it because after converting the stack to single
images the prefix "c:1/3 - ", "c:2/3 - " and "c:3/3 - " are added to the
window name depending on which channel is displayed in the window. Thats why
I think I need to add the prefix in the name.

I now figured out that apparently the problem is that I want to work on the
not active second window/image and imageJ does not scan the open windows and
just checks if the active window is named ""c:2/3 - " + imageTitle". So I
actually need a command so ImageJ would set the threshold on the not active
window "c:2/3 - " + imageTitle.

 





--
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: selectWindow does not work

Herbie
Funny, that mysterious things still happen!

It would really help if you could post a small sample stack for which
you observe the described behavior. I tried with some of the stacks
available from
"File >> Open samples"
and never got images that show this prefix.

If you could send a small sample stack as ZIP-file, then I'm sure I can
help you further.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 27.10.19 um 19:45 schrieb kefe:

> Thanks for the fast reply!
>
> I added the semicolon though I am not sure if that changed anything ;)
>
> Sorry, I copied the wrong version of the line. It is:
>
> selectWindow("c:2/3 - " + imageTitle );
>
> Somehow it does not give me the error anymore. (I had it like this before as
> well)
>
> I thought I have to use it because after converting the stack to single
> images the prefix "c:1/3 - ", "c:2/3 - " and "c:3/3 - " are added to the
> window name depending on which channel is displayed in the window. Thats why
> I think I need to add the prefix in the name.
>
> I now figured out that apparently the problem is that I want to work on the
> not active second window/image and imageJ does not scan the open windows and
> just checks if the active window is named ""c:2/3 - " + imageTitle". So I
> actually need a command so ImageJ would set the threshold on the not active
> window "c:2/3 - " + imageTitle.

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

Re: selectWindow does not work

kefe
Unfortunately I cannot send you a picture but if you look at the example
pictures in fiji with more than one channel, as for example the confocal
series you always see 1/3 or 2/3 depending on the channel in the upper left
corner. In the confocal series you even have c:1/2. However, I guess fiji
renamed the single channel images and that's why you don't see it anymore
when you do run "stack to images".  



--
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: selectWindow does not work

Herbie
OK, I see.

This works for me:

//
nme=split(getTitle(), ".");
run("Stack to Images");
selectImage("c:1/2 - "+nme[0]);
//

Please report back if it works for you too.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 27.10.19 um 21:53 schrieb kefe:
> Unfortunately I cannot send you a picture but if you look at the example
> pictures in fiji with more than one channel, as for example the confocal
> series you always see 1/3 or 2/3 depending on the channel in the upper left
> corner. In the confocal series you even have c:1/2. However, I guess fiji
> renamed the single channel images and that's why you don't see it anymore
> when you do run "stack to images".

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

Re: selectWindow does not work

kefe
unfortunately not
I get the following errors:

Error: "c:2/3 - 191024_xxx" not found in line 8
                        selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;


Since I do not understand what exactly you do with those 3 lines I dont know
what this error means.
(Sorry I am a total newbie to writing anything)



--
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: selectWindow does not work

Herbie
Good day,

please tell me:
   What exactly is the name of your image stack,
without the prefix but with the file suffix, i.e. ".tif" or ".lsm" etc.

Please make sure that all inverted commas are of the simple type, i.e.
not of the curly type. The latter may be caused by the mailer and copy &
paste.

In any case, I judge prefixes of the kind "c:2/3" as an absolute no-no,
because if you save a file with this prefix, you include a file
separator, the slash and perhaps even the colon, which may cause
tremendous trouble in the sequel.

I'm not perfectly sure why some stacks lead to images with this prefix
after run("Stack to Images"); and some do not. Perhaps Bio-Formats plays
a role. We shall see.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 28.10.19 um 08:49 schrieb kefe:

> unfortunately not
> I get the following errors:
>
> Error: "c:2/3 - 191024_xxx" not found in line 8
>        selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
>
>
> Since I do not understand what exactly you do with those 3 lines I dont know
> what this error means.
> (Sorry I am a total newbie to writing anything)
>
>
>
> --
> 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: selectWindow does not work

kefe
Hello,

the name of the image is in general the date-cellline-time.czi for example:
191014_Hela_5min.czi optionally.nd2

well, the files are saved like this by the microscope and I dont think I
have any possibility to change it.

Best,



--
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: selectWindow does not work

Herbie
Thanks for the details Kerstin!

Please run the following test-macro.
(Copy the macro code lines to an empty macro window
"Plugins >> New >> Macro" and run it.)
////
imgTitle="191014_Hela_5min.czi"; // name of the open stack
nme=split(imgTitle, ".");
print("c:1/2 - "+nme[0]);
////

For me the Log-window then shows the string:
   c:1/2 - 191014_Hela_5min
which should be the title of the desired image after calling
   run("Stack to Images");

Please confirm that the Log-window shows the correct name of the image.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 28.10.19 um 10:52 schrieb kefe:
> Hello,
>
> the name of the image is in general the date-cellline-time.czi for example:
> 191014_Hela_5min.czi optionally.nd2
>
> well, the files are saved like this by the microscope and I dont think I
> have any possibility to change it.
>
> Best,

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

Re: selectWindow does not work

Herbie
In reply to this post by kefe
Kerstin,

I guess that you didn't remove these *three* lines

imageTitle=File.nameWithoutExtension;
run("Stack to Images");
selectWindow("c:2/3 - "imageTitle" ");

from your code before running

////
nme=split(getTitle(), ".");
run("Stack to Images");
selectImage("c:1/2 - "+nme[0]);
////

The first line of my code removes the file suffix, i.e. ".czi" etc.
Please learn at least the essentials of the ImageJ-macro language:
<https://imagej.nih.gov/ij/developer/macro/macros.html>
<https://imagej.nih.gov/ij/developer/macro/functions.html>

Meanwhile I've posted a request dealing with the naming differences when
using "Plain ImageJ" or "Bio-Formats Importer" for stacks...

Because you are dealing with ".czi"-files you will most likely need the
"Bio-Formats Importer" that creates the "c:1/2 - "-suffix after calling
"run("Stack to Images");". This prefix has nothing to do with the names
of the stacks you are using and there is no need to re-name your stacks
as they come from the microscope (I've never suggested anything alike).

I hope things are a bit more transparent now.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 28.10.19 um 08:49 schrieb kefe:

> unfortunately not
> I get the following errors:
>
> Error: "c:2/3 - 191024_xxx" not found in line 8
>        selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
>
>
> Since I do not understand what exactly you do with those 3 lines I dont know
> what this error means.
> (Sorry I am a total newbie to writing anything)

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

Re: selectWindow does not work

Schebique
In reply to this post by kefe
Hi Kefe.
Despite I do not understand the weird prefix naming, I would like to put
some intro into naming anyway.

You got this error, because no active image with this name is open. Herbies
code "hide" the suffix (e.g. .tif), which would be the problem. He has
split the title into the array "nme" consisting of element 0 = "filename"
and 1 = ".tif" (suffix). If you want to concatenate this with hard coded
prefix you have to do it like this:

imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix

this is equivalent:
title=getTitle();
run("Split Channels"); //or whatever split function you use
selectWindow("C1-"+title); //or whatever suffix you need - just exchange
"C1-" with "your_preffix". This just should work.

Anyway, more "safe" would be collect resulting images names and use them
e.g. in array. Here is an example code:


//open("/home/schebique/Obrázky/A1/confocal-series.tif");
run("Confocal Series (2.2MB)");
nI_pre=nImages; //actual number of opened image windows

run("Split Channels"); //splitting channels resulting in
C1-confocal-series.tif etc.
nI_post=nImages; //number of images after splitting
newImagesCount=nI_post - nI_pre +1; //+1 because original was closed, but
we have one image more after split
img=newArray(newImagesCount); //new array where we will collect image titles
count=0; //counter for the array index
for (n=nI_pre; n<=nI_post; n++) { //loop through desired images
selectImage(n); //selecting image
img[count]=getTitle(); //getting title into the array
count++; //index counter increment
}

//loop for printing
for (a=0; a<img.length; a++) {
print(img[a]);
}
//direct selecti of new channel images
selectWindow(img[0]); //select C1
selectWindow(img[1]); //select C2
//example how to copy into the parameter:
C1=img[0]; //params could be more intuitive furthur in the code
C2=img[1];
//loop for close new windows only
for (a=0; a<img.length; a++) {
selectImage(img[a]);
close();
}

Just to be complete I usualy use a little different way to separate name
from .tif suffix:
title=getTitle();
name=replace(title, ".tif", "");
print(title+"\n"+name);

Hopefully you can find some inspiration.
Best Ondrej



po 28. 10. 2019 v 8:49 odesílatel kefe <[hidden email]> napsal:

> unfortunately not
> I get the following errors:
>
> Error:          "c:2/3 - 191024_xxx" not found in line 8
>                         selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
>
>
> Since I do not understand what exactly you do with those 3 lines I dont
> know
> what this error means.
> (Sorry I am a total newbie to writing anything)
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Mgr. Ondřej Šebesta
Laboratory of Confocal and Fluorescence Microscopy
Faculty of Science, Charles University in Prague
Vinicna 7
128 44 Prague
Czech Republic

Phone: +420 2 2195 1061
e-mail: [hidden email]

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

Re: selectWindow does not work

CARL Philippe (LBP)
In reply to this post by Herbie
Gruss Gott Herbie and dear Kerstin,
Your code below will be working, there is no issue about this.
Nevertheless, I think it is somehow over killing to use a split function simply in order to reduce the size of a String.
I say this given especially that you need then two lines in order to get your results.
Thus why not simply use of the substring method within the following code?:
imgTitle="191014_Hela_5min.czi"
print("c:1/2 - " + substring(imgTitle, 0, lengthOf(imgTitle) - 4));
My best regards,
Philippe

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

----- Mail original -----
De: "Herbie" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 28 Octobre 2019 11:07:28
Objet: Re: selectWindow does not work

Thanks for the details Kerstin!

Please run the following test-macro.
(Copy the macro code lines to an empty macro window
"Plugins >> New >> Macro" and run it.)
////
imgTitle="191014_Hela_5min.czi"; // name of the open stack
nme=split(imgTitle, ".");
print("c:1/2 - "+nme[0]);
////

For me the Log-window then shows the string:
   c:1/2 - 191014_Hela_5min
which should be the title of the desired image after calling
   run("Stack to Images");

Please confirm that the Log-window shows the correct name of the image.

Regards

Herbie

::::::::::::::::::::::::::::::::::
Am 28.10.19 um 10:52 schrieb kefe:
> Hello,
>
> the name of the image is in general the date-cellline-time.czi for example:
> 191014_Hela_5min.czi optionally.nd2
>
> well, the files are saved like this by the microscope and I dont think I
> have any possibility to change it.
>
> Best,

--
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: selectWindow does not work

Herbie
Merci Philippe,

pour ta suggestion!

I don't like substring for this purpose because there are file suffixes
containing more than 3 chars...

A la prochaine

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::::
Am 28.10.19 um 11:55 schrieb CARL Philippe (LBP):

> Gruss Gott Herbie and dear Kerstin,
> Your code below will be working, there is no issue about this.
> Nevertheless, I think it is somehow over killing to use a split function simply in order to reduce the size of a String.
> I say this given especially that you need then two lines in order to get your results.
> Thus why not simply use of the substring method within the following code?:
> imgTitle="191014_Hela_5min.czi"
> print("c:1/2 - " + substring(imgTitle, 0, lengthOf(imgTitle) - 4));
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> ----- Mail original -----
> De: "Herbie" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Lundi 28 Octobre 2019 11:07:28
> Objet: Re: selectWindow does not work
>
> Thanks for the details Kerstin!
>
> Please run the following test-macro.
> (Copy the macro code lines to an empty macro window
> "Plugins >> New >> Macro" and run it.)
> ////
> imgTitle="191014_Hela_5min.czi"; // name of the open stack
> nme=split(imgTitle, ".");
> print("c:1/2 - "+nme[0]);
> ////
>
> For me the Log-window then shows the string:
>     c:1/2 - 191014_Hela_5min
> which should be the title of the desired image after calling
>     run("Stack to Images");
>
> Please confirm that the Log-window shows the correct name of the image.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::
> Am 28.10.19 um 10:52 schrieb kefe:
>> Hello,
>>
>> the name of the image is in general the date-cellline-time.czi for example:
>> 191014_Hela_5min.czi optionally.nd2
>>
>> well, the files are saved like this by the microscope and I dont think I
>> have any possibility to change it.
>>
>> Best,
>
> --
> 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: selectWindow does not work

olivier-2
In reply to this post by kefe
Hi
Like Philippe said, it could be easier to remove extension either his way or a simple "replace"
replace(string, old, new)
old can be ".czi" or ".nd2" and new is ""
my 2p

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

Re: selectWindow does not work

CARL Philippe (LBP)
In reply to this post by Herbie
Dear Herbie,
In this case just use the substring and indexOf methods:
imgTitle="191014_Hela_5min.czi"
print("c:1/2 - " + substring(imgTitle, 0, indexOf(imgTitle, ".")));
Kindest regards,
Philippe


----- Mail original -----
De: "Herbie" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 28 Octobre 2019 12:04:19
Objet: Re: selectWindow does not work

Merci Philippe,

pour ta suggestion!

I don't like substring for this purpose because there are file suffixes
containing more than 3 chars...

A la prochaine

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::::
Am 28.10.19 um 11:55 schrieb CARL Philippe (LBP):

> Gruss Gott Herbie and dear Kerstin,
> Your code below will be working, there is no issue about this.
> Nevertheless, I think it is somehow over killing to use a split function simply in order to reduce the size of a String.
> I say this given especially that you need then two lines in order to get your results.
> Thus why not simply use of the substring method within the following code?:
> imgTitle="191014_Hela_5min.czi"
> print("c:1/2 - " + substring(imgTitle, 0, lengthOf(imgTitle) - 4));
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> ----- Mail original -----
> De: "Herbie" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Lundi 28 Octobre 2019 11:07:28
> Objet: Re: selectWindow does not work
>
> Thanks for the details Kerstin!
>
> Please run the following test-macro.
> (Copy the macro code lines to an empty macro window
> "Plugins >> New >> Macro" and run it.)
> ////
> imgTitle="191014_Hela_5min.czi"; // name of the open stack
> nme=split(imgTitle, ".");
> print("c:1/2 - "+nme[0]);
> ////
>
> For me the Log-window then shows the string:
>     c:1/2 - 191014_Hela_5min
> which should be the title of the desired image after calling
>     run("Stack to Images");
>
> Please confirm that the Log-window shows the correct name of the image.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::
> Am 28.10.19 um 10:52 schrieb kefe:
>> Hello,
>>
>> the name of the image is in general the date-cellline-time.czi for example:
>> 191014_Hela_5min.czi optionally.nd2
>>
>> well, the files are saved like this by the microscope and I dont think I
>> have any possibility to change it.
>>
>> Best,
>
> --
> 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: selectWindow does not work

CARL Philippe (LBP)
In reply to this post by Schebique
Dear Ondřej,

> He has split the title into the array "nme" consisting of element 0 = "filename"
> and 1 = ".tif" (suffix).

Ehhh sorry Ondřej, but the resulting nme[1] arry element will be "tif" and not ".tif" (given that "." is the sub-String that cut the String).

> If you want to concatenate this with hard coded prefix you have to do it like this:
> imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix

Thus given the correction higher, imgName should rather be written:
imgName = "c:1/2 - " + nme[0] + "." + nme[1];

I'm really sorry to bother with "details", but if we want to teach something to a beginner it is rather better to teach it right on the first place.

Also knowing I'm a bad teacher, I nevertheless always try to remember Richard P. Feynman (Physics Nobel Prize and excellent lecturer) words:
"There's always an easy way to explain everything, it is just very hard to find it".

My best regards,

Philippe


Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

----- Mail original -----
De: "Ondřej Šebesta" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 28 Octobre 2019 11:50:52
Objet: Re: selectWindow does not work

Hi Kefe.
Despite I do not understand the weird prefix naming, I would like to put
some intro into naming anyway.

You got this error, because no active image with this name is open. Herbies
code "hide" the suffix (e.g. .tif), which would be the problem. He has
split the title into the array "nme" consisting of element 0 = "filename"
and 1 = ".tif" (suffix). If you want to concatenate this with hard coded
prefix you have to do it like this:

imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix

this is equivalent:
title=getTitle();
run("Split Channels"); //or whatever split function you use
selectWindow("C1-"+title); //or whatever suffix you need - just exchange
"C1-" with "your_preffix". This just should work.

Anyway, more "safe" would be collect resulting images names and use them
e.g. in array. Here is an example code:


//open("/home/schebique/Obrázky/A1/confocal-series.tif");
run("Confocal Series (2.2MB)");
nI_pre=nImages; //actual number of opened image windows

run("Split Channels"); //splitting channels resulting in
C1-confocal-series.tif etc.
nI_post=nImages; //number of images after splitting
newImagesCount=nI_post - nI_pre +1; //+1 because original was closed, but
we have one image more after split
img=newArray(newImagesCount); //new array where we will collect image titles
count=0; //counter for the array index
for (n=nI_pre; n<=nI_post; n++) { //loop through desired images
selectImage(n); //selecting image
img[count]=getTitle(); //getting title into the array
count++; //index counter increment
}

//loop for printing
for (a=0; a<img.length; a++) {
print(img[a]);
}
//direct selecti of new channel images
selectWindow(img[0]); //select C1
selectWindow(img[1]); //select C2
//example how to copy into the parameter:
C1=img[0]; //params could be more intuitive furthur in the code
C2=img[1];
//loop for close new windows only
for (a=0; a<img.length; a++) {
selectImage(img[a]);
close();
}

Just to be complete I usualy use a little different way to separate name
from .tif suffix:
title=getTitle();
name=replace(title, ".tif", "");
print(title+"\n"+name);

Hopefully you can find some inspiration.
Best Ondrej



po 28. 10. 2019 v 8:49 odesílatel kefe <[hidden email]> napsal:

> unfortunately not
> I get the following errors:
>
> Error:          "c:2/3 - 191024_xxx" not found in line 8
>                         selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
>
>
> Since I do not understand what exactly you do with those 3 lines I dont
> know
> what this error means.
> (Sorry I am a total newbie to writing anything)
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Mgr. Ondřej Šebesta
Laboratory of Confocal and Fluorescence Microscopy
Faculty of Science, Charles University in Prague
Vinicna 7
128 44 Prague
Czech Republic

Phone: +420 2 2195 1061
e-mail: [hidden email]

--
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: selectWindow does not work

CARL Philippe (LBP)
In reply to this post by CARL Philippe (LBP)
Dear Herbie,
In fact to use the indexOf method is as well dangerous in the case there are "." within the file name (which is fully allowed) and thus it is even better to use the lastIndexOf method.
imgTitle="191014_Hela_5min.czi"
print("c:1/2 - " + substring(imgTitle, 0, lastIndexOf(imgTitle, ".")));
FYI in the case there are indeed "." within the picture file name your method using the split won't be working as well...
Have a nice day,
Philippe

PS: As well FYI coming from "Elsass", I learned to speak German way before French...

Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 41 84

----- Mail original -----
De: "CARL Philippe (LBP)" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 28 Octobre 2019 13:34:23
Objet: Re: selectWindow does not work

Dear Herbie,
In this case just use the substring and indexOf methods:
imgTitle="191014_Hela_5min.czi"
print("c:1/2 - " + substring(imgTitle, 0, indexOf(imgTitle, ".")));
Kindest regards,
Philippe


----- Mail original -----
De: "Herbie" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Lundi 28 Octobre 2019 12:04:19
Objet: Re: selectWindow does not work

Merci Philippe,

pour ta suggestion!

I don't like substring for this purpose because there are file suffixes
containing more than 3 chars...

A la prochaine

Herbie

:::::::::::::::::::::::::::::::::::::::::::::::::
Am 28.10.19 um 11:55 schrieb CARL Philippe (LBP):

> Gruss Gott Herbie and dear Kerstin,
> Your code below will be working, there is no issue about this.
> Nevertheless, I think it is somehow over killing to use a split function simply in order to reduce the size of a String.
> I say this given especially that you need then two lines in order to get your results.
> Thus why not simply use of the substring method within the following code?:
> imgTitle="191014_Hela_5min.czi"
> print("c:1/2 - " + substring(imgTitle, 0, lengthOf(imgTitle) - 4));
> My best regards,
> Philippe
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> ----- Mail original -----
> De: "Herbie" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Lundi 28 Octobre 2019 11:07:28
> Objet: Re: selectWindow does not work
>
> Thanks for the details Kerstin!
>
> Please run the following test-macro.
> (Copy the macro code lines to an empty macro window
> "Plugins >> New >> Macro" and run it.)
> ////
> imgTitle="191014_Hela_5min.czi"; // name of the open stack
> nme=split(imgTitle, ".");
> print("c:1/2 - "+nme[0]);
> ////
>
> For me the Log-window then shows the string:
>     c:1/2 - 191014_Hela_5min
> which should be the title of the desired image after calling
>     run("Stack to Images");
>
> Please confirm that the Log-window shows the correct name of the image.
>
> Regards
>
> Herbie
>
> ::::::::::::::::::::::::::::::::::
> Am 28.10.19 um 10:52 schrieb kefe:
>> Hello,
>>
>> the name of the image is in general the date-cellline-time.czi for example:
>> 191014_Hela_5min.czi optionally.nd2
>>
>> well, the files are saved like this by the microscope and I dont think I
>> have any possibility to change it.
>>
>> Best,
>
> --
> 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

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

Re: selectWindow does not work

Herbie
In reply to this post by Schebique
God day Ondřej,

may I please ask you to consider the whole thread.
Yours as others comments are only partially to the point.

Concerning the "weird prefix" I started a new thread which explains the
problem step by step. The "weird prefix" is not the OP's fault but, as I
assume, an annoying inconsistency of "Bio-Formats Importer".

Regards

Herbie

:::::::::::::::::::::::::::::::::::::::::::
Am 28.10.19 um 11:50 schrieb Ondřej Šebesta:

> Hi Kefe.
> Despite I do not understand the weird prefix naming, I would like to put
> some intro into naming anyway.
>
> You got this error, because no active image with this name is open. Herbies
> code "hide" the suffix (e.g. .tif), which would be the problem. He has
> split the title into the array "nme" consisting of element 0 = "filename"
> and 1 = ".tif" (suffix). If you want to concatenate this with hard coded
> prefix you have to do it like this:
>
> imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix
>
> this is equivalent:
> title=getTitle();
> run("Split Channels"); //or whatever split function you use
> selectWindow("C1-"+title); //or whatever suffix you need - just exchange
> "C1-" with "your_preffix". This just should work.
>
> Anyway, more "safe" would be collect resulting images names and use them
> e.g. in array. Here is an example code:
>
>
> //open("/home/schebique/Obrázky/A1/confocal-series.tif");
> run("Confocal Series (2.2MB)");
> nI_pre=nImages; //actual number of opened image windows
>
> run("Split Channels"); //splitting channels resulting in
> C1-confocal-series.tif etc.
> nI_post=nImages; //number of images after splitting
> newImagesCount=nI_post - nI_pre +1; //+1 because original was closed, but
> we have one image more after split
> img=newArray(newImagesCount); //new array where we will collect image titles
> count=0; //counter for the array index
> for (n=nI_pre; n<=nI_post; n++) { //loop through desired images
> selectImage(n); //selecting image
> img[count]=getTitle(); //getting title into the array
> count++; //index counter increment
> }
>
> //loop for printing
> for (a=0; a<img.length; a++) {
> print(img[a]);
> }
> //direct selecti of new channel images
> selectWindow(img[0]); //select C1
> selectWindow(img[1]); //select C2
> //example how to copy into the parameter:
> C1=img[0]; //params could be more intuitive furthur in the code
> C2=img[1];
> //loop for close new windows only
> for (a=0; a<img.length; a++) {
> selectImage(img[a]);
> close();
> }
>
> Just to be complete I usualy use a little different way to separate name
> from .tif suffix:
> title=getTitle();
> name=replace(title, ".tif", "");
> print(title+"\n"+name);
>
> Hopefully you can find some inspiration.
> Best Ondrej
>
>
>
> po 28. 10. 2019 v 8:49 odesílatel kefe <[hidden email]> napsal:
>
>> unfortunately not
>> I get the following errors:
>>
>> Error:          "c:2/3 - 191024_xxx" not found in line 8
>>                          selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
>>
>>
>> Since I do not understand what exactly you do with those 3 lines I dont
>> know
>> what this error means.
>> (Sorry I am a total newbie to writing anything)
>>
>>
>>
>> --
>> 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: selectWindow does not work

Schebique
In reply to this post by CARL Philippe (LBP)
Dear Carl.

You are right. Sorry, I missed this small detail to consider. Thank you for
clarification. I concentrated more on the second part...:)

best
Ondrej.

Dne po 28. 10. 2019 13:51 uživatel CARL Philippe (LBP) <
[hidden email]> napsal:

> Dear Ondřej,
>
> > He has split the title into the array "nme" consisting of element 0 =
> "filename"
> > and 1 = ".tif" (suffix).
>
> Ehhh sorry Ondřej, but the resulting nme[1] arry element will be "tif" and
> not ".tif" (given that "." is the sub-String that cut the String).
>
> > If you want to concatenate this with hard coded prefix you have to do it
> like this:
> > imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix
>
> Thus given the correction higher, imgName should rather be written:
> imgName = "c:1/2 - " + nme[0] + "." + nme[1];
>
> I'm really sorry to bother with "details", but if we want to teach
> something to a beginner it is rather better to teach it right on the first
> place.
>
> Also knowing I'm a bad teacher, I nevertheless always try to remember
> Richard P. Feynman (Physics Nobel Prize and excellent lecturer) words:
> "There's always an easy way to explain everything, it is just very hard to
> find it".
>
> My best regards,
>
> Philippe
>
>
> Philippe CARL
> Laboratoire de Bioimagerie et Pathologies
> UMR 7021 CNRS - Université de Strasbourg
> Faculté de Pharmacie
> 74 route du Rhin
> 67401 ILLKIRCH
> Tel : +33(0)3 68 85 41 84
>
> ----- Mail original -----
> De: "Ondřej Šebesta" <[hidden email]>
> À: "imagej" <[hidden email]>
> Envoyé: Lundi 28 Octobre 2019 11:50:52
> Objet: Re: selectWindow does not work
>
> Hi Kefe.
> Despite I do not understand the weird prefix naming, I would like to put
> some intro into naming anyway.
>
> You got this error, because no active image with this name is open. Herbies
> code "hide" the suffix (e.g. .tif), which would be the problem. He has
> split the title into the array "nme" consisting of element 0 = "filename"
> and 1 = ".tif" (suffix). If you want to concatenate this with hard coded
> prefix you have to do it like this:
>
> imgName="c:1/2 - "+nme[0]+nme[1] //in case you want to include suffix
>
> this is equivalent:
> title=getTitle();
> run("Split Channels"); //or whatever split function you use
> selectWindow("C1-"+title); //or whatever suffix you need - just exchange
> "C1-" with "your_preffix". This just should work.
>
> Anyway, more "safe" would be collect resulting images names and use them
> e.g. in array. Here is an example code:
>
>
> //open("/home/schebique/Obrázky/A1/confocal-series.tif");
> run("Confocal Series (2.2MB)");
> nI_pre=nImages; //actual number of opened image windows
>
> run("Split Channels"); //splitting channels resulting in
> C1-confocal-series.tif etc.
> nI_post=nImages; //number of images after splitting
> newImagesCount=nI_post - nI_pre +1; //+1 because original was closed, but
> we have one image more after split
> img=newArray(newImagesCount); //new array where we will collect image
> titles
> count=0; //counter for the array index
> for (n=nI_pre; n<=nI_post; n++) { //loop through desired images
> selectImage(n); //selecting image
> img[count]=getTitle(); //getting title into the array
> count++; //index counter increment
> }
>
> //loop for printing
> for (a=0; a<img.length; a++) {
> print(img[a]);
> }
> //direct selecti of new channel images
> selectWindow(img[0]); //select C1
> selectWindow(img[1]); //select C2
> //example how to copy into the parameter:
> C1=img[0]; //params could be more intuitive furthur in the code
> C2=img[1];
> //loop for close new windows only
> for (a=0; a<img.length; a++) {
> selectImage(img[a]);
> close();
> }
>
> Just to be complete I usualy use a little different way to separate name
> from .tif suffix:
> title=getTitle();
> name=replace(title, ".tif", "");
> print(title+"\n"+name);
>
> Hopefully you can find some inspiration.
> Best Ondrej
>
>
>
> po 28. 10. 2019 v 8:49 odesílatel kefe <[hidden email]>
> napsal:
>
> > unfortunately not
> > I get the following errors:
> >
> > Error:          "c:2/3 - 191024_xxx" not found in line 8
> >                         selectImage ( "c:2/3 - " + nme [ 0 <]> ) ;
> >
> >
> > Since I do not understand what exactly you do with those 3 lines I dont
> > know
> > what this error means.
> > (Sorry I am a total newbie to writing anything)
> >
> >
> >
> > --
> > Sent from: http://imagej.1557.x6.nabble.com/
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
>
> --
> Mgr. Ondřej Šebesta
> Laboratory of Confocal and Fluorescence Microscopy
> Faculty of Science, Charles University in Prague
> Vinicna 7
> 128 44 Prague
> Czech Republic
>
> Phone: +420 2 2195 1061
> e-mail: [hidden email]
>
> --
> 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
12