Obtaining 3 equal parts

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Obtaining 3 equal parts

Jerry Sedgewick
Hello,

A lab at our university is interested in dividing images of sections
spatially (rather than functionally) into 3 parts: left, middle and right
for measurements from each part. The shapes of the sections change
dramatically from one to the next, from a circular to triangular to
boomerang shapes. The only means I could come up with for equally dividing
parts involved drawing a line through vertical axis from the centroid to
either end, and then dividing the length of the line by three to find the
x, y positions along the line for each part. The horizontal line would then
have to be manually drawn, following the "bend" of the shape.

Any other suggestions would be much appreciated.

Jerry Sedgewick
University of Minnesota
Reply | Threaded
Open this post in threaded view
|

Re: Obtaining 3 equal parts

Greg Joss
The macro appended below illustrates an approach using measurement of
the equivalent ellipse of the binary image to orient the segment.
Apportioning of the area is done by using the intensity of the binary
object projected to the horizontal long axis as a surrogate for a
pixel count.
More complex shapes could be handled by first determining the median
axis using skeletonize.
//_______________
        while(nImages>0)close;print("\\Clear");run("Clear Results");
        testImage();
        setThreshold(255, 255);
        run("Set Measurements...", "area bounding fit redirect=None decimal=1");
        run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display");
        resetThreshold();
        run("Duplicate...", "title="+getTitle+"_Horiz");
        r=nResults-1;
        run("Arbitrarily...", "angle="+getResult("Angle",r)+" fill enlarge");
        setThreshold(255, 255);
        area=getResult("Area",r);
        run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display");
        r=nResults-1;
        x=getResult("BX",r);
        y=getResult("BY",r);
        w=getResult("Width",r);
        h=getResult("Height",r);
        makeRectangle(x, y, w,h);
          profile = getProfile(); // run("Plot Profile");
        area3=area/3;a1=-1;a2=-1;area23=area*2/3;
          for (i=0; i<profile.length; i++){cp+=profile[i]/255*h;
                if(a1<0&&cp>=area3)a1=i;
                if(a2<0&&cp>=area23)a2=i;
              print(i,profile[i],cp);
        }
        ar=(cp-area)/area*100;
        print("cumul intensity : area % diff =",ar);
        x1=x+a1;
        x2=x+a2;
        print(x1,x2);
        makeRectangle(x1, y, x2-x1,h);
        run("Analyze Particles...", "size=0-Infinity circularity=0.00-1.00
show=Nothing display");
        areaMid=getResult("Area",nResults-1);
        print(areaMid/area);       // this should be ~ 1/3
        setColor(128,128,128);
        drawRect(x1, y, x2-x1,h);
// run("Tile");
       
function testImage(){
        newImage("SegmentDivision", "8-bit Black", 420,420, 1);
        setForegroundColor(255, 255, 255);
        makeOval(120, 109, 172, 60);
        run("Fill");
        run("Select None");
        run("Arbitrarily...", "angle=-42");
        makeOval(171, 124, 204, 59);
        run("Fill");
        makeOval(165, 145, 73, 57);
        run("Fill");
        run("Select None");
        run("Arbitrarily...", "angle=-42");
        makeRectangle(100, 49, 204, 260);
        run("Crop");
        run("Make Binary");
}
//__________________


On 11/6/07, Jerry Sedgewick <[hidden email]> wrote:

> Hello,
>
> A lab at our university is interested in dividing images of sections
> spatially (rather than functionally) into 3 parts: left, middle and right
> for measurements from each part. The shapes of the sections change
> dramatically from one to the next, from a circular to triangular to
> boomerang shapes. The only means I could come up with for equally dividing
> parts involved drawing a line through vertical axis from the centroid to
> either end, and then dividing the length of the line by three to find the
> x, y positions along the line for each part. The horizontal line would then
> have to be manually drawn, following the "bend" of the shape.
>
> Any other suggestions would be much appreciated.
>
> Jerry Sedgewick
> University of Minnesota
>