Beispiel #1
0
def saveClusteredImage(inPix, segmentsByIDlist, width, height, filename):
    im, pix = imgIO.createWhiteImg(width, height)
    for segment in range(0,len(segmentsByIDlist)):
        RGB = inPix[segmentsByIDlist[segment][0][0], segmentsByIDlist[segment][0][1]]
        for p in range (0, len(segmentsByIDlist[segment])):
            pix[segmentsByIDlist[segment][p][0], segmentsByIDlist[segment][p][1]] = RGB
    im.save(filename + "_clustered.png")
    del im
    del pix
    im, pix = imgIO.createWhiteImg(width, height)
    for segment in range(0,len(segmentsByIDlist)):
        RGB = (randint(0,255), randint(0,255), randint(0,255))
        for p in range (0, len(segmentsByIDlist[segment])):
            pix[segmentsByIDlist[segment][p][0], segmentsByIDlist[segment][p][1]] = RGB
    im.save(filename + "_clustered_randomColor.png")
    del im
    del pix
Beispiel #2
0
def convertImage(infile, inIm=None, path="", input_dir="", output_dir="", verbose=False, strokeWidth=100, strokeHeight=100, randSizes=100, longStrokes=False, directedRotate=False, strokeDensity=70, background='blur', noHairlines=False, noMargins=False, segBound=100, colDiff=500, ground=False, saturation=2.5, highlight=False, colorify=0, otherfiles=False, felzScale=50, felzSigma=4.5, felzMinsize=10, webinterface=False):
    
    warnings.simplefilter('ignore', np.RankWarning) # ignore warnings when the polyfit function doesn't get enough data
    if inIm == None:
        inIm, inPix = imgIO.loadImgAsPixelAccess(path + input_dir + infile)
    else:
        inPix = inIm.load()
    width, height = inIm.size
    
    if inIm.mode != 'RGB':
        inIm = inIm.convert('RGB')
    
    drawRegressionLines = otherfiles
    if drawRegressionLines:
        inImCopy = inIm.copy()
        inPixCopy = inImCopy.load()
    else:
        inImCopy = None
        inPixCopy = None
    
    filename, outfile = getOutfileName(path, output_dir, infile)
    outIm, outPix = imgIO.createWhiteImg(width, height)
    inIm, inPix = saturateImage(inIm, filename, saturation=saturation, otherfiles=otherfiles)
    inPixNP = np.array(inIm)
    
    segmentsNP, segmentsByIDlist = clustering(inPixNP, width, height, scale=felzScale, sigma=felzSigma, min_size=felzMinsize)
    if otherfiles:
        saveClusteredImage(inPix, segmentsByIDlist, width, height, filename) # optional
    
    segmentsByIDlist_sorted = sortSegmentsBySize(segmentsByIDlist) # sort the segments by their length, prepend regionID to each segment
    
    segmentParams = getSegmentParams(segmentsByIDlist_sorted, inPix, drawRegressionLines, inImCopy, inPixCopy, width, height)
    
    if drawRegressionLines:
        inImCopy.save(filename + "_regLines.png")
    
    outIm, outPix = colorBackground(inIm, inPix, segmentsByIDlist, outIm, outPix, background)
    
    
    outIm = paintImg_with_brushstrokes(outfile, outIm, outPix, width, height, segmentParams, segmentsByIDlist, inPix, verbose, randSizes=randSizes, longStrokes=longStrokes, directedRotate=directedRotate, strokeWidth=strokeWidth, strokeHeight=strokeHeight, strokeDensity=strokeDensity, noHairlines=noHairlines, noMargins=noMargins, segBound=segBound, colDiff=colDiff, ground=ground, highlight=highlight, colorify=colorify, otherfiles=otherfiles, felzScale=felzScale, felzSigma=felzSigma, felzMinsize=felzMinsize, webinterface=webinterface) # segmentsByIDlist to be replaced by segmentsByIDlist_sorted
    
    return outIm