http://imagej.273.s1.nabble.com/Translation-error-in-ROI-generated-macros-tp5013047p5013067.html
> On Jun 7, 2015, at 11:29 AM, Michael Schmid <
[hidden email]> wrote:
>
> Hi Tim,
>
> looking at your code, it seems clear that the roi entered by the user is
> not kept in its original position in the Roi Manager. The command
> roiManager("translate", lateral, vertical);
> moves the roi position stored in the Roi Manager.
>
> If you just want to move the roi, but keep its position in the Roi Manager
> unchanged, you can use
> getSelectionBounds(x, y, width, height);
> setSelectionLocation(x+lateral, y+vertical);
>
> There is one more potential problem: If the original roi is not near the
> center and would be placed outside, it seems that some feature of ImageJ
> puts the roi back to the center.
> On the long term, this creates too many rois in the center of the image,
> which may affect statistical tests.
> To prevent this, I would suggest to use setSelectionLocation on the
> rotated roi, with a position as follows:
> run("Rotate...", "angle=" + (random*365-180));
> getSelectionBounds(x, y, width, height);
> lateral = random*(getWidth-width);
> vertical = random*(getHeight-height);
> setSelectionLocation(lateral, vertical);
> wait(50);
>
> Strange enough it seems that this does not work correctly without the
> 'wait(50);' before adding to the Roi Manager; there must be a race
> condition somewhere.
This bug in the setSelectionLocation(x,y) macro function is fixed in the latest ImageJ daily build (1.49u18).
> On Fri, June 5, 2015 16:07, Feinstein, Timothy N wrote:
>> Hello,
>>
>> We want to know if something localizes to the axoneme of a cilium, but the
>> signal is too noisy to do a simple Pearson's correlation. I wrote a short
>> macro to create a large number of randomly translated 'clones' of a
>> linear ROI made by the user over the body of a cilium; if the labeled
>> protein is significantly in the axoneme then the profile should show
>> greater localization (area under the curve, greater minima etc) than
>> clones randomly positioned on the image.
>>
>> The macro works well, except for one annoying problem. Whenever I run
>> this macro the first ROI, the one that the user draws, has been saved in
>> the ROI manager in a slightly different position. Oddly it seems as if
>> the Translate... function was applied to it with the defaults (10, 10)
>> left in. The code is below. Any help would be greatly appreciated.
>>
>> Thanks,
>>
>>
>> Tim
>>
>> Timothy Feinstein, Ph.D.
>> Research Scientist
>> University of Pittsburgh Department of Developmental Biology
>>
>> ________________________________
>>
>> macro "Cilia Transect Analyzer [k]" {
>>
>> // the user draws a segmented line over the cilium
>>
>> roiManager("Add");
>>
>> // add 20 randomly positioned ROIs:
>>
>> for (i=0; i<20; i++) {
>> lateral = (((random*2)-1)*getWidth)/2;
>> vertical = (((random*2)-1)*getHeight)/2;
>> roiManager("Select", 0);
>> roiManager("translate", lateral, vertical);
>> run("Rotate...", "angle=" + (random*365-180));
>> roiManager("Add");
>> }
>>
>> // delete ROIs touching the edge
>>
>> n = roiManager("count");
>> for (i=n-1; i>=0; i--) {
>> roiManager("select", i);
>> getSelectionBounds(x, y, w, h);
>> if (x<=0||y<=0||x+w>=getWidth||y+h>=getHeight)
>> roiManager("delete");
>> }
>>
>> // select all ROIs and plot the transects
>>
>> roiManager("Deselect");
>> roiManager("Multi Plot");
>>
>> }
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html