Login  Register

Re: get selection perimeter in macro

Posted by Michael Doube on Feb 27, 2008; 9:34am
URL: http://imagej.273.s1.nabble.com/get-selection-perimeter-in-macro-tp3697084p3697086.html

Thanks Justin

I ended up doing it like this - a long way around perhaps?
----------------------
    getSelectionCoordinates(xCoordinates, yCoordinates);
    perimeter = 0;
    for (p = 0; p < lengthOf(xCoordinates)-1; p++){
        if ((xCoordinates[p] == xCoordinates[p+1]) || (yCoordinates[p]
== yCoordinates[p+1])){
            perimeter++;
        } else {
            perimeter = perimeter + sqrt(2);
        }
    }
    if ((xCoordinates[lengthOf(xCoordinates)-1] == xCoordinates[0]) ||
(yCoordinates[lengthOf(xCoordinates)-1] == yCoordinates[0])){
        perimeter++;
    } else {
        perimeter = perimeter + sqrt(2);
    }
----------------------
Mike



Justin McGrath wrote:

> The easiest way that I cant think of is this:
> run("Measure");
> x = getResult("Perim.",nResults-1);
>
> You need to have Perimeter selected in Analyze->Set Measurements.  If you
> want to set it in your macro, you can use:
> run("Set Measurements...", "  perimeter");
>
> Justin
>
> On Mon, Feb 25, 2008 at 11:33 AM, Michael Doube <[hidden email]>
> wrote:
>
>  
>> Hi All
>>
>> I'd like to return the perimeter of a wand selection as a variable in my
>> macro.  So far, all I can get is
>>
>> getSelectionCoordinates(xCoordinates, yCoordinates);
>> perimeter = lengthOf(xCoordinates);
>>
>> which is not correct as edge pixels should be counted as sqrt(2).
>>
>> How can I get a similar result to:
>> *getTracedPerimeter()
>>
>> in a macro?
>>
>> Mike*
>>
>>    

--
Michael Doube  BPhil BVSc PhD MRCVS
Research Associate
Department of Bioengineering
Imperial College London
South Kensington Campus
London  SW7 2AZ
United Kingdom