I believe that you want to determine how many segments of a straight line are in the image. I did something similar to a morphological hit and was able to segment these lines, although not fully.
I prepared a vertical line structuring (SE) element, and then created two more SEs, rotating it 60 and 120 degrees around my center. I blew the source image with these SEs and then got connected components.
im = imread('IWVlt.jpg'); bw = im2bw(im, graythresh(im)); % SEs w = 15; line = zeros(w); line(:, round(w/2)) = 1; bw1 = zeros(size(bw)); for i = 1:3 bw1 = bw1 + imerode(bw, line); line = imrotate(line, 60, 'nearest'); end [lbl, n] = bwlabel(bw1, 8); figure, imshow(bw1) figure, imshow(label2rgb(lbl))
As a result, I get 25 components. By changing w in your code, you can minimize the error. 
With w = 9, which is the smallest value of w that can take when all segments are detected, I get 26 components. You can filter out too small components. 
source share