Exemplo n.º 1
0
    def process(self, input_images, connected_outs):
        if len(input_images) != 0:
            save_file = self.getParamContent('Save file')
            if save_file == None:
                print "In '%s': Please choose a valid file to save to." % self.name
                return FAIL
            if os.path.splitext(save_file)[1].lower() not in [
                    '.png', '.bmp', '.jpg', '.jpeg', '.tiff', '.txt'
            ]:
                save_file += '.jpg'

            if 'B&W or RGB' in input_images:
                save_image = input_images['B&W or RGB']
            else:
                first_image = input_images[input_images.keys()[0]]
                save_image = numpy.zeros(
                    (first_image.shape[0], first_image.shape[1], 3), dtype='f')
                for i, color in enumerate(['Red', 'Green', 'Blue']):
                    if color in input_images:
                        if input_images[color].ndim == 2:
                            save_image[:, :, i] = input_images[color]
                        elif input_images[color].shape[2] == 3:
                            save_image[:, :, i] = input_images[color][:, :, i]
                        else:
                            print "In '%s': Input image '%s' has wrong number of channels." % (
                                self.name, color)
                            return FAIL

            dir_name, ext = os.path.splitext(save_file)
            if self.getParamContent('Save mode') == 'Overwrite single':
                pass
            elif self.getParamContent('Save mode') == 'Save sequence':
                if self.last_file != save_file:
                    self.sequence_no = 0
                self.last_file = save_file
                save_file = dir_name + str(self.sequence_no).zfill(5) + ext
                self.sequence_no += 1

            if ext == '.txt':
                numpy.savetxt(save_file, save_image)
            else:
                save_image = filter_base.make_uint8(save_image)
                if save_image.ndim == 2:
                    im_type = 'L'
                elif save_image.shape[2] == 3:
                    im_type = 'RGB'
                else:
                    print "In '%s': Error: Wrong number of channel when saving. Should not see this message." % self.name
                    return FAIL
                Image.fromarray(save_image, im_type).save(save_file)
            self.updated = True
            if self.getParamContent('Notification on file write') == 'Yes':
                print "In '%s': Wrote:" % self.name, save_file
            return {}
        else:
            return FAIL
Exemplo n.º 2
0
 def process(self, input_images, connected_outs):
     if len(input_images) != 0:
         save_file = self.getParamContent('Save file')
         if save_file == None:
             print "In '%s': Please choose a valid file to save to." %self.name
             return FAIL        
         if os.path.splitext(save_file)[1].lower() not in ['.png','.bmp',
                                                           '.jpg','.jpeg',
                                                           '.tiff','.txt']:
             save_file += '.jpg'
         
         if 'B&W or RGB' in input_images:
             save_image = input_images['B&W or RGB']   
         else:
             first_image = input_images[input_images.keys()[0]]
             save_image = numpy.zeros( (first_image.shape[0], first_image.shape[1], 3),
                                       dtype='f' )
             for i, color in enumerate(['Red','Green','Blue']):
                 if color in input_images:
                     if input_images[color].ndim == 2:
                         save_image[:,:,i] = input_images[color]
                     elif input_images[color].shape[2] == 3:
                         save_image[:,:,i] = input_images[color][:,:,i]
                     else:
                         print "In '%s': Input image '%s' has wrong number of channels." %(self.name,color)
                         return FAIL
                 
         dir_name, ext = os.path.splitext(save_file)
         if self.getParamContent('Save mode') == 'Overwrite single':
             pass
         elif self.getParamContent('Save mode') == 'Save sequence':
             if self.last_file != save_file:
                 self.sequence_no = 0
             self.last_file = save_file
             save_file = dir_name + str(self.sequence_no).zfill(5) + ext
             self.sequence_no += 1
                             
         if ext == '.txt':
             numpy.savetxt(save_file, save_image)
         else:
             save_image = filter_base.make_uint8(save_image)
             if save_image.ndim == 2: 
                 im_type = 'L'
             elif save_image.shape[2] == 3:
                 im_type = 'RGB'
             else:
                 print "In '%s': Error: Wrong number of channel when saving. Should not see this message." %self.name
                 return FAIL                
             Image.fromarray(save_image, im_type).save(save_file)             
         self.updated = True                
         if self.getParamContent('Notification on file write') == 'Yes':
             print "In '%s': Wrote:" %self.name, save_file
         return {}
     else:
         return FAIL
Exemplo n.º 3
0
    def processParams(self):
        param_dict = self.getParam_dict()
        if isEqualDicts(param_dict,self.last_params): return

        kernel = self.createKernel(**(param_dict))
        self.last_params=param_dict
        self.last_kernel = kernel
        self.abortQuery()
        kernel = filter_base.make_uint8(kernel)
        kernel_rz = filter_base.resize(kernel, percent=800)
#        if self.kernel_fig is None:
#            self.kernel_fig = mpl.pyplot.figure(figsize=(3, 2), dpi=100)
#            self.kernel_plt = self.kernel_fig.add_subplot(111)
#        self.kernel_fig.clear()
#        self.kernel_plt.imshow(kernel, cmap=mpl.cm.gray)

        self.setParamContent("Kernel", kernel_rz, emitSignal=True)
Exemplo n.º 4
0
    def processParams(self):
        param_dict = self.getParam_dict()
        if isEqualDicts(param_dict, self.last_params): return

        kernel = self.createKernel(**(param_dict))
        self.last_params = param_dict
        self.last_kernel = kernel
        self.abortQuery()
        kernel = filter_base.make_uint8(kernel)
        kernel_rz = filter_base.resize(kernel, percent=800)
        #        if self.kernel_fig is None:
        #            self.kernel_fig = mpl.pyplot.figure(figsize=(3, 2), dpi=100)
        #            self.kernel_plt = self.kernel_fig.add_subplot(111)
        #        self.kernel_fig.clear()
        #        self.kernel_plt.imshow(kernel, cmap=mpl.cm.gray)

        self.setParamContent("Kernel", kernel_rz, emitSignal=True)
Exemplo n.º 5
0
 def process(self, input_images, connected_outs):
     if len(input_images) == 0:
         return FAIL
     all_weights = [self.getParamContent(input_name+' weight') for input_name in self.input_names]
     imgs = []
     weights = []   
     all_inputs_8bit = True     
     for i,input_name in enumerate(self.input_names):
         if input_name in input_images.keys():
             imgs.append(input_images[input_name])
             if input_images[input_name].dtype != 'uint8': all_inputs_8bit = False
             weights.append(all_weights[i])
     
     summation_img = numpy.zeros_like(imgs[0], dtype='f')        
     for i,img in enumerate(imgs):
         summation_img = summation_img+img*weights[i]        
     if all_inputs_8bit:     
         out_im = filter_base.make_uint8(summation_img)
     else: 
         out_im = filter_base.make_normfloat32(summation_img)                              
     return {self.o_output:out_im}