View Single Post
Old 10-14-2018, 02:03 AM   #3
Tex2002ans
Wizard
Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.Tex2002ans ought to be getting tired of karma fortunes by now.
 
Posts: 2,306
Karma: 13057279
Join Date: Jul 2012
Device: Kobo Forma, Nook
Quote:
Originally Posted by BetterRed View Post
Have a look for imaging forensic tools.
Hmmm... that may be another angle to research.

I know a lot of times they "average" pixel colors of entire rows/columns to get semi-unique fingerprints. Perhaps something like that could be used to detect lines too.

* * *

Tonight I was dabbling a bit more with Hough Lines.

I had quite a bit of success locating the line through the text.

ImageMagick Hough Lines

Original Image:

Click image for larger version

Name:	pg241.png
Views:	522
Size:	143.6 KB
ID:	166906

Step 1: Inverse the scan using ImageMagick's canny (see fmwconcepts link in Post #1):

Code:
convert test.png -canny 0x1+10%+40% test_inverse.png
Click image for larger version

Name:	pg241_inverse.png
Views:	521
Size:	197.4 KB
ID:	166910

Step 2: Then calculate Hough Lines:

From testing, on this specific book, I found a threshold between 500-700 worked:

Spoiler:
Code:
convert -hough-lines 5x5+500 -fill red -transparent white test_inverse.png test_lines_500.png
convert -hough-lines 5x5+550 -fill red -transparent white test_inverse.png test_lines_550.png
convert -hough-lines 5x5+600 -fill red -transparent white test_inverse.png test_lines_600.png
convert -hough-lines 5x5+650 -fill red -transparent white test_inverse.png test_lines_650.png
convert -hough-lines 5x5+700 -fill red -transparent white test_inverse.png test_lines_700.png


Click image for larger version

Name:	pg241_lines_500.png
Views:	519
Size:	171.1 KB
ID:	166911Click image for larger version

Name:	pg241_lines_550.png
Views:	559
Size:	170.8 KB
ID:	166912Click image for larger version

Name:	pg241_lines_600.png
Views:	544
Size:	170.6 KB
ID:	166913

The higher the threshold, the more "false positives" disappeared.

Step 3: Overlay Hough Lines with image:

Spoiler:
Code:
convert test.png ( test_lines_500.png ) -compose over -composite test4_composite_500.png
convert test.png ( test_lines_550.png ) -compose over -composite test4_composite_550.png
convert test.png ( test_lines_600.png ) -compose over -composite test4_composite_600.png
convert test.png ( test_lines_650.png ) -compose over -composite test4_composite_650.png
convert test.png ( test_lines_700.png ) -compose over -composite test4_composite_700.png


Click image for larger version

Name:	pg241_composite_500.png
Views:	504
Size:	401.4 KB
ID:	166907Click image for larger version

Name:	pg241_composite_550.png
Views:	513
Size:	403.4 KB
ID:	166908Click image for larger version

Name:	pg241_composite_600.png
Views:	500
Size:	404.4 KB
ID:	166909

Here's the same steps with another page:

Click image for larger version

Name:	pg093.png
Views:	517
Size:	149.9 KB
ID:	166902Click image for larger version

Name:	pg093_inverse.png
Views:	483
Size:	206.1 KB
ID:	166904Click image for larger version

Name:	pg093_lines_600.png
Views:	519
Size:	76.0 KB
ID:	166905Click image for larger version

Name:	pg093_composite_600.png
Views:	510
Size:	239.0 KB
ID:	166903

* * *

Side Note: To see what a Hough Line calculation is actually doing, I found this part of the video did a decent job explaining it visually:

https://youtu.be/4zHbI-fFIlI?t=219

It goes row-by-row detecting each white pixel, then spins a line in a 360. Plotting this leads to points of various strength (which tells you probable locations + angles of lines).

Last edited by Tex2002ans; 10-14-2018 at 01:45 PM.
Tex2002ans is offline   Reply With Quote