Home > Software design >  To find the coordinates of the skeleton of contour of an image using java
To find the coordinates of the skeleton of contour of an image using java

Time:04-09

My requirement is to find the coordinates of skeleton of an image using JAVA. This is the actual image contour from which i ahve to find the skeleton Below are my questions.

  1. I could do that by using OpenCV Java but it has gaps and also it is not 1 pixel width. Can we get the skeleton(of 1 pixel width) with out gaps using Java's openCV?This is the skeleton got from openCV JAVA

  2. I can also find the skeleton by using imageJ library of Java but the returned skeleton is in ByteProcessor with which I can not process further to get the coordinates of skeleton. Is there a way to convert ByteProcessor back to image(matrix) so that I can find the coordinates by using openCV findcontours()?

  3. Apart from these two, are there any other way of finding skeleton of an image using Java.

Attached the images for reference. Please advice.

CodePudding user response:

maybe you should use other words to describe your problem, if it describes better, you should better say you need an array with coordinates of the skeleton. I can propose you to make two pixel sliding window for each line and extract contour when pixels are different (blakc/white) then, just link extracting points in an array to get all coordinates

CodePudding user response:

Here is an ImageJ-macro that gives you the coordinates:

orig=getTitle();
nme=split(orig, ".");
path=getDir("image") nme[0] ".csv";
run("Duplicate...", "title=cpy");
run("Skeletonize");
run("Create Selection");
run("Save XY Coordinates...", "save=" path);
selectWindow(orig);
run("Restore Selection");
close("cpy");
open(path);

It should be easy to convert it to Java (just use the Recorder).

  • Related