I am getting inconsistent results with scripting the run("Interpolate") command.
I can best illustrate the problem with the following macro script given below. Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. Further explanation: The tool thresholds the images, then calls doWand at the clicked location to create an ROI that outlines the circle. Next it performs a run("Interpolate", "interval=3 smooth"); The resulting region is added to the ROI Manager. This process is repeated but a doWand call is made with a slightly different x,y position. My understanding is that the two ROI's generated should be identical however they often are not. If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. This script was tested with ImageJ 1.47b; Java 1.6.0_33 [32 bit] on an Apple MacBook Pro OS 10.6.8 Is this an ImageJ bug, or am I not understanding something. //----------------------------------------------------------------------------------------------------------------- macro "StartTest [s]" { roiManager("reset"); newImage("Untitled", "8-bit Black", 300, 300, 1); makeOval(50, 50, 200, 200); setForegroundColor(126, 126, 126); run("Fill", "slice"); } macro "Test Tool - C000D05D06D07D08D09D0aD13D14D15D1aD1bD1cD22D23D2cD2dD31D32D35D36D37D38D39D3aD3dD3eD41D44D45D4aD4bD4eD50D51D53D54D5bD5cD5eD5fD60D63D66D67D68D69D6cD6fD70D73D76D79D7cD7fD80D83D86D89D8cD8fD90D93D96D97D98D99D9cD9fDa0Da1Da3Da4DabDacDaeDafDb1Db4Db5DbaDbbDbeDc1Dc2Dc5Dc6Dc7Dc8Dc9DcaDcdDceDd2Dd3DdcDddDe3De4De5DeaDebDecDf5Df6Df7Df8Df9DfaC000C111C222C333C444C555C666C777C888C999CaaaCbbbCcccCdddCeeeCfff"{ roiManager("reset"); getCursorLoc(x, y, z, flags); // Record cursor location // print("x=" + x + " y=" + y ); setThreshold(10, 255); // Set the threshold doWand(x, y); run("Interpolate", "interval=3 smooth"); resetThreshold(); roiManager("Add"); doWand(x+1, y+2); // Click in a different position run("Interpolate", "interval=3 smooth"); resetThreshold(); roiManager("Add"); selectedROIIndexes = newArray(0,1); roiManager("Select", selectedROIIndexes); roiManager("XOR"); } Michael Ellis Digital Scientific UK Ltd -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
The run("Fit Spline"); call also seems to suffer from similar problems when scripting insofar as the control points are effected by the doWand cursor position.
Different starting locations generate similar but not identical splines whereas I would have assumed the generated spline to be solely dependent on the initial ROI only? Any help? On 4 Sep 2012, at 17:07, Michael Ellis wrote: > I am getting inconsistent results with scripting the run("Interpolate") command. > > I can best illustrate the problem with the following macro script given below. > > Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. > > Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. > > > Further explanation: > > The tool thresholds the images, then calls doWand at the clicked location to create an ROI that outlines the circle. > > Next it performs a run("Interpolate", "interval=3 smooth"); > > The resulting region is added to the ROI Manager. > > This process is repeated but a doWand call is made with a slightly different x,y position. > > My understanding is that the two ROI's generated should be identical however they often are not. > > If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. > > The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. > > The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. > > This script was tested with ImageJ 1.47b; Java 1.6.0_33 [32 bit] on an Apple MacBook Pro OS 10.6.8 > > Is this an ImageJ bug, or am I not understanding something. > > //----------------------------------------------------------------------------------------------------------------- > > macro "StartTest [s]" { > roiManager("reset"); > newImage("Untitled", "8-bit Black", 300, 300, 1); > makeOval(50, 50, 200, 200); > setForegroundColor(126, 126, 126); > run("Fill", "slice"); > } > > macro "Test Tool - C000D05D06D07D08D09D0aD13D14D15D1aD1bD1cD22D23D2cD2dD31D32D35D36D37D38D39D3aD3dD3eD41D44D45D4aD4bD4eD50D51D53D54D5bD5cD5eD5fD60D63D66D67D68D69D6cD6fD70D73D76D79D7cD7fD80D83D86D89D8cD8fD90D93D96D97D98D99D9cD9fDa0Da1Da3Da4DabDacDaeDafDb1Db4Db5DbaDbbDbeDc1Dc2Dc5Dc6Dc7Dc8Dc9DcaDcdDceDd2Dd3DdcDddDe3De4De5DeaDebDecDf5Df6Df7Df8Df9DfaC000C111C222C333C444C555C666C777C888C999CaaaCbbbCcccCdddCeeeCfff"{ > roiManager("reset"); > > getCursorLoc(x, y, z, flags); // Record cursor location > // print("x=" + x + " y=" + y ); > > setThreshold(10, 255); // Set the threshold > doWand(x, y); > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > doWand(x+1, y+2); // Click in a different position > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > selectedROIIndexes = newArray(0,1); > roiManager("Select", selectedROIIndexes); > roiManager("XOR"); > } > > > > Michael Ellis > Digital Scientific UK Ltd > -- > 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 Michael P Ellis
I do not know anything about most of what you have written -- so there may be
another problem. but setting and resetting the thresholds themselves can create a difference. Barbara --- On Tue, 9/4/12, Michael Ellis <[hidden email]> wrote: The run("Fit Spline"); call also seems to suffer from similar problems when scripting insofar as the control points are effected by the doWand cursor position. Different starting locations generate similar but not identical splines whereas I would have assumed the generated spline to be solely dependent on the initial ROI only? Any help? On 4 Sep 2012, at 17:07, Michael Ellis wrote: > I am getting inconsistent results with scripting the run("Interpolate") command. > > I can best illustrate the problem with the following macro script given below. > > Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. > > Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. > > > Further explanation: > > The tool > > Next it performs a run("Interpolate", "interval=3 smooth"); > > The resulting region is added to the ROI Manager. > > This process is repeated but a doWand call is made with a slightly different x,y position. > > My understanding is that the two ROI's generated should be identical however they often are not. > > If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. > > The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. > > The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. > > This script was tested with > > Is this an ImageJ bug, or am I not understanding something. > > //----------------------------------------------------------------------------------------------------------------- > > macro "StartTest [s]" { > roiManager("reset"); > newImage("Untitled", "8-bit Black", 300, 300, 1); > makeOval(50, 50, 200, 200); > setForegroundColor(126, 126, 126); > run("Fill", "slice"); > } > > macro "Test Tool - > roiManager("reset"); > > getCursorLoc(x, y, z, flags); // Record cursor location > // print("x=" + x + " y=" + y ); > > setThreshold(10, 255); // Set the threshold > doWand(x, y); > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > doWand(x+1, y+2); > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > selectedROIIndexes = newArray(0,1); > roiManager("Select", selectedROIIndexes); > roiManager("XOR"); > } > > > > Michael Ellis > Digital Scientific UK Ltd > -- > 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 |
Sorry I am wrong, I did not fully read what you had written. I should not
have sent that. --- On Tue, 9/4/12, Barbara Kresp- <[hidden email]> wrote: I do not know anything about most of what you have written -- so there may be another problem. but setting and resetting the thresholds themselves can create a difference. Barbara --- On Tue, 9/4/12, Michael Ellis <[hidden email]> wrote: The run("Fit Spline"); call also seems to suffer from similar problems when scripting insofar as the control points are effected by the doWand cursor position. Different starting locations generate similar but not identical splines whereas I would have assumed the generated spline to be solely dependent on the initial ROI only? Any help? On 4 Sep 2012, at 17:07, Michael Ellis wrote: > I am getting inconsistent results with scripting the run("Interpolate") command. > > I can best illustrate the problem with the following macro script given below. > > Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. > > Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. > > > Further explanation: > > The tool > > Next it performs a run("Interpolate", "interval=3 smooth"); > > The resulting region is added to the ROI Manager. > > This process is repeated but a doWand call is made with a slightly different x,y position. > > My understanding is that the two ROI's generated should be identical however they often are not. > > If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. > > The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. > > The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. > > This script was tested with > > Is this an ImageJ bug, or am I not understanding something. > > //----------------------------------------------------------------------------------------------------------------- > > macro "StartTest [s]" { > roiManager("reset"); > newImage("Untitled", "8-bit Black", 300, 300, 1); > makeOval(50, 50, 200, 200); > setForegroundColor(126, 126, 126); > run("Fill", "slice"); > } > > macro "Test Tool - > roiManager("reset"); > > getCursorLoc(x, y, z, flags); // Record cursor location > // print("x=" + x + " y=" + y ); > > setThreshold(10, 255); // Set the threshold > doWand(x, y); > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > doWand(x+1, y+2); > run("Interpolate", "interval=3 smooth"); > resetThreshold(); > roiManager("Add"); > > selectedROIIndexes = newArray(0,1); > roiManager("Select", selectedROIIndexes); > roiManager("XOR"); > } > > > > Michael Ellis > Digital Scientific UK Ltd > -- > 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 |
In reply to this post by Michael P Ellis
Hi Michael,
as far as I can say, what you see are simply rounding errors. When you make a selection by the wand, you get a polygon selection tracing the outline of the pixels. You will always get the same outline, but the starting point is different, depending on where you click (a closed polygon has no well-defined 'starting' and 'ending' point, but the list of polygon vertices in the computer has). The smoothed interpolated or splined selections are slightly different, depending on the starting point of the original selection: if you take every 3rd point of the smoothed outline, it depends where you start. The resulting difference is only in the subpixel range; it reflects the limited accuracy of creating the interpolated outline. Bitwise operations of selections such as XOR are done pixel by pixel, so the smooth selections have to be converted into masks where each pixel is either inside or outside. Due to rounding, small sub-pixel differences may then become full pixels. When reducing the number of vertices of a closed polygon as in Edit>Selection>Interpolate or Edit>Selection>Fit Spline, I think that there is no way to avoid that the result depends on the starting point of the polygon. Michael ________________________________________________________________ On Sep 4, 2012, at 20:41, Michael Ellis wrote: > The run("Fit Spline"); call also seems to suffer from similar problems when scripting insofar as the control points are effected by the doWand cursor position. > > Different starting locations generate similar but not identical splines whereas I would have assumed the generated spline to be solely dependent on the initial ROI only? > > Any help? > > > > > > > On 4 Sep 2012, at 17:07, Michael Ellis wrote: > >> I am getting inconsistent results with scripting the run("Interpolate") command. >> >> I can best illustrate the problem with the following macro script given below. >> >> Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. >> >> Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. >> >> >> Further explanation: >> >> The tool thresholds the images, then calls doWand at the clicked location to create an ROI that outlines the circle. >> >> Next it performs a run("Interpolate", "interval=3 smooth"); >> >> The resulting region is added to the ROI Manager. >> >> This process is repeated but a doWand call is made with a slightly different x,y position. >> >> My understanding is that the two ROI's generated should be identical however they often are not. >> >> If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. >> >> The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. >> >> The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. >> >> This script was tested with ImageJ 1.47b; Java 1.6.0_33 [32 bit] on an Apple MacBook Pro OS 10.6.8 >> >> Is this an ImageJ bug, or am I not understanding something. >> >> //----------------------------------------------------------------------------------------------------------------- >> >> macro "StartTest [s]" { >> roiManager("reset"); >> newImage("Untitled", "8-bit Black", 300, 300, 1); >> makeOval(50, 50, 200, 200); >> setForegroundColor(126, 126, 126); >> run("Fill", "slice"); >> } >> >> macro "Test Tool - C000D05D06D07D08D09D0aD13D14D15D1aD1bD1cD22D23D2cD2dD31D32D35D36D37D38D39D3aD3dD3eD41D44D45D4aD4bD4eD50D51D53D54D5bD5cD5eD5fD60D63D66D67D68D69D6cD6fD70D73D76D79D7cD7fD80D83D86D89D8cD8fD90D93D96D97D98D99D9cD9fDa0Da1Da3Da4DabDacDaeDafDb1Db4Db5DbaDbbDbeDc1Dc2Dc5Dc6Dc7Dc8Dc9DcaDcdDceDd2Dd3DdcDddDe3De4De5DeaDebDecDf5Df6Df7Df8Df9DfaC000C111C222C333C444C555C666C777C888C999CaaaCbbbCcccCdddCeeeCfff"{ >> roiManager("reset"); >> >> getCursorLoc(x, y, z, flags); // Record cursor location >> // print("x=" + x + " y=" + y ); >> >> setThreshold(10, 255); // Set the threshold >> doWand(x, y); >> run("Interpolate", "interval=3 smooth"); >> resetThreshold(); >> roiManager("Add"); >> >> doWand(x+1, y+2); // Click in a different position >> run("Interpolate", "interval=3 smooth"); >> resetThreshold(); >> roiManager("Add"); >> >> selectedROIIndexes = newArray(0,1); >> roiManager("Select", selectedROIIndexes); >> roiManager("XOR"); >> } >> >> >> >> Michael Ellis >> Digital Scientific UK Ltd >> -- >> 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 |
Michael, hi
Wayne Rasband responded to my question and as you point out the issue is that you can have two ROI's that can contain identical sets of pixels, but their boundary polygon can have different starting points. Operations that work on the generated ROI (such smoothed interpolated or splined selections) can generate different results due to bounding errors. It is somewhat counter-intuitive that "identical" ROIs (where equality here is defined based on the set of pixels that the ROI contain) can give rise to different results (albeit only minor differences). A solution I would favour would be for ImageJ to reorder the polygon points of an ROI to use a consistent starting point (sat the top most left most point) but Wayne suggest that this overhead would be too costly when it makes no difference most of the time. Should you be interested, I got around the problem by writing my own ImageJ macro function that given an ROI (polygon, freehand, traced, polyline or freeline) redefines it so its start point is the left most, upper most point in the ROI. /* * Return index of topmost, leftmost coordinate in coordinate list * x: IN array of x coordinates * y: IN array of y coordinates */ function getTopLeft(x, y) { index = 0; for (i=0; i<x.length; i++) { if (y[i] < y[index]) { index = i; } else if (y[i] == y[index]) { if (x[i] < x[index]) index = i; } } return index; } /* * Redefine the current polygon or freehand ROI so its co-ordinates * start with the topmost, leftmost coordinate. This is useful * where operations such run("Interpolate", "interval=3 smooth") * can generate slightly different results (due to rounding errors) * given ROIs that bound identical sets of pixels but have different * starting points. */ function reorderROICordinates() { type = selectionType(); // Only do if selection is polygon, freehand, traced, polyline or freeline if (type == 2 || type == 3 || type == 4 || type == 6 || type == 7) { getSelectionCoordinates(xs, ys); index = getTopLeft(xs, ys); if (index == 0) return; xs1 = Array.slice(xs,index,xs.length); xs2 = Array.slice(xs, 0, index); xst = Array.concat(xs1, xs2); ys1 = Array.slice(ys,index,ys.length); ys2 = Array.slice(ys, 0, index); yst = Array.concat(ys1, ys2); for (i=0; i < xs.length; i++) { xs[i] = xst[i]; ys[i] = yst[i]; } makeSelection("freehand", xs, ys); } } On 13 Sep 2012, at 13:35, Michael Schmid wrote: > Hi Michael, > > as far as I can say, what you see are simply rounding errors. > > When you make a selection by the wand, you get a polygon selection tracing the outline of the pixels. You will always get the same outline, but the starting point is different, depending on where you click (a closed polygon has no well-defined 'starting' and 'ending' point, but the list of polygon vertices in the computer has). > > The smoothed interpolated or splined selections are slightly different, depending on the starting point of the original selection: if you take every 3rd point of the smoothed outline, it depends where you start. The resulting difference is only in the subpixel range; it reflects the limited accuracy of creating the interpolated outline. > > Bitwise operations of selections such as XOR are done pixel by pixel, so the smooth selections have to be converted into masks where each pixel is either inside or outside. Due to rounding, small sub-pixel differences may then become full pixels. > > When reducing the number of vertices of a closed polygon as in Edit>Selection>Interpolate or Edit>Selection>Fit Spline, I think that there is no way to avoid that the result depends on the starting point of the polygon. > > > Michael > ________________________________________________________________ > On Sep 4, 2012, at 20:41, Michael Ellis wrote: > >> The run("Fit Spline"); call also seems to suffer from similar problems when scripting insofar as the control points are effected by the doWand cursor position. >> >> Different starting locations generate similar but not identical splines whereas I would have assumed the generated spline to be solely dependent on the initial ROI only? >> >> Any help? >> >> >> >> >> >> >> On 4 Sep 2012, at 17:07, Michael Ellis wrote: >> >>> I am getting inconsistent results with scripting the run("Interpolate") command. >>> >>> I can best illustrate the problem with the following macro script given below. >>> >>> Install the script then run the StartTest macro. This will create a small test 300x300 byte image with centred grey circle. >>> >>> Next try using the Test tool (it has a tool icon of concentric circles) and click at several locations within the grey circle. The problem I am experiencing is illustrated if after clicking you ever you see some regions defined on the fringe of the circle! You may need to click several times. >>> >>> >>> Further explanation: >>> >>> The tool thresholds the images, then calls doWand at the clicked location to create an ROI that outlines the circle. >>> >>> Next it performs a run("Interpolate", "interval=3 smooth"); >>> >>> The resulting region is added to the ROI Manager. >>> >>> This process is repeated but a doWand call is made with a slightly different x,y position. >>> >>> My understanding is that the two ROI's generated should be identical however they often are not. >>> >>> If you remove the run("Interpolate", "interval=3 smooth"); calls the problem goes away. >>> >>> The script presented is only to illustrate the problem. But the inconsistent behaviour is causing real problems for the analysis I am attempting. >>> >>> The macro takes the exclusive or (XOR) of the two generated regions, and if there is a residual region define if the two generated regions are not identical. >>> >>> This script was tested with ImageJ 1.47b; Java 1.6.0_33 [32 bit] on an Apple MacBook Pro OS 10.6.8 >>> >>> Is this an ImageJ bug, or am I not understanding something. >>> >>> //----------------------------------------------------------------------------------------------------------------- >>> >>> macro "StartTest [s]" { >>> roiManager("reset"); >>> newImage("Untitled", "8-bit Black", 300, 300, 1); >>> makeOval(50, 50, 200, 200); >>> setForegroundColor(126, 126, 126); >>> run("Fill", "slice"); >>> } >>> >>> macro "Test Tool - C000D05D06D07D08D09D0aD13D14D15D1aD1bD1cD22D23D2cD2dD31D32D35D36D37D38D39D3aD3dD3eD41D44D45D4aD4bD4eD50D51D53D54D5bD5cD5eD5fD60D63D66D67D68D69D6cD6fD70D73D76D79D7cD7fD80D83D86D89D8cD8fD90D93D96D97D98D99D9cD9fDa0Da1Da3Da4DabDacDaeDafDb1Db4Db5DbaDbbDbeDc1Dc2Dc5Dc6Dc7Dc8Dc9DcaDcdDceDd2Dd3DdcDddDe3De4De5DeaDebDecDf5Df6Df7Df8Df9DfaC000C111C222C333C444C555C666C777C888C999CaaaCbbbCcccCdddCeeeCfff"{ >>> roiManager("reset"); >>> >>> getCursorLoc(x, y, z, flags); // Record cursor location >>> // print("x=" + x + " y=" + y ); >>> >>> setThreshold(10, 255); // Set the threshold >>> doWand(x, y); >>> run("Interpolate", "interval=3 smooth"); >>> resetThreshold(); >>> roiManager("Add"); >>> >>> doWand(x+1, y+2); // Click in a different position >>> run("Interpolate", "interval=3 smooth"); >>> resetThreshold(); >>> roiManager("Add"); >>> >>> selectedROIIndexes = newArray(0,1); >>> roiManager("Select", selectedROIIndexes); >>> roiManager("XOR"); >>> } >>> >>> >>> >>> Michael Ellis >>> Digital Scientific UK Ltd >>> -- >>> 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 |
Free forum by Nabble | Edit this page |