Ejemplo n.º 1
0
    def setup_layer(self) -> None:
        assert self._image is not None, 'Source image is not provided!'
        assert self._pins is not None, 'Layer pins are not provided!'
        self._pin_count = len(self.pins)

        # Configurations for each specific type.
        if self._type & tp.COLOR_RGB:
            assert (utils.channels(self._image) >= 3 and
                    'RGB(A) image is expected for a layer with type COLOR_RGB')
            self._line_cost = LINE_COST_FUNCTIONS['RGB_COLOR_COST']
        else:
            assert (
                utils.channels(self._image) == 1 and
                'GrayScale image is expected for a layer with type MONOCHROME')
            self._line_cost = LINE_COST_FUNCTIONS['MONOCHROME_COST']

        #TODO: support having origin and offset
        if self._working_image is None:
            self._working_image = 255 * np.ones(self._image.shape[:3],
                                                np.uint8)
        if len(self._visited_pins) == 0:
            self._visited_pins = self._pin_count * self._pin_count * [0]
        # Pre-compute line lengths and spaces for higher performance.
        if len(self._line_spaces) == 0 or len(self._lengths) == 0:
            self._line_spaces, self._lengths = utils.compute_lines(self._pins)
Ejemplo n.º 2
0
    def drawSpectra(self, data, samplerate):
        leftData, rightData = utils.channels(data)
        leftPoints, rightPoints = [], []
        width, _ = self.windowSize

        # buffer left/right data
        self.leftBuffer.add(leftData)
        if (self.leftBuffer.filled):
            leftSpectrum = self.buildSpectrum(self.leftBuffer.data)
            # slicing the data breaks pitch dection outside of the window.
            # (full range of the fft bins. doesn't have to fall inside the window.)
            leftSpectrum = self.avgLeft.average(leftSpectrum)
            leftPoints = self.drawSpectrum(leftSpectrum)
            freq = self.calcFreq(leftSpectrum, samplerate)
            self.printText(
                "L Freq: {0:.2f}Hz {1}".format(freq, audio.pitch(freq)), 0,
                self.leftcolor)

        self.rightBuffer.add(rightData)
        if (self.rightBuffer.filled):
            rightSpectrum = self.buildSpectrum(self.rightBuffer.data)
            rightSpectrum = self.avgRight.average(rightSpectrum)
            rightPoints = self.drawSpectrum(rightSpectrum)
            freq = self.calcFreq(rightSpectrum, samplerate)
            self.printText(
                "R Freq: {0:.2f}Hz {1}".format(freq, audio.pitch(freq)), 1,
                self.rightcolor)

        return leftPoints, rightPoints
Ejemplo n.º 3
0
 def update_image(self, src_idx: int, dst_idx: int) -> None:
   line_space = self._line_spaces[src_idx * self._pin_count + dst_idx]
   ratio = self._thread_intensity / 255.0
   color = [ratio * c for c in self._thread_color[:3]]
   for px, py in line_space:
     for c in range(utils.channels(self._working_image)):
       pixel = (1.0 - ratio) * self._working_image.item(py, px, c) + color[c]
       self._working_image.itemset((py, px, c), min(255, int(pixel)))
Ejemplo n.º 4
0
def alias(img,amount): #cheating with a mask
	length, width = bounds(img)
	channel = channels(img)
	post = avail(img)
	mask = [[0,0,0],[255,255,255],[0,0,0],
			[255,255,255],[255,255,255],[255,255,255],
			[0,0,0],[255,255,255],[0,0,0]]
	result = find(img,mask,(3,3))
	return result
Ejemplo n.º 5
0
    def drawXY(self, data, scale=5):
        width, height = self.windowSize
        lcvalues, rcvalues = utils.channels(data)

        lcvalues = list(
            map(lambda x: (width / 2) + (x / ((1 << 32) - 1) * width * scale),
                lcvalues))
        rcvalues = list(
            map(
                lambda y: height - ((height / 2) + (y / (
                    (1 << 32) - 1) * height * scale)), rcvalues))

        return list(zip(lcvalues, rcvalues))
Ejemplo n.º 6
0
    def drawWaveForm(self, data, samplerate):
        """ Draw the shape of the wave in data set."""
        lchannel_data, rchannel_data = utils.channels(data)
        # turn data into a list of points
        width, height = self.windowSize
        """ Simply loop through all the points of data scale them right, and plot them. """
        lpoints = []
        if (len(lchannel_data) < width):
            for x in range(0, len(lchannel_data), 1):
                value = self.pointcalc([lchannel_data[x]])
                y = int(height * 0.20 - (value / ((1 << 32) - 1) *
                                         (height / 2.0)))
                point = (x, y)
                lpoints.append(point)
        else:
            for x, chunk in enumerate(
                    utils.chunks(lchannel_data,
                                 round(len(lchannel_data) / width))):
                value = self.pointcalc(chunk) * self.waveFormScale
                if numpy.isnan(value) or numpy.isinf(value):
                    value = 0
                y = int(height * 0.20 - (value / ((1 << 32) - 1) *
                                         (height / 2.0)))
                point = (x, y)
                lpoints.append(point)

        rpoints = []
        if (len(rchannel_data) < width):
            for x in range(0, len(rchannel_data), 1):
                value = rchannel_data[x]
                y = int(height * 0.50 - (value / ((1 << 32) - 1) *
                                         (height / 2.0)))
                point = (x, y)
                rpoints.append(point)
        else:
            for x, chunk in enumerate(
                    utils.chunks(rchannel_data,
                                 round(len(rchannel_data) / width))):
                value = self.pointcalc(chunk) * self.waveFormScale
                y = int(height * 0.50 - (value / ((1 << 32) - 1) *
                                         (height / 2.0)))
                point = (x, y)
                rpoints.append(point)

        points = lpoints, rpoints
        return points
Ejemplo n.º 7
0
def alias(img, amount):  # cheating with a mask
    length, width = bounds(img)
    channel = channels(img)
    post = avail(img)
    mask = [
        [0, 0, 0],
        [255, 255, 255],
        [0, 0, 0],
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        [0, 0, 0],
        [255, 255, 255],
        [0, 0, 0],
    ]
    result = find(img, mask, (3, 3))
    return result
Ejemplo n.º 8
0
#!/usr/bin/env python
from utils import (load, take, show, bgr, image, like, bounds,
channels, crop, scale, color, avail, colorPicker)
from proto import alias, sharpen, group, find, edge, center, distance
from PIL import Image

print "# fast stuff"
img = load('samples/abstract/colors.png')
#b = take()
show(img)
b, g, r = bgr(img)
img = image(b,b,b)
test = like(img)
bound = bounds(b)
channel = channels(b)
coord = (0,0,50,50)
closer = crop(img, coord)
bigger = scale(closer, 2.0)
eyedrop = color(img, 0, 30)
pallet = avail(img)
colorPicker(img,0,30)

print "# slow stuff"
res1 = alias(img, .3)
res2 = sharpen(img, .3)
blob1 = group(img)
mask = Image.new("RGB", (50, 10), "white")
blob3 = find(img,mask,(3,3))
coords1 = edge(img)
coords2 = center(blob1)
dist = distance(0,3)