Split Image Horizontally With Python Based On Dark Center Line
Solution 1:
First, run a horizontal gradient so you only accentuate vertical edges. You can calculate a horizontal gradient with these coefficients:
-1 0 1-2 0 2-1 0 1
Then compute the sum of the vertical columns, you can use np.sum(array,axis=0)
and you will get this:
I have re-shaped it for ease of viewing - it is actually only 1 pixel tall. Hopefully you can see the bright white line in the middle which you can find with Numpy argmax()
. It will also be better when you just do a horizontal gradient because at the moment I am using the purple and yellow image with vertical and horizontal edges enhanced.
Note that the inspiration for this approach is that you said you "want to identify that long, vertical centerline" and the rationale is that a long line of white pixels will add up to a large sum. Note that I have assumed your image is de-skewed (since you said the line is vertical) and this method may not work so well on skew images where "vertical" line will be spread across several columns.
Post a Comment for "Split Image Horizontally With Python Based On Dark Center Line"