I'm working with Julia. I've the following result from a road's binary image after Thinning (skeleton) . After thinning, I used Harris corner detection, which gets me red dots. To get line segments, I remove the red dots and each line is a line-segment with unique number. The problem is that some red points are too close. How can I make red dots white (i.e. not corner points) if the points are too close?
using Images
using LinearAlgebra
t = thinning(road_image)
detection_method = harris
corners = imcorner(t, Percentile(99.5); method=detection_method)
labels = label_components(corners)
new_labels = label_components(labels) #because some labels are cluster of points, so this makes them 1
all_nodes = component_centroids(new_labels)
centre_line_node = CartesianIndex.(map(i -> trunc.(Int, all_nodes[i]), 1:length(all_nodes)))
img_labels = RGB{N0f8}.(t)
img_labels[centre_line_node] .= RGB(1.0, 0.0, 0.0)
CodePudding user response:
Although you didn't provide enough details about your code (even the full code)
If you want details about the functions, see the previous answer I mentioned above (It's documented). Here, I just replaced contours
with contours_branches
and t==1 && push!(contours, nb)
with (t==1 || t==3) && push!(contours_branches, nb)
as far as I remember. But the idea is the same.
Update:
The code can get enhanced further. For example, I replaced the for
loop in the highlight_contours
function with img_matrix[contours] .= RGB(1,0,0)
. But other improvements are out of the interest of this answer.