Yet another Last™ update of margin color detection algorithm

This commit is contained in:
Paweł Jastrzębski
2014-01-11 16:31:49 +01:00
parent 34aaeab8b1
commit def9e42a61
2 changed files with 22 additions and 34 deletions
+1 -1
View File
@@ -333,7 +333,7 @@ def getImageFileName(imgfile):
def applyImgOptimization(img, opt, hqImage=None): def applyImgOptimization(img, opt, hqImage=None):
if not img.fill: if not img.fill:
img.getImageFill() img.getImageFill(opt.webtoon)
if not opt.webtoon: if not opt.webtoon:
img.cropWhiteSpace(10.0) img.cropWhiteSpace(10.0)
if opt.cutpagenumbers and not opt.webtoon: if opt.cutpagenumbers and not opt.webtoon:
+21 -33
View File
@@ -408,47 +408,35 @@ class ComicPage:
RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i]) RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i])
white = 0 white = 0
black = 0 black = 0
for i in range(253, 256): for i in range(251, 256):
white += RBGW[i] white += RBGW[i]
for i in range(3): for i in range(5):
black += RBGW[i] black += RBGW[i]
if black > pixelCount*0.5 and white == 0: if black > pixelCount*0.8 and white == 0:
return 1 return 1
elif white > pixelCount*0.5 and black == 0: elif white > pixelCount*0.8 and black == 0:
return -1 return -1
else: else:
return False return False
def getImageFill(self): def getImageFill(self, webtoon):
fill = 0 fill = 0
# Search for horizontal solid lines if not webtoon and not self.rotated:
startY = 0 # Search for horizontal solid lines
stopY = 4 startY = 0
searching = True while startY < self.image.size[1]:
while stopY <= self.image.size[1]: checkSolid = self.getImageHistogram(self.image.crop((0, startY, self.image.size[0], startY+1)))
checkSolid = self.getImageHistogram(self.image.crop((0, startY, self.image.size[0], stopY))) if checkSolid:
if checkSolid: fill += checkSolid
fill += checkSolid startY += 1
startY = stopY + 1 else:
stopY = startY + 4 # Search for vertical solid lines
if stopY > self.image.size[1] and searching: startX = 0
startY = self.image.size[1] - 4 while startX < self.image.size[0]:
stopY = self.image.size[1] checkSolid = self.getImageHistogram(self.image.crop((startX, 0, startX+1, self.image.size[1])))
searching = False if checkSolid:
# Search for vertical solid lines fill += checkSolid
startX = 0 startX += 1
stopX = 4
searching = True
while stopX <= self.image.size[0]:
checkSolid = self.getImageHistogram(self.image.crop((startX, 0, stopX, self.image.size[1])))
if checkSolid:
fill += checkSolid
startX = stopX + 1
stopX = startX + 4
if stopX > self.image.size[0] and searching:
startX = self.image.size[0] - 4
stopX = self.image.size[0]
searching = False
if fill > 0: if fill > 0:
self.fill = 'black' self.fill = 'black'
else: else: