I have retrieved all pixels from a png image which looks like this…
I started to get all filled lines horizontal to get the start end pixel of each line …. as I scan horizontal I get also the vertical lines in horizontal layer…. I guess it is possible to code all manually but it takes time…. my question is has anyone experience with opencv,imageJ or other to tell if any of this libs could solve the problem… I am also open for any algorithm suggestion…. (using Java)….
-> The biggest problem is the thickness of the lines between 1 and 4 pixels otherwise I could easily retrieve the joint points
Here is a possible solution using image morphology. The code below is in C++ since I only have little experience with Java.
To solve your problem, you need:
The bad news is both operations is not yet supported in OpenCV as of version 2.4.3. The good news is I have implemented both operations, the code is available on my blog:
void thinning(cv::Mat& im)void hitmiss(cv::Mat& src, cv::Mat dst, cv::Mat& kernel)I will be using my
thinning()andhitmiss()functions and your test image.After loading the image, convert it to single-channel binary image.
Since the width of the lines vary from 1 to 4 pixels perform thinning to get one-width lines.
From the thinned image, notice that there are perfect and not perfect joint points as shown in the figure below.
To cover both the perfect and imperfect joint points, we need the following kernels for the hit-or-miss transform.
Open the original image to make the result clearer.
The joint points successfully located, draw it on the original image.
For the sake of completeness, here is the full code. With some efforts you can port it to Java.