如何使用ImageMagick来区分页面中的空白列以区分两篇论文 [英] How to detect a blank column in a page using ImageMagick to distinguish two column papers
问题描述
我尝试使用ImageMagick区分两列pdf科学论文,并使用bash脚本找到两列分开的位置.
I try to distinguish two-column pdf scientific papers using ImageMagick and locate the point where the two columns are separated using a bash script.
我的想法是使用页面中央的滑动窗口来查找完全白色的窗口.像这样:
My idea is to use a sliding window at the center of the page to find a window which is completely white. Something like:
for i in {0..$page_width..$step} do
# get the color of a box 100x100+"$i"+50%
# if the box is completely blank or 90% blank, then return ($i + 50)
done
但是,我不知道检查图片中方框的代码是否完全空白.
However, I don't know the code to check a box in the picture is completely blank.
样本图片:
推荐答案
一种方法是通过调整大小来计算垂直列下方所有像素的投影" (即均值)图像只有1像素高.我对图像进行了反转/取反,因此您可以更好地看到颜色,并将1像素高的图像拉伸到20像素高,以便可以在底部看到它:
One way to do this is to calculate a "projection" (i.e. mean) of all the pixels down the vertical columns by resizing the image to just 1pixel tall. I have inverted/negated the image so you can see the colours better and stretched the 1pixel tall image to 20pixels tall so you can see it at the bottom:
magick paper.png -alpha off -negate -scale x1\! -auto-level -scale x20\! result.png
因此,如果您再进一步一点,使输出一行为100像素,然后将其视为文本,则可能希望在页面中心50%位置附近有一些特别低的值:
So, if you take that a little further and make the output a single row of 100 pixels and look at it as text, you might hope for some particularly low values around the 50% position at the centre of the page:
magick paper.png -alpha off -colorspace gray -negate -scale x1\! -scale 100x\! -auto-level txt:
示例输出
# ImageMagick pixel enumeration: 100,1,65535,gray
0,0: (0) #000000 gray(0)
1,0: (0) #000000 gray(0)
2,0: (0) #000000 gray(0)
3,0: (56.1923) #383838 gray(22.0362%)
4,0: (209.168) #D1D1D1 gray(82.0267%)
5,0: (187.374) #BBBBBB gray(73.4801%)
6,0: (180.066) #B4B4B4 gray(70.6143%)
7,0: (188.581) #BDBDBD gray(73.9534%)
8,0: (197.288) #C5C5C5 gray(77.368%)
9,0: (230.555) #E7E7E7 gray(90.4138%)
...
...
45,0: (221.296) #DDDDDD gray(86.7826%)
46,0: (234.086) #EAEAEA gray(91.7985%)
47,0: (239.522) #F0F0F0 gray(93.93%)
48,0: (191.323) #BFBFBF gray(75.0288%)
49,0: (44.6977) #2D2D2D gray(17.5285%) <--- HERE IS THE CENTRAL GUTTER
50,0: (27.1557) #1B1B1B gray(10.6493%) <--- AND HERE - AROUND 50% ACROSS
51,0: (145.663) #929292 gray(57.1227%)
52,0: (154.567) #9B9B9B gray(60.6144%)
53,0: (184.97) #B9B9B9 gray(72.5372%)
...
...
91,0: (156.178) #9C9C9C gray(61.2462%)
92,0: (151.242) #979797 gray(59.3107%)
93,0: (146.532) #939393 gray(57.4635%)
94,0: (149.511) #969696 gray(58.6319%)
95,0: (185.506) #BABABA gray(72.7475%)
96,0: (21.7851) #161616 gray(8.54316%)
97,0: (0) #000000 gray(0)
98,0: (0) #000000 gray(0)
99,0: (0) #000000 gray(0)
其他想法:
-
您可以使用以下方法让 ImageMagick 为您执行阈值处理,并查看第572行:
You could let ImageMagick do the thresholding for you with something like this and look around line 572:
magick paper.png -alpha off -colorspace gray -negate -scale x1\! -threshold 2% txt:
您可以先将左右边缘剃除10%,以消除边缘效果:
You could shave 10% off the left and right edges first, to get rid of edge-effects:
magick paper.png -shave 10%x ... result.png
这篇关于如何使用ImageMagick来区分页面中的空白列以区分两篇论文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!