# Perimeter detection & interpolation

Hello, I’m trying to figure out how to: 1) determine the outer edge of a 2D binary object, and; 2) then interpolate around the edge as if there are no imperfections on the surface. The first step I’ve done in ImageJ, but I can’t find a way to do the second!

1. is using magic wand to identify the perimeter
2. is an example of how I need to remove surface imperfections and interpolate between points to get a simpler outer perimeter
3. is a convex hull selection, but it doesn’t adhere to the original perimeter enough

Any suggestions would be greatly appreciated!

Maybe once you have the rough outline, you can apply the Ramer-Douglas-Peucker (RDP) or Visvalingam line simplification (see this carthographic application) algorithms to reduce complexity of the coordinate set of the ROI without losing too much information.

Some methods do not guarantee that you are keeping the object completely enclosed, but might be enough to your purpose.

I wonder if any of these could work:

Segment the region, make binary, then run a morphological closing (max filter followed by min filter of the same size) then create a selection of the result

Filter your image with a large Gaussian filter, threshold and create selection

Threshold the object, then create a selection based on the threshold, get the coordinates of the ROI, then write a running average (of varying sizes depending how much detail you want to remove) on the array of coordinates and create a new selection with those filtered arrays.

Hi
@jpah1

]

``````run("Duplicate...", "title=1");
close("\\Others");
run("Duplicate...", "title=2");
setBackgroundColor(0,0,0);
//setTool("wand");
doWand(486, 158, 16.0, "Legacy");
run("Clear", "slice");
setBackgroundColor(255,255,255);
setOption("BlackBackground",true);
run("Clear Outside");
run("Select None");
wait(1000);
setAutoThreshold("Yen");
//run("Threshold...");
//setThreshold(0, 0);
setOption("BlackBackground", true);
run("Fill Holes");
run("Create Selection");
run("Fit Spline");
roiManager("Show All");
roiManager("Select", 0);
selectWindow("1");
run("Restore Selection");
run("Enlarge...", "enlarge=-12");
``````

Greetings

Yes that it is another possibility, but I did not suggest an erosion (which will will generate a ROI smaller than the original), but a closing (dilation followed by erosion, or max followed by min filter).

1 Like

Thank you all! These tips have been really helpful. Using your suggestions, I learned a lot. I made many different attempts and here is a method that seems to preliminarily work rather well:

1. Morphological Filter --> Opening (55px, Disk)
2. Morphological Filter --> Closing (55px, Disk)
3. Shape smoothing --> Absolute Number FDs (20)

Compare results:

Manually hand drawing perimeter and calculating surface area = 307.441 mm^2
Above methodology = 321.459 mm^2
Original shape with perfect edge = 331.312 mm^2

There is about 3% error, which is acceptable for now! But I hope to improve.

TESTB_Leaf_fig3C.tif (1.6 MB)

Btw, here is the “perfect edge” example