This post was updated on .
Hy everybody,
I'm actually working on my bachelor thesis and a part of it is writing some macros which will make evaluation more easy and faster. Here is my problem: -I have n Rois on my list, n' (with 0<n'<n) of them are previous ones (from former picture, labeled); -the other n-n' new should be labeled as the former ones when they have same spot; -my idea was to check for each of the new, whether they have a intersection with one of the old and get the old name -there is also the possibility of a roi fusion, such that the new may be labeled as"old1 + old2+..." (mult) The idea is absolutly clear and doing the macro manually doesn't run into an error. The macro itself sais "NullPointerException", because some of the old ROIs are still in the list but do not appear on the image and aren't measurable anymore. I'm very desperate please tell me where my mistake is. Thanks to all of you Here the macro: function interSct (Sel1, Sel2) { intSel=newArray(Sel1,Sel2); roiManager("Select",intSel); roiManager("And"); setSel=selectionType(); run("Select None"); if(setSel!=-1){ return 1; } else { return 0 } } macro automLabel { getNumber("nOld (previous ROIs)",10); nNew=roiManager("count"); for(i=nOld;i<nNew;i++){ mult=0; for(j=0;j<nOld;j++) { reName=0; roiManager("Select", j); newName= getInfo("selection.name"); reName=interSct(i,j); if(reName){ if (!mult){ roiManager("Select",i); roiManager("Rename", newName); mult++; } else { roiManager("Select", i); oldName= getInfo("selection.name"); newName= oldName + " + " + newName; roiManager("Rename", newName); } } } } } |
Hi Influenza,
On Sun, 28 Apr 2013, Influenza wrote: > The idea is absolutly clear and doing the macro manually doesn't run > into an error. The macro itself sais "NullPointerException", because > some of the old ROIs are still in the list but do not appear on the > image and aren't measurable anymore. What is the complete Exception message (i.e. including the stacktrace)? Could you maybe reduce the test case to a minimal one a la -- snip -- if (roiManager("Count") > 0) { roiManager("Delete"); } newImage("Scratchpad", "8-bit", 256, 256, 1); makeRectangle(10, 10, 10, 10); roiManager("Add"); makeRectangle(15, 15, 10, 10); roiManager("Add"); makeRectangle(15, 5, 10, 15); roiManager("Add"); selection = newArray(0, 2); roiManager("Select", selection); roiManager("AND"); -- snap -- ? Your code appears to assume a certain naming of the ROIs in the ROI Manager, and it is real hard to reproduce the problem you described. A minimal macro similar (but not identical!) to my example above would make it so much easier to find the culprit. Ciao, Johannes -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Thank you Johannes!
I must admit that I don't quite understand what you mean with "some of the old ROIs are still in the list but do not appear on the image". So if I got this right the problem should disappear when I add all ROIs to Overlay first? More Details for the project: I'm working with bacteria. And plotting them in rectangles would lead into wrong labeling because of the bacterias shape. That's why the macro is kind of complicated. Here is the Error Message: ImageJ 1.47m; Java 1.7.0_07 [32-bit]; Windows Vista 6.0; 45MB of 640MB (7%) java.lang.NullPointerException at ij.plugin.frame.RoiManager.and(RoiManager.java:1290) at ij.plugin.frame.RoiManager.runCommand(RoiManager.java:1696) at ij.macro.Functions.roiManager(Functions.java:2459) at ij.macro.Functions.getFunctionValue(Functions.java:221) at ij.macro.Interpreter.getFactor(Interpreter.java:1329) at ij.macro.Interpreter.getTerm(Interpreter.java:1300) at ij.macro.Interpreter.getStringExpression(Interpreter.java:1436) at ij.macro.Interpreter.getStringTerm(Interpreter.java:1259) at ij.macro.Interpreter.getString(Interpreter.java:1216) at ij.macro.Interpreter.doStatement(Interpreter.java:264) at ij.macro.Interpreter.doBlock(Interpreter.java:553) at ij.macro.Interpreter.runUserFunction(Interpreter.java:294) at ij.macro.Interpreter.doUserFunctionAssignment(Interpreter.java:832) at ij.macro.Interpreter.doAssignment(Interpreter.java:672) at ij.macro.Interpreter.doStatement(Interpreter.java:228) at ij.macro.Interpreter.doBlock(Interpreter.java:553) at ij.macro.Interpreter.doStatement(Interpreter.java:255) at ij.macro.Interpreter.doIf(Interpreter.java:910) at ij.macro.Interpreter.doStatement(Interpreter.java:231) at ij.macro.Interpreter.doBlock(Interpreter.java:553) at ij.macro.Interpreter.doStatement(Interpreter.java:255) at ij.macro.Interpreter.doFor(Interpreter.java:499) at ij.macro.Interpreter.doStatement(Interpreter.java:237) at ij.macro.Interpreter.doBlock(Interpreter.java:553) at ij.macro.Interpreter.doStatement(Interpreter.java:255) at ij.macro.Interpreter.doFor(Interpreter.java:499) at ij.macro.Interpreter.doStatement(Interpreter.java:237) at ij.macro.Interpreter.doBlock(Interpreter.java:553) at ij.macro.Interpreter.runUserFunction(Interpreter.java:294) at ij.macro.Interpreter.doStatement(Interpreter.java:222) at ij.macro.Interpreter.doStatements(Interpreter.java:207) at ij.macro.Interpreter.run(Interpreter.java:104) at ij.macro.Interpreter.run(Interpreter.java:74) at ij.macro.MacroRunner.run(MacroRunner.java:130) at java.lang.Thread.run(Thread.java:722) |
In reply to this post by Influenza
This case is closed, thanks to R. Wayne.
For interested: The error was caused by the rename part. I did not suspend that two ROIs were named equal, such that one adress gets lost. Hence the next time the ("AND") function runs the NullPointerException occured. |
In reply to this post by Influenza
On Apr 28, 2013, at 5:09 PM, Influenza wrote:
> Hy everybody, > > I'm actually working on my bachelor thesis and a part of it is writing some > macros which will make evaluation more easy and faster. > > Here is my problem: > > -I have n Rois on my list, n' (with 0<n'<n) of them are previous ones (from > former picture, labeled); > -the other n-n' new should be labeled as the former ones when they have same > spot; > -my idea was to check for each of the new, whether they have a intersection > with one of the old and get the old name > -there is also the possibility of a roi fusion, such that the new may be > labeled as"old1 + old2+..." (mult) > > The idea is absolutly clear and doing the macro manually doesn't run into an > error. The macro itself sais "NullPointerException", because some of the old > ROIs are still in the list but do not appear on the image and aren't > measurable anymore. > > I'm very desperate please tell me where my mistake is. > Thanks to all of you > Here the macro: The macro is using roiManager("Rename",newName) when, in some cases, 'newName' duplicates an existing ROI name. This can cause problems, including exceptions, since the ROI Manager requires unique names. In ImageJ 1.47p, roiManager("Rename",newName) adds "-1" to 'newName' if it duplicates an existing name. This is consistent with the way the ROI Manager's "Rename" button has always worked. -wayne > function interSct (Sel1, Sel2) { > > intSel=newArray(Sel1,Sel2); > roiManager("Select",intSel); > roiManager("And"); > setSel=selectionType(); > run("Select None"); > if(setSel!=-1){ > return 1; > } else { > return 0 > } > } > > macro automLabel { > getNumber("nOld (previous ROIs)",10); > nNew=roiManager("count"); > for(i=nOld;i<nNew;i++){ > > mult=0; > for(j=0;j<nOld;j++) { > reName=0; > roiManager("Select", j); > newName= getInfo("selection.name"); > fix=startsWith(newName,"Fix"); > if(!fix) { > reName=interSct(i,j); > if(reName){ > if (!mult){ > roiManager("Select",i); > roiManager("Rename", newName); > mult++; > } else { > roiManager("Select", i); > oldName= getInfo("selection.name"); > newName= oldName + " + " + newName; > roiManager("Rename", newName); > } > } > } > } > } > } > > > > > > > -- > View this message in context: http://imagej.1557.x6.nabble.com/NullPointerException-when-using-roiManager-AND-in-macro-tp5002838.html > Sent from the ImageJ mailing list archive at Nabble.com. > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Influenza
Hi Influenza,
On Mon, 29 Apr 2013, Influenza wrote: > I must admit that I don't quite understand what you mean with "some of the > old ROIs are still in the list but do not appear on the image". I quoted your mail, i.e. those are your words, not mine: http://thread.gmane.org/gmane.comp.java.imagej/28420 > So if I got this right the problem should disappear when I add all ROIs > to Overlay first? I am not saying that. I am saying that I have trouble understanding how to trigger the problem, i.e. finding out what the underlying, technical problem actually is. > More Details for the project: > > I'm working with bacteria. And plotting them in rectangles would lead > into wrong labeling because of the bacterias shape. That's why the macro > is kind of complicated. As far as the exception goes, it does not really matter whether the image is of bacteria or a white image. What matters is to have an easy way to get exactly the same exception as you got. That is why I tried to give you a hint how to rewrite your macro so that it is easy to reproduce the error on my (or for that matter, Wayne's) side. Ciao, Johannes -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |