mirror of
https://github.com/ciromattia/kcc
synced 2025-12-15 18:56:28 +00:00
Fill detection final improvements
This commit is contained in:
38
kcc/image.py
38
kcc/image.py
@@ -421,31 +421,29 @@ class ComicPage:
|
|||||||
def getImageFill(self, isWebToon):
|
def getImageFill(self, isWebToon):
|
||||||
fill = 0
|
fill = 0
|
||||||
if isWebToon or self.rotated:
|
if isWebToon or self.rotated:
|
||||||
imageT = self.image.crop((0, 0, self.image.size[0], 1))
|
fill += self.getImageHistogram(self.image.crop((0, 0, self.image.size[0], 1)))
|
||||||
imageB = self.image.crop((0, self.image.size[1]-1, self.image.size[0], self.image.size[1]))
|
fill += self.getImageHistogram(self.image.crop((0, self.image.size[1]-1, self.image.size[0],
|
||||||
fill += self.getImageHistogram(imageT)
|
self.image.size[1])))
|
||||||
fill += self.getImageHistogram(imageB)
|
|
||||||
else:
|
else:
|
||||||
imageL = self.image.crop((0, 0, 1, self.image.size[1]))
|
fill += self.getImageHistogram(self.image.crop((0, 0, 1, self.image.size[1])))
|
||||||
imageR = self.image.crop((self.image.size[0]-1, 0, self.image.size[0], self.image.size[1]))
|
fill += self.getImageHistogram(self.image.crop((self.image.size[0]-1, 0, self.image.size[0],
|
||||||
fill += self.getImageHistogram(imageL)
|
self.image.size[1])))
|
||||||
fill += self.getImageHistogram(imageR)
|
|
||||||
if fill == 2:
|
if fill == 2:
|
||||||
return 'black'
|
return 'black'
|
||||||
elif fill == 0:
|
elif fill == 0:
|
||||||
return 'white'
|
return 'white'
|
||||||
else:
|
else:
|
||||||
if isWebToon or self.rotated:
|
bBox = self.image.getbbox()
|
||||||
imageL = self.image.crop((0, 0, 1, self.image.size[1]))
|
wBox = ImageOps.invert(self.image).getbbox()
|
||||||
imageR = self.image.crop((self.image.size[0]-1, 0, self.image.size[0], self.image.size[1]))
|
if bBox is None:
|
||||||
fill += self.getImageHistogram(imageL)
|
bBox = 0
|
||||||
fill += self.getImageHistogram(imageR)
|
|
||||||
else:
|
else:
|
||||||
imageT = self.image.crop((0, 0, self.image.size[0], 1))
|
bBox = (bBox[2]-bBox[0])*(bBox[3]-bBox[1])
|
||||||
imageB = self.image.crop((0, self.image.size[1]-1, self.image.size[0], self.image.size[1]))
|
if wBox is None:
|
||||||
fill += self.getImageHistogram(imageT)
|
wBox = 0
|
||||||
fill += self.getImageHistogram(imageB)
|
|
||||||
if fill >= 2:
|
|
||||||
return 'black'
|
|
||||||
else:
|
else:
|
||||||
return 'white'
|
wBox = (wBox[2]-wBox[0])*(wBox[3]-wBox[1])
|
||||||
|
if wBox <= bBox:
|
||||||
|
return "white"
|
||||||
|
else:
|
||||||
|
return "black"
|
||||||
Reference in New Issue
Block a user