"Error: Row (1) out of range" - please help

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

"Error: Row (1) out of range" - please help

LyleBabcock
I am trying to develop a macro that analyzes muscle fiber size and type.
Getting fiber size from a channel with a membrane stain is easy, but
determining fiber type depends on info from other channels. What I am trying
to do is take the ROIs made on the membrane stain channel, overlay them on
the fiber-type channels, measure the grayscale intensity and if the mean
grayscale intensity is above a certain point then the fiber is labeled
accordingly. When I add the following to my macro (below), everything works
fine and all type I fibers are correctly labeled in the ROI Manager and in
the image:

getList("image.titles");
if (isOpen("MHCI")) {
        selectWindow("MHCI");
        run("From ROI Manager");
        roiManager("multi-measure append");
        nROI = roiManager("count");
        for (i = 0; i < nROI; i++) {
        Mean = getResult("Mean", i);
        if (Mean > 7500) {
        roiManager("select", i);
        roiManager("rename", "I");
        }
}
}
run("Clear Results");


HOWEVER.... I have 3 fiber types that I am trying to label, and when I add
the next section to identify the Type IIa fibers (code below, basically the
same code except its for MHCIIa) I get a bug window saying "Error: Row (1)
out of range in line 212: Mean2 = getResult ( "Mean" , i <)> ;". Whats more
frustrating is that when I use this section below as a separate macro (run
the main program, get correctly labeled MHCI fibers, then run the code below
separately) it works perfectly fine.

if (isOpen("MHCIIa")) {
        selectWindow("MHCIIa");
        run("From ROI Manager");
        roiManager("multi-measure append");
        nROI2 = roiManager("count");
        for (i = 0; i < nROI2; i++) {
        Mean2 = getResult("Mean", i);
        if (Mean2 > 7500) {
        roiManager("select", i);
        roiManager("rename", "IIa");
        }
}
}

So why is it when I run the code with both sections, it won't work, but if I
run them separately they work fine??

Also, if I remove the clear results command and run both sections together,
the program miss-labeles all Type I fibers as Type IIa, which doesn't make
any sense. Can anyone help me make sense of this???



--
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: "Error: Row (1) out of range" - please help

Jeremy Adler
Hi Lyle,

the problem originates with
 roiManager("multi-measure append");
if you look at the Results table, the data all appears in one line
with headings Mean1, Mean2 etc

So reading Mean = getResult("Mean", i);
will return NaN - the location 'Mean' does not exist.
try adding     print(Mean);   to your   for loop
to see what is being returned.

I suspect that the macro works sometimes because
the Results table contained a few results when you started,
so
Mean = getResult("Mean", i);
does not crash, the row  i exists - returning NaN, see above
but when the you clear the Results table and run
 roiManager("multi-measure append");
there is only one line of data and it crashes when the macro tries to read the second line, when  i=1
test this by adding
print(i,Mean);    to the for loop
this will show when the macro worked and when it crashed.

to fix the problem
1) change
getResult("Mean", i);
to read Mean with a number
something like
read="Mean"+i+1
read will be   Mean1, Mean2 etc
note ROI zero is producing a value in column headed Mean1, hence the  i+1
use
Mean=getResult(read, 0);   0 because there is only one line of measurements

or simpler
2) go back to your original version
where each ROI was sequentially used to make a measurement
and the results appear in multiple lines
and read(Mean,i)  will work

unrelated
your getList("image.titles");
is not doing anything - but you don't need it.

List=getList("image.titles");
creates an array called List that holds the available titles
that can be read out - see arrays.

best wishes

Jeremy Adler
BioVis
Uppsala U

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of LyleBabcock
Sent: den 7 augusti 2019 00:31
To: [hidden email]
Subject: "Error: Row (1) out of range" - please help

I am trying to develop a macro that analyzes muscle fiber size and type.
Getting fiber size from a channel with a membrane stain is easy, but determining fiber type depends on info from other channels. What I am trying to do is take the ROIs made on the membrane stain channel, overlay them on the fiber-type channels, measure the grayscale intensity and if the mean grayscale intensity is above a certain point then the fiber is labeled accordingly. When I add the following to my macro (below), everything works fine and all type I fibers are correctly labeled in the ROI Manager and in the image:

getList("image.titles");
if (isOpen("MHCI")) {
selectWindow("MHCI");
run("From ROI Manager");
roiManager("multi-measure append");
nROI = roiManager("count");
for (i = 0; i < nROI; i++) {
Mean = getResult("Mean", i);
if (Mean > 7500) {
roiManager("select", i);
roiManager("rename", "I");
}
}
}
run("Clear Results");


HOWEVER.... I have 3 fiber types that I am trying to label, and when I add the next section to identify the Type IIa fibers (code below, basically the same code except its for MHCIIa) I get a bug window saying "Error: Row (1) out of range in line 212: Mean2 = getResult ( "Mean" , i <)> ;". Whats more frustrating is that when I use this section below as a separate macro (run the main program, get correctly labeled MHCI fibers, then run the code below
separately) it works perfectly fine.

if (isOpen("MHCIIa")) {
selectWindow("MHCIIa");
run("From ROI Manager");
roiManager("multi-measure append");
nROI2 = roiManager("count");
for (i = 0; i < nROI2; i++) {
Mean2 = getResult("Mean", i);
if (Mean2 > 7500) {
roiManager("select", i);
roiManager("rename", "IIa");
}
}
}

So why is it when I run the code with both sections, it won't work, but if I run them separately they work fine??

Also, if I remove the clear results command and run both sections together, the program miss-labeles all Type I fibers as Type IIa, which doesn't make any sense. Can anyone help me make sense of this???



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

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








När du har kontakt med oss på Uppsala universitet med e-post så innebär det att vi behandlar dina personuppgifter. För att läsa mer om hur vi gör det kan du läsa här: http://www.uu.se/om-uu/dataskydd-personuppgifter/

E-mailing Uppsala University means that we will process your personal data. For more information on how this is performed, please read here: http://www.uu.se/en/about-uu/data-protection-policy

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

Re: "Error: Row (1) out of range" - please help

jchanson-2
In reply to this post by LyleBabcock
The multi-measure command measures the currently selected ROIs. If no ROIs
are selected, it measures all of them.  At the end of the first pass, the
last ROI will be selected.  So, at the beginning of pass 2, only one ROI
will be measured.  Try adding a deselect command just before the measurement
- roiManager("deselect");



--
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: "Error: Row (1) out of range" - please help

LyleBabcock
In reply to this post by Jeremy Adler
the multi-measure append does give one measurement per row instead of a row
with all the measurements. Multi-measure by itself gives one row with all
the measurements. Also the "+i+1" doesn't work, the debug window said a
numeral value is expected.

Also, the code for relabeling type I fibers works perfectly. All I did was
copy and paste and change I to IIa, corresponding to the fiber types, and it
doesn't work. If the multi measure append is the problem, how come it works
for type I fibers?



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

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