Esempio n. 1
0
    def run_algo(self, stdout=None):
        """
        The core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        timeout = False

        # Get image size
        size = image(self.work_dir + 'input_0.png').size

        # Run tvrestore
        self.wait_proc(
            self.run_proc([
                'fstv', 'u0.png', 'mask.png', 'inpainted.png',
                str(self.cfg['param']['alpha']),
                str(self.cfg['param']['beta'])
            ],
                          stdout=stdout,
                          stderr=stdout), timeout)

        zoomfactor = int(max(1, floor(550.0 / max(size[0], size[1]))))
        size = (zoomfactor * size[0], zoomfactor * size[1])

        for filename in ['input_0', 'composite', 'inpainted']:
            img = image(self.work_dir + filename + '.png')
            img.resize(size, method='nearest')
            img.save(self.work_dir + filename + '_zoom.png')

        self.cfg['param']['displayheight'] = max(200, size[1])
        self.cfg['param']['zoomfactor'] = zoomfactor
        self.cfg['param']['zoomwidth'] = size[0]
        self.cfg['param']['zoomheight'] = size[1]
Esempio n. 2
0
    def select_subimage(self, x0, y0, x1, y1):
        """
        cut subimage from original image
        """
        # draw selected rectangle on the image
        imgS = image(self.work_dir + 'input_0.png')
        imgS.draw_line([(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)], 
                       color="red")
        imgS.draw_line([(x0+1, y0+1), (x1-1, y0+1), (x1-1, y1-1), (x0+1, y1-1), 
                       (x0+1, y0+1)], color="white")
        imgS.save(self.work_dir + 'input_0s.png')
        # crop the image
        # try cropping from the original input image (if different from input_0)
        im0 = image(self.work_dir + 'input_0.orig.png')
        dx0 = im0.size[0]
        img = image(self.work_dir + 'input_0.png')
        dx = img.size[0]
        if (dx != dx0) :
            z = float(dx0)/float(dx)
            im0.crop((int(x0*z), int(y0*z), int(x1*z), int(y1*z)))
            # resize if cropped image is too big
            if self.input_max_pixels and prod(im0.size) > self.input_max_pixels:
                im0.resize(self.input_max_pixels, method="antialias")
            img = im0
        else :
            img.crop((x0, y0, x1, y1))
	# save result
        img.save(self.work_dir + 'input_0.sel.png')
        return
Esempio n. 3
0
    def wait(self, **kwargs):
        """
        params handling and run redirection
        """
        if 'precision' in kwargs:
            self.cfg['param']['precision'] = kwargs['precision']
        if 'SiftRatio' in kwargs:
            self.cfg['param']['siftratio'] = kwargs['SiftRatio']
        im0 = 'input_0.png'
        if 'rectangle' in kwargs:
            try:
                self.cfg['param']['x0'] = int(kwargs['x0'])
                self.cfg['param']['y0'] = int(kwargs['y0'])
                self.cfg['param']['x1'] = int(kwargs['x1'])
                self.cfg['param']['y1'] = int(kwargs['y1'])
            except ValueError:
                return self.error(errcode='badparams',
                                  errmsg="Incorrect parameters.")
            im0 = 'input_crop.png'

        # no parameter
        http.refresh(self.base_url + 'run?key=%s' % self.key)
        width  = max(image(self.work_dir + im0).size[0],
                     image(self.work_dir + 'input_1.png').size[0])
        height = max(image(self.work_dir + im0).size[1],
                     image(self.work_dir + 'input_1.png').size[1])
        return self.tmpl_out("wait.html", width=width, height=height, im0=im0)
Esempio n. 4
0
 def select_subimage(self, x0, y0, x1, y1):
     """
     cut subimage from original image
     """
     # draw selected rectangle on the image
     imgS = image(self.work_dir + 'input_0.png')
     imgS.draw_line([(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)],
                    color="red")
     imgS.draw_line([(x0 + 1, y0 + 1), (x1 - 1, y0 + 1), (x1 - 1, y1 - 1),
                     (x0 + 1, y1 - 1), (x0 + 1, y0 + 1)],
                    color="white")
     imgS.save(self.work_dir + 'input_0s.png')
     # crop the image
     # try cropping from the original input image
     # (if different from input_1)
     im0 = image(self.work_dir + 'input_0.orig.png')
     dx0 = im0.size[0]
     img = image(self.work_dir + 'input_0.png')
     dx = img.size[0]
     if (dx != dx0):
         z = float(dx0) / float(dx)
         im0.crop((int(x0 * z), int(y0 * z), int(x1 * z), int(y1 * z)))
         # resize if cropped image is too big
         if (self.input_max_pixels
                 and prod(im0.size) > self.input_max_pixels):
             im0.resize(self.input_max_pixels, method="antialias")
         img = im0
     else:
         img.crop((x0, y0, x1, y1))
     # save result
     img.save(self.work_dir + 'input_0.sel.png')
     return
Esempio n. 5
0
 def run_algo(self, s, k, t, stdout=None):
     """
     the core algo runner
     could also be called by a batch processor
     this one needs no parameter
     """
     
     p = self.run_proc(['psf_estim',
                        '-p', self.bin_dir + 'pattern_noise.pgm',
                        '-s', str(s),
                        '-k', str(k),
                        '-d', 'det_out.ppm',
                        '-t', str(t),
                        '-o', 'psf.pgm',
                        'input_0.pgm', 'psf.txt'],
                         stdout=stdout, stderr=stdout)
     self.wait_proc(p)               
    
     im = image(self.work_dir + "psf.pgm")
     # re adjust width and height to avoid visualization interpolation
     width = 600
     height = 600
     # interpolate it by neareset neighbor
     im = im.resize((width, height), "nearest") 
     im.save(self.work_dir + "psf.png")
     
     im = image(self.work_dir + "det_out.ppm")
     im.save(self.work_dir + "det_out.png")
     return
Esempio n. 6
0
 def run_algo(self, stdout=None):
     """
     The core algo runner
     could also be called by a batch processor
     this one needs no parameter
     """
     
     timeout = False
     files = ['input_0_sel', 'detectedraw', 'ppSkin', 'ppRobust', 'ppBoth']
    
     self.wait_proc(self.run_proc(['detect', 'input_0_sel.png', str(self.cfg['param']['layercount']), str(self.cfg['param']['threshold'])],
             stdout=stdout, stderr=stdout), timeout*0.90)
        
     # Resize for visualization (always zoom by at least 2x)
     (sizeX, sizeY) = image(self.work_dir + 'input_0_sel.png').size
     zoomfactor = max(1, int(math.ceil(480.0/max(sizeX, sizeY))))
     
     if zoomfactor > 1:
         (sizeX, sizeY) = (zoomfactor*sizeX, zoomfactor*sizeY)
         
         for filename in files:
             im = image(self.work_dir + filename + '.png')
             im.resize((sizeX, sizeY), method='nearest')
             im.save(self.work_dir + filename + '_zoom.png')
         
         self.cfg['param']['disp_suffix'] = '_zoom.png'
     else:
         self.cfg['param']['disp_suffix'] = '.png'
     
     self.cfg['param']['zoomfactor'] = zoomfactor
     self.cfg['param']['displayheight'] = max(200, sizeY)
     self.cfg['param']['stdout'] = \
         open(self.work_dir + 'stdout.txt', 'r').read()
Esempio n. 7
0
 def params(self, newrun=False, msg=None):
     """
     configure the algo execution
     """
     if newrun:
         old_work_dir = self.work_dir
         old_cfg_param = self.cfg['param']
         self.clone_input()
         self.cfg['param'].update(old_cfg_param)
         self.cfg['param']['norectif'] = True  # No rectif for new run
         self.cfg.save()
         cp_list = ['H_input_0.png', 'H_input_1.png']
         for fname in cp_list:
             shutil.copy(old_work_dir + fname, self.work_dir + fname)
     if 'radius' not in self.cfg['param']:
         self.cfg['param']['radius'] = 9
         self.cfg['param']['alpha'] = 0.9
         self.cfg.save()
     if 'sense' not in self.cfg['param']:
         self.cfg['param']['sense'] = 'r'
     if (image(self.work_dir + 'input_0.png').size !=
             image(self.work_dir + 'input_1.png').size):
         return self.error('badparams',
                           "The images must have the same size")
     return self.tmpl_out("params.html")
Esempio n. 8
0
 def run_algo(self, stdout=None):
     """
     The core algo runner
     could also be called by a batch processor
     this one needs no parameter
     """
     
     timeout = False
     
     # Get image size
     size = image(self.work_dir + 'input_0.png').size
     
     # Run tvrestore
     self.wait_proc(self.run_proc(['tvinpaint', 'mask.png',
         str(self.cfg['param']['lambda']), 'u0.png', 'inpainted.png'],
         stdout=stdout, stderr=stdout), timeout)
     
     zoomfactor = int(max(1, floor(550.0/max(size[0], size[1]))))
     size = (zoomfactor*size[0], zoomfactor*size[1])
     
     for filename in ['input_0', 'composite', 'inpainted']:
         img = image(self.work_dir + filename + '.png')
         img.resize(size, method='nearest')
         img.save(self.work_dir + filename + '_zoom.png')
     
     self.cfg['param']['displayheight'] = max(200, size[1])
     self.cfg['param']['zoomfactor'] = zoomfactor
     self.cfg['param']['zoomwidth'] = size[0]
     self.cfg['param']['zoomheight'] = size[1]
Esempio n. 9
0
 def run_algo(self, stdout=None, timeout=False):
     """
     The core algo runner
     could also be called by a batch processor
     this one needs no parameter
     """
     # Get image size
     size = image(self.work_dir + 'input_0.png').size
     
     # Run eple: EPLE is allowed to iterate just once because of the its speed
     # PLE, even slower, isn't fit for the demo. 
     self.wait_proc(self.run_proc(['inpaintEPLE', 'u0.png', 'mask.png',
         'inpainted.png', str(self.cfg['param']['iteration']) ], stdout=stdout, stderr=stdout), timeout)
     
     zoomfactor = int(max(1, floor(550.0/max(size[0], size[1]))))
     size = (zoomfactor*size[0], zoomfactor*size[1])
     
     for filename in ['input_0', 'composite', 'inpainted']:
         img = image(self.work_dir + filename + '.png')
         img.resize(size, method='nearest')
         img.save(self.work_dir + filename + '_zoom.png')
     
     self.cfg['param']['displayheight'] = max(200, size[1])
     self.cfg['param']['zoomfactor'] = zoomfactor
     self.cfg['param']['zoomwidth'] = size[0]
     self.cfg['param']['zoomheight'] = size[1]
     self.cfg['param']['stdout'] = \
         open(self.work_dir + 'stdout.txt', 'r').read()
Esempio n. 10
0
    def run_algo(self, s, k, t, stdout=None):
        """
        the core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        p = self.run_proc([
            'psf_estim', '-p', self.bin_dir + 'pattern_noise.pgm', '-s',
            str(s), '-k',
            str(k), '-d', 'det_out.ppm', '-t',
            str(t), '-o', 'psf.pgm', 'input_0.pgm', 'psf.txt'
        ],
                          stdout=stdout,
                          stderr=stdout)
        self.wait_proc(p)

        im = image(self.work_dir + "psf.pgm")
        # re adjust width and height to avoid visualization interpolation
        width = 600
        height = 600
        # interpolate it by neareset neighbor
        im = im.resize((width, height), "nearest")
        im.save(self.work_dir + "psf.png")

        im = image(self.work_dir + "det_out.ppm")
        im.save(self.work_dir + "det_out.png")
        return
