1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-29 01:21:56 +00:00

Implemented new method to detect border color in non-webtoon comics

This commit is contained in:
Paweł Jastrzębski
2013-11-08 16:55:43 +01:00
parent a7e4968836
commit c8e5b7de9a
2 changed files with 70 additions and 30 deletions

View File

@@ -296,7 +296,8 @@ def getImageFileName(imgfile):
def applyImgOptimization(img, opt, overrideQuality=5):
img.getImageFill(opt.webtoon)
if not img.fill:
img.getImageFill(opt.webtoon)
if not opt.webtoon:
img.cropWhiteSpace(10.0)
if opt.cutpagenumbers and not opt.webtoon:
@@ -377,17 +378,17 @@ def fileImgProcess(work):
applyImgOptimization(img1, opt)
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
if opt.quality == 2:
img3 = image.ComicPage(split[0], opt.profileData)
img3 = image.ComicPage(split[0], opt.profileData, img0.fill)
applyImgOptimization(img3, opt, 0)
img3.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
img4 = image.ComicPage(split[1], opt.profileData)
img4 = image.ComicPage(split[1], opt.profileData, img1.fill)
applyImgOptimization(img4, opt, 0)
img4.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
else:
applyImgOptimization(img, opt)
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
if opt.quality == 2:
img2 = image.ComicPage(os.path.join(dirpath, afile), opt.profileData)
img2 = image.ComicPage(os.path.join(dirpath, afile), opt.profileData, img.fill)
if img.rotated:
img2.image = img2.image.rotate(90)
img2.rotated = True

View File

@@ -142,7 +142,7 @@ class ProfileData:
class ComicPage:
def __init__(self, source, device):
def __init__(self, source, device, fill=None):
try:
self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = device
except KeyError:
@@ -172,7 +172,10 @@ class ComicPage:
self.border = None
self.noHPV = None
self.noVPV = None
self.fill = None
if fill:
self.fill = fill
else:
self.fill = None
def saveToDir(self, targetdir, forcepng, color, wipe):
try:
@@ -428,7 +431,7 @@ class ComicPage:
self.image = self.image.crop((0, 0, widthImg - diff, heightImg))
return self.image
def getImageHistogram(self, image):
def getImageHistogram(self, image, new=True):
histogram = image.histogram()
RBGW = []
pixelCount = 0
@@ -437,37 +440,73 @@ class ComicPage:
RBGW.append(histogram[i] + histogram[256 + i] + histogram[512 + i])
white = 0
black = 0
for i in range(245, 256):
for i in range(251, 256):
white += RBGW[i]
for i in range(11):
for i in range(5):
black += RBGW[i]
if black > white and black > pixelCount*0.5:
return True
if new:
if black > 0 and white == 0:
return 1
elif white > 0 and black == 0:
return -1
else:
return False
else:
return False
if black > white and black > pixelCount*0.5:
return True
else:
return False
def getImageFill(self, isWebToon):
fill = 0
if isWebToon or self.rotated:
fill += self.getImageHistogram(self.image.crop((0, 0, self.image.size[0], 5)))
if isWebToon:
fill = 0
fill += self.getImageHistogram(self.image.crop((0, 0, self.image.size[0], 5)), False)
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, self.image.size[0],
self.image.size[1])))
else:
fill += self.getImageHistogram(self.image.crop((0, 0, 5, self.image.size[1])))
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0],
self.image.size[1])))
if fill == 2:
self.fill = 'black'
elif fill == 0:
self.fill = 'white'
self.image.size[1])), False)
if fill == 2:
self.fill = 'black'
elif fill == 0:
self.fill = 'white'
else:
fill = 0
fill += self.getImageHistogram(self.image.crop((0, 0, 5, 5)), False)
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0], 5)), False)
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, 5, self.image.size[1])), False)
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, self.image.size[1]-5,
self.image.size[0], self.image.size[1])), False)
if fill > 1:
self.fill = 'black'
else:
self.fill = 'white'
else:
fill = 0
fill += self.getImageHistogram(self.image.crop((0, 0, 5, 5)))
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0], 5)))
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, 5, self.image.size[1])))
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, self.image.size[1]-5,
self.image.size[0], self.image.size[1])))
if fill > 1:
# Search fom horizontal solid lines
startY = 0
stopY = 3
searching = True
while stopY <= self.image.size[1]:
checkSolid = self.getImageHistogram(self.image.crop((0, startY, self.image.size[0], stopY)))
if checkSolid:
fill += checkSolid
startY = stopY + 1
stopY = startY + 3
if stopY > self.image.size[1] and searching:
stopY = self.image.size[1]
searching = False
# Search fom vertical solid lines
startX = 0
stopX = 3
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 + 3
if stopX > self.image.size[0] and searching:
stopX = self.image.size[0]
searching = False
if fill > 0:
self.fill = 'black'
else:
self.fill = 'white'