mirror of
https://github.com/ciromattia/kcc
synced 2026-10-15 14:02:33 +00:00
Yet another Last™ update of margin color detection algorithm
This commit is contained in:
+1
-1
@@ -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
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user