Esempio n. 11
0
    def run_algo(self, stdout=None):
        """
        The core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        timeout = False
        pattern = self.cfg['param']['pattern']

        # Mosaic image
        self.wait_proc(
            self.run_proc(
                ['mosaic', '-p', pattern, 'input_0_sel.png', 'mosaiced.png'],
                stdout=stdout,
                stderr=stdout), timeout * 0.2)

        # Demosaic image
        self.wait_proc([
            self.run_proc(
                ['dmzhangwu', '-p', pattern, 'mosaiced.png', 'dmzhangwu.png'],
                stdout=stdout,
                stderr=stdout),
            self.run_proc(
                ['dmbilinear', '-p', pattern, 'mosaiced.png', 'bilinear.png'],
                stdout=stdout,
                stderr=stdout)
        ], timeout * 0.6)

        # Compute image differences
        self.wait_proc([
            self.run_proc([
                'imdiff', 'input_0_sel.png', 'dmzhangwu.png',
                'diffdmzhangwu.png'
            ],
                          stdout=stdout,
                          stderr=stdout),
            self.run_proc([
                'imdiff', 'input_0_sel.png', 'bilinear.png', 'diffbilinear.png'
            ],
                          stdout=stdout,
                          stderr=stdout)
        ], timeout * 0.2)

        # Resize for visualization (new size of the smallest dimension = 200)
        (sizeX, sizeY) = image(self.work_dir + 'input_0_sel.png').size
        zoomfactor = max(1, int(ceil(200.0 / min(sizeX, sizeY))))
        (sizeX, sizeY) = (zoomfactor * sizeX, zoomfactor * sizeY)

        for filename in [
                'input_0_sel', 'mosaiced', 'dmzhangwu', 'bilinear',
                'diffdmzhangwu', 'diffbilinear'
        ]:
            im = image(self.work_dir + filename + '.png')
            im.resize((sizeX, sizeY), method='nearest')
            im.save(self.work_dir + filename + '_zoom.png')

        self.cfg['param']['displayheight'] = sizeY
        self.cfg['param']['zoomfactor'] = zoomfactor
Esempio n. 12
0
    def result(self):
        """
        display the algo results
        """
        print "Display results"

        # read the parameters
        sigma = self.cfg['param']['sigma']
        try:
            x0 = self.cfg['param']['x0']
        except KeyError:
            x0 = None
        try:
            y0 = self.cfg['param']['y0']
        except KeyError:
            y0 = None
        try:
            x1 = self.cfg['param']['x1']
        except KeyError:
            x1 = None
        try:
            y1 = self.cfg['param']['y1']
        except KeyError:
            y1 = None

        (sizeX, sizeY) = image(self.work_dir + 'input_0.png').size
        # Resize for visualization (new size of the smallest dimension = 200)
        zoom_factor = None
        if (sizeX < 200) or (sizeY < 200):
            if sizeX > sizeY:
                zoom_factor = int(ceil(200.0/sizeY))
            else:
                zoom_factor = int(ceil(200.0/sizeX))

            sizeX = sizeX*zoom_factor
            sizeY = sizeY*zoom_factor

            im = image(self.work_dir + 'input_0.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'input_0_zoom.png')
            
            im = image(self.work_dir + 'input_1.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'input_1_zoom.png')
            
            im = image(self.work_dir + 'output_1.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'output_1_zoom.png')
            
            im = image(self.work_dir + 'output_2.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'output_2_zoom.png')
            
        return self.tmpl_out("result.html", sigma=sigma,
                             x0=x0, y0=y0, x1=x1, y1=y1,
                             sizeY=sizeY, zoom_factor=zoom_factor)
Esempio n. 13
0
    def result(self):
        """
        display the algo results
        """

        # read the parameters
        scale = self.cfg['param']['scale']
        try:
            x0 = self.cfg['param']['x0']
        except KeyError:
            x0 = None
        try:
            y0 = self.cfg['param']['y0']
        except KeyError:
            y0 = None
        try:
            x1 = self.cfg['param']['x1']
        except KeyError:
            x1 = None
        try:
            y1 = self.cfg['param']['y1']
        except KeyError:
            y1 = None

        (sizeX, sizeY) = image(self.work_dir + 'input_0.sel.png').size
        # Resize for visualization (new size of the smallest dimension = 200)
        zoom_factor = None
        if (sizeX < 200) or (sizeY < 200):
            if sizeX > sizeY:
                zoom_factor = int(ceil(200.0 / sizeY))
            else:
                zoom_factor = int(ceil(200.0 / sizeX))

            sizeX = sizeX * zoom_factor
            sizeY = sizeY * zoom_factor

            im = image(self.work_dir + 'input_0.sel.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'input_0_zoom.sel.png')

            im = image(self.work_dir + 'cartoon.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'cartoon_zoom.png')

            im = image(self.work_dir + 'texture.png')
            im.resize((sizeX, sizeY), method="pixeldup")
            im.save(self.work_dir + 'texture_zoom.png')

        return self.tmpl_out("result.html",
                             scale=scale,
                             x0=x0,
                             y0=y0,
                             x1=x1,
                             y1=y1,
                             sizeY=sizeY,
                             zoom_factor=zoom_factor)
Esempio n. 14
0
 def result(self, error_nomatch=None):
     """
     display the algo results
     """
     height = max(image(self.work_dir + 'input_0.png').size[1],
                  image(self.work_dir + 'input_1.png').size[1])
     if error_nomatch:
         return self.tmpl_out("result_nomatch.html", height=height)
     else:
         return self.tmpl_out("result.html", height=height)
Esempio n. 15
0
 def params(self, newrun=False, msg=None):
     """
     configure the algo execution
     """
     if newrun:
         self.clone_input()
     if (image(self.work_dir + 'input_0.png').size
         != image(self.work_dir + 'input_1.png').size):
         return self.error('badparams',
                           "The images must have the same size")
     return self.tmpl_out("params.html")
Esempio n. 16
0
 def result(self, public=None):
     """
     display the algo results
     """
     resultHeight = image(self.work_dir + 'input_0_selection.png').size[1]
     imageHeightResized = min (600, resultHeight)
     resultHeight = max(200, resultHeight)
     return self.tmpl_out("result.html", height=resultHeight, \
                          heightImageDisplay=imageHeightResized, \
                          width=image(self.work_dir\
                                        +'input_0_selection.png').size[0])
Esempio n. 17
0
 def params(self, newrun=False, msg=None):
     """
     configure the algo execution
     """
     if newrun:
         self.clone_input()
     width  = max(image(self.work_dir + 'input_0.png').size[0],
                  image(self.work_dir + 'input_1.png').size[0])
     height = max(image(self.work_dir + 'input_0.png').size[1],
                  image(self.work_dir + 'input_1.png').size[1])
     return self.tmpl_out("params.html", width=width, height=height)
Esempio n. 18
0
    def run_algo(self, stdout=None):
        """
        The core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        timeout = False
        pattern = self.cfg["param"]["pattern"]

        # Mosaic image
        self.wait_proc(
            self.run_proc(["mosaic", "-p", pattern, "input_0_sel.png", "mosaiced.png"], stdout=stdout, stderr=stdout),
            timeout * 0.2,
        )

        # Demosaic image
        self.wait_proc(
            [
                self.run_proc(
                    ["dmzhangwu", "-p", pattern, "mosaiced.png", "dmzhangwu.png"], stdout=stdout, stderr=stdout
                ),
                self.run_proc(
                    ["dmbilinear", "-p", pattern, "mosaiced.png", "bilinear.png"], stdout=stdout, stderr=stdout
                ),
            ],
            timeout * 0.6,
        )

        # Compute image differences
        self.wait_proc(
            [
                self.run_proc(
                    ["imdiff", "input_0_sel.png", "dmzhangwu.png", "diffdmzhangwu.png"], stdout=stdout, stderr=stdout
                ),
                self.run_proc(
                    ["imdiff", "input_0_sel.png", "bilinear.png", "diffbilinear.png"], stdout=stdout, stderr=stdout
                ),
            ],
            timeout * 0.2,
        )

        # Resize for visualization (new size of the smallest dimension = 200)
        (sizeX, sizeY) = image(self.work_dir + "input_0_sel.png").size
        zoomfactor = max(1, int(ceil(200.0 / min(sizeX, sizeY))))
        (sizeX, sizeY) = (zoomfactor * sizeX, zoomfactor * sizeY)

        for filename in ["input_0_sel", "mosaiced", "dmzhangwu", "bilinear", "diffdmzhangwu", "diffbilinear"]:
            im = image(self.work_dir + filename + ".png")
            im.resize((sizeX, sizeY), method="nearest")
            im.save(self.work_dir + filename + "_zoom.png")

        self.cfg["param"]["displayheight"] = sizeY
        self.cfg["param"]["zoomfactor"] = zoomfactor
