Login  Register

Re: selectWindow does not work

Posted by CARL Philippe (LBP) on Oct 28, 2019; 12:51pm
URL: http://imagej.273.s1.nabble.com/selectWindow-does-not-work-tp5022577p5022594.html

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