def singleScaleOrientedPaint(im, out, thetas, importance, texture, size, N, noise, nAngles=36): '''same as single scale paint but now the brush strokes will be oriented according to the angles in thetas.''' (height, width, rgb) = out.shape scaledTexture = helper.scaleImage(texture, size) rotations = helper.rotateBrushes(texture, nAngles) rotations = [helper.scaleImage(t, size) for t in rotations] for step in range(N): y=int(rnd.random() * 0.9999 * height) x=int(rnd.random() * 0.9999 * width) if importance[y,x,0] > rnd.random(): i = nAngles * thetas[y,x] / (2 * math.pi) rotatedTexture = rotations[abs(int(round(i[0])))] color_noise = (1 - noise / 2 + noise * np.random.rand(3)) brush(out, y, x, im[y,x] * color_noise, rotatedTexture)
def singleScaleOrientedPaint(im, out, thetas, importance, texture, size, N, noise, nAngles=36): '''same as single scale paint but now the brush strokes will be oriented according to the angles in thetas.''' # size is the product of the dimensions, so we divide by the max texture_scaled = helper.scaleImage(texture, float(size) / max(texture.shape)) out_height = out.shape[0] out_width = out.shape[1] brushes = helper.rotateBrushes(texture_scaled, nAngles) num_strokes = 0 # generate N strokes of the brush while (num_strokes < N): # randrange intervals [0, x), end noninclusive y, x = rnd.randrange(0, out_height), rnd.randrange(0, out_width) rejection_factor = rnd.random() if importance[y, x][0] > rejection_factor: noise_factor = 1 - noise / 2 + noise * np.random.rand(3) color = im[y, x] * noise_factor index = int(thetas[y, x, 0] * nAngles / (2 * math.pi)) brush(out, y, x, color, brushes[index]) # color with this index brush # keeping increment inside ensures N strokes num_strokes += 1
def singleScalePaint(im, out, importance, texture, size=10, N=1000, noise=0.3): '''Paints with all brushed at the same scale using importance sampling.''' (height, width, rgb) = out.shape scaledTexture = helper.scaleImage(texture, size) for step in range(N): y=int(rnd.random() * 0.9999 * height) x=int(rnd.random() * 0.9999 * width) if importance[y,x,0] > rnd.random(): color_noise = (1 - noise / 2 + noise * np.random.rand(3)) brush(out, y, x, im[y,x] * color_noise, scaledTexture)
def singleScalePaint(im, out, importance, texture, size=10, N=1000, noise=0.3): '''Paints with all brushed at the same scale using importance sampling.''' scaleFactor = min(float(size) / texture.shape[0], float(size) / texture.shape[1]) scaledTexture = helper.scaleImage(texture, scaleFactor) if scaleFactor < 1 else texture.copy() halfH, halfW = (int(scaledTexture.shape[0] / 2), int(scaledTexture.shape[1] / 2)) for i in xrange(N * int(1.0 / np.average(importance))): y, x = (rnd.randrange(halfH, im.shape[0] - halfH), rnd.randrange(halfW, im.shape[1] - halfW)) if rnd.random() <= importance[y, x, 0]: color = im[y, x] * (1 - (noise / 2.0) + (noise * np.random.rand(3))) brush(out, y, x, color, scaledTexture)
def singleScaleOrientedPaint(im, out, thetas, importance, texture, size, N, noise, nAngles=36): '''same as single scale paint but now the brush strokes will be oriented according to the angles in thetas.''' scaleFactor = min(float(size) / texture.shape[0], float(size) / texture.shape[1]) scaledTexture = helper.scaleImage(texture, scaleFactor) if scaleFactor < 1 else texture.copy() brushes = helper.rotateBrushes(scaledTexture, nAngles) halfH, halfW = (int(brushes[0].shape[0] / 2), int(brushes[0].shape[1] / 2)) for i in xrange(N * int(1.0 / np.average(importance))): y, x = (rnd.randrange(halfH, im.shape[0] - halfH), rnd.randrange(halfW, im.shape[1] - halfW)) if rnd.random() <= importance[y, x, 0]: angleIndex = int((thetas[y, x, 0] * nAngles) / (2 * math.pi)) color = im[y, x] * (1 - (noise / 2.0) + (noise * np.random.rand(3))) brush(out, y, x, color, brushes[angleIndex])
def singleScalePaint(im, out, importance, texture, size=10, N=1000, noise=0.3): '''Paints with all brushed at the same scale using importance sampling.''' k = float(size)/max(texture.shape) texScaled = helper.scaleImage(texture, k) outH = out.shape[0] outW = out.shape[1] strokes = 0 while (strokes < N): (y, x) = (rnd.randrange(0, outH), rnd.randrange(0, outW)) u = np.random.rand() if importance[y,x][0] > u: col = im[y, x] modNoise = 1-noise/2+noise*np.random.rand(3) col *= modNoise brush(out, y, x, col, texScaled) strokes += 1
def singleScalePaint(im, out, importance, texture, size=10, N=1000, noise=0.3): '''Paints with all brushed at the same scale using importance sampling.''' # size is the product of the dimensions, so we divide by the max texture_scaled = helper.scaleImage(texture, float(size) / max(texture.shape)) out_height = out.shape[0] out_width = out.shape[1] num_strokes = 0 # generate N strokes of the brush while (num_strokes < N): # randrange uses interval [0, x), end noninclusive y, x = rnd.randrange(0, out_height), rnd.randrange(0, out_width) rejection_factor = rnd.random() # ignore samples if below rejection factor if importance[y, x][0] > rejection_factor: noise_factor = 1 - noise / 2 + noise * np.random.rand(3) color = im[y, x] * noise_factor brush(out, y, x, color, texture_scaled) # keeping increment inside ensures N strokes num_strokes += 1
def singleScaleOrientedPaint(im, out, thetas, importance, texture, size, N, noise, nAngles=36): '''same as single scale paint but now the brush strokes will be oriented according to the angles in thetas.''' k = float(size)/max(texture.shape) texScaled = helper.scaleImage(texture, k) outH = out.shape[0] outW = out.shape[1] brushes = helper.rotateBrushes(texScaled, nAngles) strokes = 0 while (strokes < N): (y, x) = (rnd.randrange(0, outH), rnd.randrange(0, outW)) u = np.random.rand() if importance[y,x][0] > u: col = im[y, x] modNoise = 1-noise/2+noise*np.random.rand(3) col *= modNoise i = int((thetas[y,x][0]*nAngles)/(2*np.pi)) % nAngles brush(out, y, x, col, brushes[i]) strokes += 1