mirror of
https://github.com/ciromattia/kcc
synced 2026-05-22 15:32:06 +00:00
Implemented new method to detect border color in non-webtoon comics
This commit is contained in:
@@ -296,7 +296,8 @@ def getImageFileName(imgfile):
|
|||||||
|
|
||||||
|
|
||||||
def applyImgOptimization(img, opt, overrideQuality=5):
|
def applyImgOptimization(img, opt, overrideQuality=5):
|
||||||
img.getImageFill(opt.webtoon)
|
if not img.fill:
|
||||||
|
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:
|
||||||
@@ -377,17 +378,17 @@ def fileImgProcess(work):
|
|||||||
applyImgOptimization(img1, opt)
|
applyImgOptimization(img1, opt)
|
||||||
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
img1.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
if opt.quality == 2:
|
if opt.quality == 2:
|
||||||
img3 = image.ComicPage(split[0], opt.profileData)
|
img3 = image.ComicPage(split[0], opt.profileData, img0.fill)
|
||||||
applyImgOptimization(img3, opt, 0)
|
applyImgOptimization(img3, opt, 0)
|
||||||
img3.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
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)
|
applyImgOptimization(img4, opt, 0)
|
||||||
img4.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
img4.saveToDir(dirpath, opt.forcepng, opt.forcecolor, True)
|
||||||
else:
|
else:
|
||||||
applyImgOptimization(img, opt)
|
applyImgOptimization(img, opt)
|
||||||
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
img.saveToDir(dirpath, opt.forcepng, opt.forcecolor, wipe)
|
||||||
if opt.quality == 2:
|
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:
|
if img.rotated:
|
||||||
img2.image = img2.image.rotate(90)
|
img2.image = img2.image.rotate(90)
|
||||||
img2.rotated = True
|
img2.rotated = True
|
||||||
|
|||||||
91
kcc/image.py
91
kcc/image.py
@@ -142,7 +142,7 @@ class ProfileData:
|
|||||||
|
|
||||||
|
|
||||||
class ComicPage:
|
class ComicPage:
|
||||||
def __init__(self, source, device):
|
def __init__(self, source, device, fill=None):
|
||||||
try:
|
try:
|
||||||
self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = device
|
self.profile_label, self.size, self.palette, self.gamma, self.panelviewsize = device
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -172,7 +172,10 @@ class ComicPage:
|
|||||||
self.border = None
|
self.border = None
|
||||||
self.noHPV = None
|
self.noHPV = None
|
||||||
self.noVPV = None
|
self.noVPV = None
|
||||||
self.fill = None
|
if fill:
|
||||||
|
self.fill = fill
|
||||||
|
else:
|
||||||
|
self.fill = None
|
||||||
|
|
||||||
def saveToDir(self, targetdir, forcepng, color, wipe):
|
def saveToDir(self, targetdir, forcepng, color, wipe):
|
||||||
try:
|
try:
|
||||||
@@ -428,7 +431,7 @@ class ComicPage:
|
|||||||
self.image = self.image.crop((0, 0, widthImg - diff, heightImg))
|
self.image = self.image.crop((0, 0, widthImg - diff, heightImg))
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
def getImageHistogram(self, image):
|
def getImageHistogram(self, image, new=True):
|
||||||
histogram = image.histogram()
|
histogram = image.histogram()
|
||||||
RBGW = []
|
RBGW = []
|
||||||
pixelCount = 0
|
pixelCount = 0
|
||||||
@@ -437,37 +440,73 @@ 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(245, 256):
|
for i in range(251, 256):
|
||||||
white += RBGW[i]
|
white += RBGW[i]
|
||||||
for i in range(11):
|
for i in range(5):
|
||||||
black += RBGW[i]
|
black += RBGW[i]
|
||||||
if black > white and black > pixelCount*0.5:
|
if new:
|
||||||
return True
|
if black > 0 and white == 0:
|
||||||
|
return 1
|
||||||
|
elif white > 0 and black == 0:
|
||||||
|
return -1
|
||||||
|
else:
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
return False
|
if black > white and black > pixelCount*0.5:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
def getImageFill(self, isWebToon):
|
def getImageFill(self, isWebToon):
|
||||||
fill = 0
|
if isWebToon:
|
||||||
if isWebToon or self.rotated:
|
fill = 0
|
||||||
fill += self.getImageHistogram(self.image.crop((0, 0, self.image.size[0], 5)))
|
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],
|
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, self.image.size[0],
|
||||||
self.image.size[1])))
|
self.image.size[1])), False)
|
||||||
else:
|
if fill == 2:
|
||||||
fill += self.getImageHistogram(self.image.crop((0, 0, 5, self.image.size[1])))
|
self.fill = 'black'
|
||||||
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0],
|
elif fill == 0:
|
||||||
self.image.size[1])))
|
self.fill = 'white'
|
||||||
if fill == 2:
|
else:
|
||||||
self.fill = 'black'
|
fill = 0
|
||||||
elif fill == 0:
|
fill += self.getImageHistogram(self.image.crop((0, 0, 5, 5)), False)
|
||||||
self.fill = 'white'
|
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:
|
else:
|
||||||
fill = 0
|
fill = 0
|
||||||
fill += self.getImageHistogram(self.image.crop((0, 0, 5, 5)))
|
# Search fom horizontal solid lines
|
||||||
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, 0, self.image.size[0], 5)))
|
startY = 0
|
||||||
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-5, 5, self.image.size[1])))
|
stopY = 3
|
||||||
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-5, self.image.size[1]-5,
|
searching = True
|
||||||
self.image.size[0], self.image.size[1])))
|
while stopY <= self.image.size[1]:
|
||||||
if fill > 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'
|
self.fill = 'black'
|
||||||
else:
|
else:
|
||||||
self.fill = 'white'
|
self.fill = 'white'
|
||||||
Reference in New Issue
Block a user