Esempio n. 19
0
 def result(self, public=None):
     """
     display the algo results
     """
     resultHeight = image(self.work_dir + 'input_0.png').size[1]
     imageHeightResized = min(600, resultHeight)
     resultHeight = max(200, resultHeight)
     return self.tmpl_out("result.html", height=resultHeight, \
                          heightImageDisplay=imageHeightResized, \
                          width=image(self.work_dir\
                                        +'input_0.png').size[0])
Esempio n. 20
0
    def result(self):
        """
        display the algo results
        """
        # read the parameters
        L = self.cfg['param']['l']
        s = self.cfg['param']['s']
        sizeX = image(self.work_dir + 'input_0.png').size[0]
        sizeY = max(
            image(self.work_dir + 'input_0.png').size[1], 3 * 128 + 4 * 20)

        return self.tmpl_out("result.html", L=L, s=s, sizeX=sizeX, sizeY=sizeY)
Esempio n. 21
0
    def run_algo(self, r, stdout=None, timeout=False):
        """
        the core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        #color correction of R, G and B channels
        option = 1
        p1 = self.run_proc(['localcolorcorrection', 'input_0.sel.png', 
                            'output_1.png', str(r), str(option)], 
                            stdout=None, stderr=None)

        #color correction of intensity channel (keep R/G/B ratios)
        option = 2
        p2 = self.run_proc(['localcolorcorrection', 'input_0.sel.png', 
                           'output_2.png', str(r), str(option)], 
                           stdout=None, stderr=None)

        #color correction of Y channel (use YPbPr color space)
        option = 3
        p3 = self.run_proc(['localcolorcorrection', 'input_0.sel.png', 
                           'output_3.png', str(r), str(option)], 
                           stdout=None, stderr=None)

        #color correction of L channel (use HSL color space)
        option = 4
        p4 = self.run_proc(['localcolorcorrection', 'input_0.sel.png', 
                           'output_4.png', str(r), str(option)], 
                           stdout=None, stderr=None)

        self.wait_proc([p1, p2, p3, p4], timeout)

        #Compute histograms of images
        im1 = image(self.work_dir + 'input_0.sel.png')
        im2 = image(self.work_dir + 'output_1.png')
        im3 = image(self.work_dir + 'output_2.png')
        im4 = image(self.work_dir + 'output_3.png')
        im5 = image(self.work_dir + 'output_4.png')
        #compute maximum of histogram values for the input image
        maxH = im1.max_histogram(option="all")
        #draw all the histograms using the same reference maximum
        im1.histogram(option="all", maxRef=maxH)
        im1.save(self.work_dir + 'input_0_hist.png')
        im2.histogram(option="all", maxRef=maxH)
        im2.save(self.work_dir + 'output_1_hist.png')
        im3.histogram(option="all", maxRef=maxH)
        im3.save(self.work_dir + 'output_2_hist.png')
        im4.histogram(option="all", maxRef=maxH)
        im4.save(self.work_dir + 'output_3_hist.png')
        im5.histogram(option="all", maxRef=maxH)
        im5.save(self.work_dir + 'output_4_hist.png')
Esempio n. 22
0
    def result(self):
        """
        display the algo results
        """
        # read the parameters
        L = self.cfg['param']['l']
        s = self.cfg['param']['s']
        sizeX = image(self.work_dir + 'input_0.png').size[0]
        sizeY = max(image(self.work_dir + 'input_0.png').size[1],
                    3 * 128 + 4 * 20)

        return self.tmpl_out("result.html", L=L, s=s,
                             sizeX=sizeX, sizeY=sizeY)
Esempio n. 23
0
 def grid(self, stepG, scaleR, action=None, x=0, y=0):
     """
     handle the grid drawing and selection
     """
     if action == 'run':
         # use the whole image
         img = image(self.work_dir + 'input_0.png')
         img.save(self.work_dir + 'input' + self.input_ext)
         img.save(self.work_dir + 'input.png')
         # go to the wait page, with the key and scale
         stepG = 0
         http.redir_303(self.base_url
                        + "wait?key=%s&scaleR=%s&step=%s" 
                        % (self.key, scaleR, stepG))
         return
     elif action == 'redraw':
         # draw the grid
         step = int(stepG)
         if 0 < step:
             img = image(self.work_dir + 'input_0.png')
             img.draw_grid(step)
             img.save(self.work_dir + 'input_grid.png')
             grid = True
         else:
             grid = False
         return self.tmpl_out("params.html", step=stepG,
                              grid=grid, scale_r=float(scaleR))
     else:
         # use a part of the image
         x = int(x)
         y = int(y)
         # get the step used to draw the grid
         step = int(stepG)
         assert step > 0
         # cut the image section
         img = image(self.work_dir + 'input_0.png')
         x0 = (x / step) * step
         y0 = (y / step) * step
         x1 = min(img.size[0], x0 + step)
         y1 = min(img.size[1], y0 + step)
         img.crop((x0, y0, x1, y1))
         # zoom and save image
         img.resize((400, 400), method="nearest")
         img.save(self.work_dir + 'input' + self.input_ext)
         img.save(self.work_dir + 'input.png')
         # go to the wait page, with the key and scale
         http.redir_303(self.base_url
                        + "wait?key=%s&scaleR=%s&step=%s" 
                        % (self.key, scaleR, stepG))
         return
Esempio n. 24
0
    def result(self):
        """
        display the algo results
        """
        # read the parameters
        s1 = self.cfg['param']['s1']
        s2 = self.cfg['param']['s2']
        sizeY = image(self.work_dir + 'input_0.png').size[1]
        sizeYhist = image(self.work_dir + 'input_0_hist.png').size[1]
        # add 20 pixels to the histogram size to take margin into account
        sizeYmax = max(sizeY, sizeYhist+60)

        return self.tmpl_out("result.html", s1=s1, s2=s2,
                             sizeY="%i" % sizeYmax)
Esempio n. 25
0
    def result(self):
        """
        display the algo results
        """
        return self.tmpl_out("result.html",
			     useOriginal=os.path.isfile(self.work_dir + 'input_0s.png'),
                             sizeY="%i" % image(self.work_dir + 'input.png').size[1])
Esempio n. 26
0
    def wait(self, **kwargs):
        """
        params handling and run redirection
        """
        if 'sense' in kwargs:
            self.cfg['param']['sense'] = kwargs['sense']
            self.cfg.save()
        if 'norectif' in kwargs:
            self.cfg['param']['norectif'] = True
            self.cfg.save()
        try:
            if 'dmin' in kwargs:  # Check integer values
                dmin = int(kwargs['dmin'])
                dmax = int(kwargs['dmax'])
                self.cfg['param']['dmin'] = dmin
                self.cfg['param']['dmax'] = dmax
                self.cfg.save()
        except ValueError:
            return self.error(
                errcode='badparams',
                errmsg="The disparity range parameters must be integers.")

        http.refresh(self.base_url + 'run?key=%s' % self.key)
        return self.tmpl_out("wait.html",
                             height=image(self.work_dir +
                                          'input_0.png').size[1])
Esempio n. 27
0
 def result(self, public=None):
     """
     display the algo results
     """
     return self.tmpl_out("result.html",
                          height=image(self.work_dir
                                       + 'input_0.png').size[1])
Esempio n. 28
0
    def input_select(self, **kwargs):
        """
        use the selected available input images
        """
        print("ENTERING input_select")
        self.new_key()
        self.init_cfg()
        print("key = " + self.key)
        # kwargs contains input_id.x and input_id.y
        input_id = kwargs.keys()[0].split('.')[0]
        assert input_id == kwargs.keys()[1].split('.')[0]
        # get the images
        input_dict = config.file_dict(self.input_dir)
        idir = self.input_dir + input_dict[input_id]['subdir'] + '/'
        fnames = "a.png b.png".split()
        for f in fnames:
            shutil.copy(idir + f, self.work_dir + f)
        hastruth = os.path.isfile(idir + "t.tiff")
        self.cfg['meta']['hastruth'] = hastruth
        if (hastruth):
            shutil.copy(idir + "t.tiff", self.work_dir + "t.tiff")
            shutil.copy(idir + "t.png", self.work_dir + "t.png")

        #fnames = input_dict[input_id]['files'].split()
        #for i in range(len(fnames)):
        #    shutil.copy(self.input_dir + fnames[i],
        #                self.work_dir + 'input_%i' % i)
        #msg = self.process_input()
        self.log("input selected : %s" % input_id)
        self.cfg['meta']['original'] = False
        self.cfg['meta']['height'] = image(self.work_dir + '/a.png').size[1]
        self.cfg.save()
        # jump to the params page
        return self.params(msg="(no message)", key=self.key)
Esempio n. 29
0
    def set_default_gui_state(self):
        img = image(self.work_dir + "input_0.png")
        w = img.size[0]
        h = img.size[1]
        m = 50
        ow = w + 2 * m
        oh = h + 2 * m

        self.cfg["param"]["m"] = m
        self.cfg["param"]["w"] = w
        self.cfg["param"]["h"] = h
        self.cfg["param"]["ow"] = ow
        self.cfg["param"]["oh"] = oh
        self.cfg["param"]["c"] = str(
            [
                [(0 + m + int(w * 0.4)), 0 + m + int(h * 0.4)],
                [w - 1 + m, 0 + m],
                [w - 1 + m, h - 1 + m],
                [0 + m, h - 1 + m],
            ]
        )
        self.cfg["param"]["p"] = str([[0, 0], [w - 1, 0], [w - 1, h - 1], [0, h - 1]])
        self.cfg["param"]["hit"] = -1
        self.cfg["param"]["state"] = "plain"
        return
Esempio n. 30
0
    def index(self):
        """
        demo presentation and input menu
        """
        #print("ENTERING index")
        tn_size = 192
        # read the input index as a dict
        inputd = config.file_dict(self.input_dir)
        #print(inputd)
        for (input_id, input_info) in inputd.items():
            tn_fname = [thumbnail(self.input_dir + \
                                     input_info['subdir'] \
                                     + '/i0000.png',(tn_size,tn_size))]
            inputd[input_id]['hastruth'] = os.path.isfile(
                self.input_dir + input_info['subdir'] + '/a.png')
            inputd[input_id]['height'] = image(self.input_dir +
                                               input_info['subdir'] +
                                               '/i0000.png').size[1]
            inputd[input_id]['baseinput'] = \
                        self.input_url + input_info['subdir'] + '/'
            inputd[input_id]['url'] = [
                self.input_url + input_info['subdir'] + '/' +
                os.path.basename(f) for f in ["i0000.png"]
            ]
            inputd[input_id]['tn_url'] = [
                self.input_url + input_info['subdir'] + '/' +
                os.path.basename(f) for f in tn_fname
            ]

        return self.tmpl_out("input.html", inputd=inputd)
Esempio n. 31
0
    def input_select(self, **kwargs):
        """
        use the selected available input images
        """
        #print("ENTERING input_select")
        self.new_key()
        self.init_cfg()
        #print("key = " + self.key)
        # kwargs contains input_id.x and input_id.y
        input_id = kwargs.keys()[0].split('.')[0]
        assert input_id == kwargs.keys()[1].split('.')[0]
        # get the images
        input_dict = config.file_dict(self.input_dir)
        idir = self.input_dir + input_dict[input_id]['subdir'] + '/'
        #print("idir = " + idir)
        fnames = [os.path.basename(f) for f in glob.glob(idir + 'i????.png')]
        for f in fnames:
            shutil.copy(idir + f, self.work_dir + f)
        hastruth = os.path.isfile(idir + "a.png")
        self.cfg['meta']['hastruth'] = hastruth
        self.cfg['meta']['maxframes'] = len(fnames)
        if (hastruth):
            shutil.copy(idir + "a.png", self.work_dir + "a.png")

        self.log("input selected : %s" % input_id)
        self.cfg['meta']['original'] = False
        self.cfg['meta']['height'] = image(self.work_dir +
                                           '/i0000.png').size[1]
        self.cfg.save()
        # jump to the params page
        return self.params(msg="(no message)", key=self.key)
Esempio n. 32
0
    def result(self):
        """
        display the algo results
        """
        # read the parameters
        s1 = self.cfg['param']['s1']
        s2 = self.cfg['param']['s2']
        sizeY = image(self.work_dir + 'input_0.png').size[1]
        sizeYhist = image(self.work_dir + 'input_0_hist.png').size[1]
        # add 20 pixels to the histogram size to take margin into account
        sizeYmax = max(sizeY, sizeYhist + 60)

        return self.tmpl_out("result.html",
                             s1=s1,
                             s2=s2,
                             sizeY="%i" % sizeYmax)
Esempio n. 33
0
    def result(self):
        """
        display the algo results
        """
        print "Display results"

        # read the parameters
        sigma = self.cfg['param']['sigma']

        try:
            x0 = self.cfg['param']['x0']
        except KeyError:
            x0 = None
        try:
            y0 = self.cfg['param']['y0']
        except KeyError:
            y0 = None
        try:
            x1 = self.cfg['param']['x1']
        except KeyError:
            x1 = None
        try:
            y1 = self.cfg['param']['y1']
        except KeyError:
            y1 = None

        (sizeX, sizeY) = image(self.work_dir + 'input_0.sel.png').size
        zoom_factor = None
        return self.tmpl_out("result.html", sigma=sigma, \
                             x0=x0, y0=y0, x1=x1, y1=y1, \
                             sizeX=sizeX, sizeY=sizeY, \
                             zoom_factor=zoom_factor)
Esempio n. 34
0
 def result(self, public=None):
     """
     display the algo results
     """
     return self.tmpl_out("result.html",
                          height=image(self.work_dir +
                                       'input_0.png').size[1])
Esempio n. 35
0
    def result(self):
        """
        display the algo results
        """
        sizeY = image(self.work_dir + 'input_0.png').size[1]

        return self.tmpl_out("result.html", sizeY=sizeY)
Esempio n. 36
0
    def run_algo(self):
        """Core algorithm runner, it could also be called by a batch processor,
           this one needs no parameter.
        """

        # run LSD
        p = self.run_proc(['lsd', '-P', 'output.eps', '-S', 'output.svg',
                           'input_0_selection.pgm', 'output.txt'])
        self.wait_proc(p)

        # convert the EPS result into a PNG image
        try:
            p = self.run_proc(['/usr/bin/gs', '-dNOPAUSE', '-dBATCH',
                               '-sDEVICE=pnggray', '-dGraphicsAlphaBits=4',
                               '-r72','-dEPSCrop', '-sOutputFile=output.png',
                               'output.eps'])
            self.wait_proc(p)
            im = image(self.work_dir + "output.png")
            im.convert('1x8i')
            im.invert()
            im.save(self.work_dir + "output-inv.png")
        except Exception:
            self.log("eps->png conversion failed,"
                     + " GS is probably missing on this system")

        return
Esempio n. 37
0
    def input_select(self, **kwargs):
        """
        use the selected available input images
        """
        print("ENTERING input_select")
        self.new_key()
        self.init_cfg()
        print("key = " + self.key)
        # kwargs contains input_id.x and input_id.y
        input_id = kwargs.keys()[0].split('.')[0]
        assert input_id == kwargs.keys()[1].split('.')[0]
        # get the images
        input_dict = config.file_dict(self.input_dir)
        idir = self.input_dir + input_dict[input_id]['subdir'] + '/'
        print("idir = " + idir)
        fnames = [os.path.basename(f) for f in glob.glob(idir + 'i????.png')]
        for f in fnames:
            shutil.copy(idir + f, self.work_dir + f)
        hastruth = os.path.isfile(idir + "a.png")
        self.cfg['meta']['hastruth'] = hastruth
        self.cfg['meta']['maxframes'] = len(fnames)
        if (hastruth):
            shutil.copy(idir + "a.png", self.work_dir + "a.png")

        self.log("input selected : %s" % input_id)
        self.cfg['meta']['original'] = False
        self.cfg['meta']['height'] = image(self.work_dir + '/i0000.png').size[1]
        self.cfg.save()
        # jump to the params page
        return self.params(msg="(no message)", key=self.key)
Esempio n. 38
0
    def run_algo(self, stdout=None):
        """
        The core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """

        timeout = False
        omega_string = str(self.cfg['param']['omega'])

        if omega_string == 'G':
            omega_string += ':' + str(self.cfg['param']['gaussianstd'])

        if self.cfg['param']['method'] == 'poly':
            method_string = 'poly:' + str(self.cfg['param']['degree'])
        else:
            method_string = 'interp:' + str(self.cfg['param']['numlevels'])

        self.wait_proc([
            self.run_proc([
                'ace', '-a',
                str(self.cfg['param']['alpha']), '-w' + omega_string,
                '-m' + method_string, 'input_0_sel.png', 'ace.png'
            ],
                          stdout=stdout,
                          stderr=stdout),
            self.run_proc(['histeq', 'input_0_sel.png', 'he.png'],
                          stdout=None,
                          stderr=stdout)
        ], timeout)

        self.cfg['param']['displayheight'] = max(200, \
            image(self.work_dir + 'input_0_sel.png').size[1])
        self.cfg.save()
Esempio n. 39
0
 def result(self):
     """
     display the algo results
     """
     self.cfg['meta']['height'] = image(self.work_dir +
                                        '/i0000.png').size[1]
     return self.tmpl_out("result.html")
Esempio n. 40
0
    def wait(self, **kwargs):
        """
        params handling and run redirection
        """
        if 'rectif' in kwargs:
            self.cfg['param']['rectif'] = True
        if 'valK' in kwargs:
            self.autoK = False
            self.cfg['param']['k'] = \
                str(min(self.Kmax, float(kwargs['valK'])))
        if 'autoK' in kwargs and kwargs['autoK'] == 'True':
            self.autoK = True
            self.cfg['param']['k'] = 'auto'
        if 'valL' in kwargs:
            self.autoL = False
            self.cfg['param']['lambda'] = \
                str(min(self.Lmax, float(kwargs['valL'])))
        if 'autoL' in kwargs and kwargs['autoL'] == 'True':
            self.autoL = True
            self.cfg['param']['lambda'] = 'auto'
        if 'dmin' in kwargs: # Check integer values
            dmin = int(kwargs['dmin'])
            dmax = int(kwargs['dmax'])
            self.cfg['param']['dmin'] = dmin
            self.cfg['param']['dmax'] = dmax
        self.cfg.save()

        http.refresh(self.base_url + 'run?key=%s' % self.key)
        return self.tmpl_out("wait.html",
                             height=image(self.work_dir
                                          + 'input_0.png').size[1])
Esempio n. 41
0
    def result(self):
        """
        display the algo results
        """
        print "Display results"

        # read the parameters
        sigma = self.cfg['param']['sigma']

        try:
            x0 = self.cfg['param']['x0']
        except KeyError:
            x0 = None
        try:
            y0 = self.cfg['param']['y0']
        except KeyError:
            y0 = None
        try:
            x1 = self.cfg['param']['x1']
        except KeyError:
            x1 = None
        try:
            y1 = self.cfg['param']['y1']
        except KeyError:
            y1 = None

        (sizeX, sizeY) = image(self.work_dir + 'input_0.sel.png').size
        zoom_factor = None
        return self.tmpl_out("result.html", sigma=sigma, \
                             x0=x0, y0=y0, x1=x1, y1=y1, \
                             sizeX=sizeX, sizeY=sizeY, \
                             zoom_factor=zoom_factor)
Esempio n. 42
0
    def index(self):
        """
        demo presentation and input menu
        """
        print("ENTERING index")
        tn_size = 192
        # read the input index as a dict
        inputd = config.file_dict(self.input_dir)
        print(inputd)
        for (input_id, input_info) in inputd.items():
            fname = ["a.png", "b.png", "t.png"]
            tn_fname = [thumbnail(self.input_dir + \
                 input_info['subdir'] \
                           + '/a.png',(tn_size,tn_size))]
            inputd[input_id]['hastruth'] = os.path.isfile(
                self.input_dir + input_info['subdir']+'/t.tiff')
            inputd[input_id]['height'] = image(self.input_dir
                       + input_info['subdir'] + '/a.png').size[1]
            inputd[input_id]['baseinput'] = \
                self.input_url + input_info['subdir'] + '/'
            inputd[input_id]['url'] = [self.input_url
                            + input_info['subdir']
                    + '/' + os.path.basename(f)
                  for f in fname]
            inputd[input_id]['tn_url'] = [self.input_url
                         + input_info['subdir']
                         + '/'
                         + os.path.basename(f)
                 for f in tn_fname]

        return self.tmpl_out("input.html", inputd=inputd)
Esempio n. 43
0
    def result(self):
        """
        display the algo results
        """
        sizeY=image(self.work_dir + 'input_0.png').size[1]

        return self.tmpl_out("result.html", sizeY=sizeY)
Esempio n. 44
0
    def input_select(self, **kwargs):
        """
        use the selected available input images
        """
        print("ENTERING input_select")
        self.new_key()
        self.init_cfg()
        print("key = " + self.key)
        # kwargs contains input_id.x and input_id.y
        input_id = kwargs.keys()[0].split('.')[0]
        assert input_id == kwargs.keys()[1].split('.')[0]
        # get the images
        input_dict = config.file_dict(self.input_dir)
        idir = self.input_dir + input_dict[input_id]['subdir'] + '/'
        fnames = "a.png b.png".split()
        for f in fnames:
            shutil.copy(idir + f, self.work_dir + f)
        hastruth = os.path.isfile(idir + "t.tiff")
        self.cfg['meta']['hastruth'] = hastruth
        if (hastruth):
            shutil.copy(idir + "t.tiff", self.work_dir + "t.tiff")
            shutil.copy(idir + "t.png", self.work_dir + "t.png")

        #fnames = input_dict[input_id]['files'].split()
        #for i in range(len(fnames)):
        #    shutil.copy(self.input_dir + fnames[i],
        #                self.work_dir + 'input_%i' % i)
        #msg = self.process_input()
        self.log("input selected : %s" % input_id)
        self.cfg['meta']['original'] = False
        self.cfg['meta']['height'] = image(self.work_dir + '/a.png').size[1]
        self.cfg.save()
        # jump to the params page
        return self.params(msg="(no message)", key=self.key)
Esempio n. 45
0
 def _rectify(self, stdout):
     """
     rectify input images
     """
     start_time = time.time()
     end_time = start_time + self.timeout/3
     (w, h) = image(self.work_dir+'input_0.png').size
     pairs = self.work_dir+'input_0.png_input_1.png_pairs.txt'
     pairs_good = self.work_dir+'input_0.png_input_1.png_pairs_orsa.txt'
     try:
         p = self.run_proc(['sift',
                            self.work_dir+'input_0.png',
                            self.work_dir+'input_1.png',
                            pairs],
                           stdout=stdout, stderr=stdout)
         self.wait_proc(p, timeout=end_time-start_time)
         start_time = time.time()
         p = self.run_proc(['orsa', str(w), str(h),
                            pairs, pairs_good, '500', '1', '0', '2', '0'],
                           stdout=stdout, stderr=stdout)
         self.wait_proc(p, timeout=end_time-start_time)
         start_time = time.time()
         outRect = open(self.work_dir+'rect.txt','w')
         p = self.run_proc(['rectify', pairs_good, str(w), str(h),
                            self.work_dir+'input_0.png_h.txt',
                            self.work_dir+'input_1.png_h.txt'],
                           stdout=outRect, stderr=outRect)
         self.wait_proc(p, timeout=end_time-start_time)
         start_time = time.time()
         p = []
         p.append(self.run_proc(['homography', '-f',
                                 self.work_dir+'input_0.png',
                                 self.work_dir+'input_0.png_h.txt',
                                 self.work_dir+'H_input_0.png'],
                                stdout=outRect, stderr=outRect))
         p.append(self.run_proc(['homography', '-f',
                                 self.work_dir+'input_1.png',
                                 self.work_dir+'input_1.png_h.txt',
                                 self.work_dir+'H_input_1.png'],
                                stdout=outRect, stderr=outRect))
         self.wait_proc(p, timeout=end_time-start_time)
     except RuntimeError:
         if 0 != p.returncode:
             stdout.close()
             raise NoMatchError
         else:
             raise
     outRect.close()
     outRect = open(self.work_dir+'rect.txt','r')
     lines = outRect.readlines()
     for line in lines:
         stdout.write(line)
         words = line.split()
         if words[0] == "Disparity:":
             dmin = words[1]
             dmax = words[2]
     outRect.close()
     os.unlink(self.work_dir+'rect.txt')
     stdout.flush()
     return (dmin, dmax)
Esempio n. 46
0
    def run_algo(self):
        """Core algorithm runner, it could also be called by a batch processor,
           this one needs no parameter.
        """

        # run LSD
        p = self.run_proc([
            'lsd', '-P', 'output.eps', '-S', 'output.svg',
            'input_0_selection.pgm', 'output.txt'
        ])
        self.wait_proc(p)

        # convert the EPS result into a PNG image
        try:
            p = self.run_proc([
                '/usr/bin/gs', '-dNOPAUSE', '-dBATCH', '-sDEVICE=pnggray',
                '-dGraphicsAlphaBits=4', '-r72', '-dEPSCrop',
                '-sOutputFile=output.png', 'output.eps'
            ])
            self.wait_proc(p)
            im = image(self.work_dir + "output.png")
            im.convert('1x8i')
            im.invert()
            im.save(self.work_dir + "output-inv.png")
        except Exception:
            self.log("eps->png conversion failed," +
                     " GS is probably missing on this system")

        return
Esempio n. 47
0
def scan_for_faces(img):
    print("Scanning " + img + " for faces.") 
    global df_faces
    try:
        time.sleep(3)
        print("Creating image")
        this_image = image(img)
        print("Getting faces")
        faces = this_image.get_image_faces()
        print("Image: " + img)
        print("Number of faces: " + str(len(faces)))
        df_faces = df_faces.append(pd.DataFrame({
            'img':img,
            'left':[f.left for f in faces],
            'top':[f.top for f in faces],
            'width':[f.width for f in faces],
            'height':[f.height for f in faces],
            'age':[f.age for f in faces],
            'gender':[f.gender for f in faces],
            'smile':[f.smile for f in faces],
            'emotion':[f.emotion for f in faces]            
        }))
        return True
    except:
        return False
Esempio n. 48
0
 def result(self):
     """
     display the algo results
     """
     return self.tmpl_out("result.html",
                          height=image(self.work_dir
                                       + 'output.png').size[1])
Esempio n. 49
0
    def run_algo(self, params=None):
        """
        the core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """
        self.cfg['param']['sizex'] = image(self.work_dir + \
                                           'input_0.png').size[0]
        self.cfg['param']['sizey'] = image(self.work_dir + \
                                            'input_0.png').size[1]
      
        commandargs = ['LUTBasedNSDistanceTransform']

        print(type(self.cfg['param']['distance_def']), \
                   self.cfg['param']['distance_def'])

        if self.cfg['param']['centered']:
            commandargs += ['-c']

        if self.cfg['param']['distance_def'] == 'd4':
            commandargs += ['-4']
        elif self.cfg['param']['distance_def'] == 'd8':
            commandargs += ['-8']
        elif self.cfg['param']['distance_def'] == 'ratio':
            commandargs += ['-r', str(self.cfg['param']['ratio'])]
        elif self.cfg['param']['distance_def'] == 'sequence':
            commandargs += ['-s', str(self.cfg['param']['sequence'])]

        commandargs += ['-f', 'input_0.png']
        commandargs += ['-t', 'png']
        f = open(self.work_dir+"resu_r.png", "w")
        self.runCommand(commandargs, stdOut=f, stdErr=subprocess.PIPE, \
                        comp='> resu_r.png')
        f.close()


        commandargs = ['convert.sh', '-normalize', 'resu_r.png', \
                      'resu_n.jpg']
        self.runCommand(commandargs, stdErr=subprocess.PIPE)


        fcommands = open(self.work_dir+"commands.txt", "w")
        fcommands.write(self.commands)
        fcommands.close()

        return
Esempio n. 50
0
 def result(self, public=None):
     """
     display the algo results
     SHOULD be defined in the derived classes, to check the parameters
     """
     return self.tmpl_out('result.html',
         displaysize=image(self.work_dir + 'output_0.bmp').size,            
         stdout=open(self.work_dir + 'stdout.txt', 'r').read())
Esempio n. 51
0
    def result(self):
        """
        display the algo results
        """

        self.cfg['param']['orsa']= '0'
        height = 10 + image(self.work_dir+'matches.png').size[1]
        return self.tmpl_out("result.html", height=height)
Esempio n. 52
0
def plot_cross(input_image, x, y, output_image):
    """
    draw a cross at the position (x,y)
    """
    img = image(input_image)
    img.draw_cross((x, y), size=4, color="white")
    img.draw_cross((x, y), size=2, color="red")
    img.save(output_image)
Esempio n. 53
0
    def run_algo(self, params=None):
        """
        the core algo runner
        could also be called by a batch processor
        this one needs no parameter
        """
        self.cfg['param']['sizex'] = image(self.work_dir + \
                                           'input_0.png').size[0]
        self.cfg['param']['sizey'] = image(self.work_dir + \
                                            'input_0.png').size[1]

        commandargs = ['LUTBasedNSDistanceTransform']

        print(type(self.cfg['param']['distance_def']), \
                   self.cfg['param']['distance_def'])

        if self.cfg['param']['centered']:
            commandargs += ['-c']

        if self.cfg['param']['distance_def'] == 'd4':
            commandargs += ['-4']
        elif self.cfg['param']['distance_def'] == 'd8':
            commandargs += ['-8']
        elif self.cfg['param']['distance_def'] == 'ratio':
            commandargs += ['-r', str(self.cfg['param']['ratio'])]
        elif self.cfg['param']['distance_def'] == 'sequence':
            commandargs += ['-s', str(self.cfg['param']['sequence'])]

        commandargs += ['-f', 'input_0.png']
        commandargs += ['-t', 'png']
        f = open(self.work_dir + "resu_r.png", "w")
        self.runCommand(commandargs, stdOut=f, stdErr=subprocess.PIPE, \
                        comp='> resu_r.png')
        f.close()


        commandargs = ['convert.sh', '-normalize', 'resu_r.png', \
                      'resu_n.jpg']
        self.runCommand(commandargs, stdErr=subprocess.PIPE)

        fcommands = open(self.work_dir + "commands.txt", "w")
        fcommands.write(self.commands)
        fcommands.close()

        return
Esempio n. 54
0
 def result(self):
     """
     display the algo results
     """
     # read the parameters
     t = self.cfg['param']['t']
     return self.tmpl_out("result.html", t=t,
                          sizeY="%i" % image(self.work_dir 
                                             + 'input_1.png').size[1])