- Registriert
- 3 Aug. 2014
- Beiträge
- 28.573
Teste das mal mit dem Bild das du hier reingestellt hast, ich sehe da sehr wohl einen Unterschied ob es 32 oder 256 Farben (Graustufen) sind - in Gimp kann man über "Bild" > "Modus" > "Indexiert" -> konvertieren auf X Farben.
Gerade an den "Sprechblasen" ganz unteres Bild - die "Sonnenform" - da wo es hellgraue Farben gibt, durch den Scan. Du reduzierst dir die Hölle aus den Dingern und wirst dich schwarz und weiß (2 Farbig) ärgern...
Sei nicht so knauserig und tu dir was gutes und speichere es als 8 Bit PNG ab.
Edit:
Ich habe übrigens meine Lösung jetzt angepasst:
Ergebniss des Autocroppings:
[src=python]
#!/usr/bin/python3
from glob import glob
from math import ceil
from PIL import Image
# READS FROM "input/files.jpg"
# SAVE TO "output/files.jpg"
inputList = glob("input/*.jpg")
#-------------------------------------------------------------------------------
# OPTIONS
borderSize = 3 # The amount of pixels which (should) define a border
maxSearchWidth = 120 # The max search in pixels of the edges
borderColor = (5, 5, 5) # Border color in RGB which is valid as border
borderColorVariantion = 15 # How many levels each pixel is allowed to differ from borderColor to be counted as borderpixel
tolerancePixels = 2 # Pixel tolerance from which border pixels can be apart (more seems to be required!)
space = 6; # The space minimum to be left from detected edges (can be negative)
estimationSteps = 100 # How many steps the image should be gone through in x and y
#-------------------------------------------------------------------------------
borderColorSum = sum(borderColor)
borderColorVariantion = borderColorVariantion * 3;
borderColorSumLow = borderColorSum - borderColorVariantion;
borderColorSumHigh = borderColorSum + borderColorVariantion;
for picture in inputList:
cordsTB = [];
cordsBT = [];
cordsLR = [];
cordsRL = [];
pic = Image.open(picture)
pixels = pic.load()
#print(pic.format, pic.size, pic.mode)
#pic.show()
testLR = ceil(pic.size[0] / estimationSteps)
testTB = ceil(pic.size[1] / estimationSteps)
#---------------------------------------------------------------------------
# RIGHT LEFT DETERMINATION
cordsTB = []
cordsBT = []
step = 0
for x in range(0, pic.size[0]-1, testLR):
cordsTB.append([])
cordsBT.append([])
for y in range(0, maxSearchWidth):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsTB[step].append
for y in range(pic.size[1]-1, pic.size[1]-maxSearchWidth, -1):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsBT[step].append
step += 1
#---------------------------------------------------------------------------
# LEFT-RIGHT DETERMINATION
cordsLR = []
cordsRL = []
step = 0
for y in range(0, pic.size[1]-1, testTB):
cordsLR.append([])
cordsRL.append([])
for x in range(0, maxSearchWidth):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsLR[step].append(x)
for x in range(pic.size[0]-1, pic.size[0]-maxSearchWidth, -1):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsRL[step].append(x)
step += 1
#---------------------------------------------------------------------------
# CROPPING ESTIMATES
# TOP CROP
initialCoords = []
for coordinates in cordsTB:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
top = initialCoords[0]
for coord in initialCoords:
if coord < top:
top = coord
else:
top = 0
#---------------------------------------------------------------------------
# BOTTOM CROP
initialCoords = []
for coordinates in cordsBT:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
bottom = initialCoords[0]
for coord in initialCoords:
if coord > bottom:
bottom = coord
else:
bottom = pic.size[1]
#---------------------------------------------------------------------------
# LEFT CROP
initialCoords = []
for coordinates in cordsLR:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) >= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
left = initialCoords[0]
for coord in initialCoords:
if coord < left:
left = coord
else:
left = 0
#---------------------------------------------------------------------------
# RIGHT CROP
initialCoords = []
for coordinates in cordsRL:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
right = initialCoords[0]
for coord in initialCoords:
if coord > right:
right = coord
else:
right = pic.size[0]
# EDGE SPACING
if (left - space) >= 0:
left -= space
if (top - space) >= 0:
top -= space
if (right + space) <= pic.size[0]:
right += space
if (bottom + space) <= pic.size[1]:
bottom += space;
# CROPPED
pic = pic.crop((left, top, right, bottom))
# SAVE
pic.save("output/"+ picture.replace("input/", "", 1));
# SHOW
#pic.show()
[/src]
Gerade an den "Sprechblasen" ganz unteres Bild - die "Sonnenform" - da wo es hellgraue Farben gibt, durch den Scan. Du reduzierst dir die Hölle aus den Dingern und wirst dich schwarz und weiß (2 Farbig) ärgern...
Sei nicht so knauserig und tu dir was gutes und speichere es als 8 Bit PNG ab.
Edit:
Ich habe übrigens meine Lösung jetzt angepasst:
Ergebniss des Autocroppings:
[src=python]
#!/usr/bin/python3
from glob import glob
from math import ceil
from PIL import Image
# READS FROM "input/files.jpg"
# SAVE TO "output/files.jpg"
inputList = glob("input/*.jpg")
#-------------------------------------------------------------------------------
# OPTIONS
borderSize = 3 # The amount of pixels which (should) define a border
maxSearchWidth = 120 # The max search in pixels of the edges
borderColor = (5, 5, 5) # Border color in RGB which is valid as border
borderColorVariantion = 15 # How many levels each pixel is allowed to differ from borderColor to be counted as borderpixel
tolerancePixels = 2 # Pixel tolerance from which border pixels can be apart (more seems to be required!)
space = 6; # The space minimum to be left from detected edges (can be negative)
estimationSteps = 100 # How many steps the image should be gone through in x and y
#-------------------------------------------------------------------------------
borderColorSum = sum(borderColor)
borderColorVariantion = borderColorVariantion * 3;
borderColorSumLow = borderColorSum - borderColorVariantion;
borderColorSumHigh = borderColorSum + borderColorVariantion;
for picture in inputList:
cordsTB = [];
cordsBT = [];
cordsLR = [];
cordsRL = [];
pic = Image.open(picture)
pixels = pic.load()
#print(pic.format, pic.size, pic.mode)
#pic.show()
testLR = ceil(pic.size[0] / estimationSteps)
testTB = ceil(pic.size[1] / estimationSteps)
#---------------------------------------------------------------------------
# RIGHT LEFT DETERMINATION
cordsTB = []
cordsBT = []
step = 0
for x in range(0, pic.size[0]-1, testLR):
cordsTB.append([])
cordsBT.append([])
for y in range(0, maxSearchWidth):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsTB[step].append
for y in range(pic.size[1]-1, pic.size[1]-maxSearchWidth, -1):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsBT[step].append
step += 1
#---------------------------------------------------------------------------
# LEFT-RIGHT DETERMINATION
cordsLR = []
cordsRL = []
step = 0
for y in range(0, pic.size[1]-1, testTB):
cordsLR.append([])
cordsRL.append([])
for x in range(0, maxSearchWidth):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsLR[step].append(x)
for x in range(pic.size[0]-1, pic.size[0]-maxSearchWidth, -1):
pixelValue = sum(pic.getpixel((x,y)));
if pixelValue >= borderColorSumLow and pixelValue <= borderColorSumHigh:
cordsRL[step].append(x)
step += 1
#---------------------------------------------------------------------------
# CROPPING ESTIMATES
# TOP CROP
initialCoords = []
for coordinates in cordsTB:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
top = initialCoords[0]
for coord in initialCoords:
if coord < top:
top = coord
else:
top = 0
#---------------------------------------------------------------------------
# BOTTOM CROP
initialCoords = []
for coordinates in cordsBT:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
bottom = initialCoords[0]
for coord in initialCoords:
if coord > bottom:
bottom = coord
else:
bottom = pic.size[1]
#---------------------------------------------------------------------------
# LEFT CROP
initialCoords = []
for coordinates in cordsLR:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) >= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
left = initialCoords[0]
for coord in initialCoords:
if coord < left:
left = coord
else:
left = 0
#---------------------------------------------------------------------------
# RIGHT CROP
initialCoords = []
for coordinates in cordsRL:
try:
starting = coordinates[0]
currentSize = 1
for coord in coordinates[1:]:
if (coord - tolerancePixels) <= starting:
currentSize += 1
if currentSize == borderSize:
initialCoords.append(starting)
break;
else:
starting = coord
currentSize = 1
except:
pass
if len(initialCoords) != 0:
right = initialCoords[0]
for coord in initialCoords:
if coord > right:
right = coord
else:
right = pic.size[0]
# EDGE SPACING
if (left - space) >= 0:
left -= space
if (top - space) >= 0:
top -= space
if (right + space) <= pic.size[0]:
right += space
if (bottom + space) <= pic.size[1]:
bottom += space;
# CROPPED
pic = pic.crop((left, top, right, bottom))
# SAVE
pic.save("output/"+ picture.replace("input/", "", 1));
# SHOW
#pic.show()
[/src]
Zuletzt bearbeitet: