Changeset - 71b9467cfaa2
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 8 years ago 2017-04-30 17:23:55
drewp@bigasterisk.com
add combineImages for use by solver algorithms
Ignore-this: 2add0d7c039abd9e442d11308425d5d9
2 files changed with 34 insertions and 4 deletions:
0 comments (0 inline, 0 general)
light9/paint/solve.py
Show inline comments
 
@@ -45,10 +45,16 @@ def getVal(graph, subj):
 
        ret = float(ret)
 
    return ret
 

	
 
def loadNumpy(path, thumb=(100, 100)):
 
    img = Image.open(path)
 
    img.thumbnail(thumb)
 
    return numpyFromPil(img)
 
    
 
class Solver(object):
 
    def __init__(self, graph):
 
        self.graph = graph
 
        self.samples = {} # uri: Image array
 
        self.fromPath = {} # basename: image array
 
        self.blurredSamples = {}
 
        self.sampleSettings = {} # (uri, path): { dev: { attr: val } }
 
        
 
@@ -57,10 +63,9 @@ class Solver(object):
 

	
 
        with self.graph.currentState() as g:
 
            for samp in g.subjects(RDF.type, L9['LightSample']):
 
                path = 'show/dance2017/cam/test/%s' % g.value(samp, L9['path'])
 
                img = Image.open(path)
 
                img.thumbnail((100, 100))
 
                self.samples[samp] = numpyFromPil(img)
 
                base = g.value(samp, L9['path']).toPython()
 
                path = 'show/dance2017/cam/test/%s' % base
 
                self.samples[samp] = self.fromPath[base] = loadNumpy(path)
 
                self.blurredSamples[samp] = self._blur(self.samples[samp])
 

	
 
                for s in g.objects(samp, L9['setting']):
 
@@ -133,6 +138,15 @@ class Solver(object):
 
                           
 
        return out
 

	
 
    def combineImages(self, layers):
 
        """make a result image from our self.samples images"""
 
        out = (self.fromPath.itervalues().next() * 0).astype(numpy.uint16)
 
        for layer in layers:
 
            colorScaled = self.fromPath[layer['path']] * layer['color']
 
            out += colorScaled.astype(numpy.uint16)
 
        numpy.clip(out, 0, 255, out)
 
        return out.astype(numpy.uint8)
 
        
 
    def simulationLayers(self, settings):
 
        """
 
        how should a simulation preview approximate the light settings
light9/paint/solve_test.py
Show inline comments
 
import unittest
 
import numpy.testing
 
import solve
 
from light9.namespaces import RDF, L9, DEV
 
from light9.rdfdb.localsyncedgraph import LocalSyncedGraph
 
@@ -60,3 +61,18 @@ class TestSimulationLayers(unittest.Test
 
            {'path': 'bg2-d.jpg', 'color': (1, 1, 1)},
 
            {'path': 'bg2-f.jpg', 'color': (1, 1, 1)},
 
                      ], layers)
 

	
 
class TestCombineImages(unittest.TestCase):
 
    def setUp(self):
 
        graph = LocalSyncedGraph(files=['show/dance2017/cam/test/bg.n3'])
 
        self.solver = solve.Solver(graph)
 
        self.solver.loadSamples()
 
    def test(self):
 
        out = self.solver.combineImages(layers=[
 
            {'path': 'bg2-d.jpg', 'color': (.2, .2, .3)},
 
            {'path': 'bg2-a.jpg', 'color': (.888, 0, .3)},
 
        ])
 
        solve.saveNumpy('/tmp/t.png', out)
 
        golden = solve.loadNumpy('show/dance2017/cam/test/layers_out1.png')
 
        numpy.testing.assert_array_equal(golden, out)
 

	
0 comments (0 inline, 0 general)