Python matplotlib.image.imsave() Examples

The following are 11 code examples of matplotlib.image.imsave(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.image , or try the search function .
Example #1
Source File: resize.py    From deep_learning_for_camera_trap_images with MIT License 6 votes vote down vote up
def do_chunk(pid,filelist):
    for co,row in enumerate(filelist):
      try:
        if co%1000==0:
          print(co)
          sys.stdout.flush()
        img=mpimg.imread(row)
        img=scipy.misc.imresize(img[0:-100,:],(256,256))
        path=dst_dir+str(row[len(src_dir):row.rfind('/')])

        if not os.path.exists(path):
          os.makedirs(path)
        mpimg.imsave(dst_dir+row[len(src_dir):],img)
      except:
        print 'Severe Error for'+row
        #raise
    print("Process "+str(pid)+"  is done") 
Example #2
Source File: model.py    From spyre with MIT License 6 votes vote down vote up
def getImagePath(self, img_obj):
        buffer = io.BytesIO()
        mpimg.imsave(buffer, img_obj)
        try:
            mpimg.imsave(buffer, img_obj)
        except Exception:
            logging.error("Error: getImage method must return an image object")
        return(buffer) 
Example #3
Source File: pyplot.py    From Computable with MIT License 5 votes vote down vote up
def imsave(*args, **kwargs):
    return _imsave(*args, **kwargs) 
Example #4
Source File: pyplot.py    From matplotlib-4-abaqus with MIT License 5 votes vote down vote up
def imsave(*args, **kwargs):
    return _imsave(*args, **kwargs) 
Example #5
Source File: pyplot.py    From neural-network-animation with MIT License 5 votes vote down vote up
def imsave(*args, **kwargs):
    return _imsave(*args, **kwargs) 
Example #6
Source File: explorer.py    From visual-navigation-agent-pytorch with MIT License 5 votes vote down vote up
def show(self):
        fig = plt.figure()
        imgplot = plt.imshow(self.env.render(mode = 'image'))
        def press(event):
            def redraw():
                plt.imshow(self.env.render(mode = 'image'))
                fig.canvas.draw()

            if event.key == 's':
                mpimg.imsave("output.png",self.env.render(mode = 'image'))
            elif event.key == 'up':
                self.env.step('MoveAhead')
                redraw()
            elif event.key == 'right':
                self.env.step('RotateRight')
                redraw()
            elif event.key == 'left':
                self.env.step('RotateLeft')
                redraw()

            pass

        plt.rcParams['keymap.save'] = ''
        fig.canvas.mpl_connect('key_press_event', press)
        plt.axis('off')
        plt.show() 
Example #7
Source File: test_convert_ucf11.py    From Optical-Flow-Guided-Feature with MIT License 5 votes vote down vote up
def test():
    print('Test read data')
    dataset = ucf11.get_split('test', 'data/UCF11-tfrecord')
    input, label = ucf11.build_data(dataset, 'train',batch_size=BATCH_SIZE)

    new_input = off_preprocessing.preprocess_image(input, 240, 240, is_training=True)

    example_queue = tf.FIFOQueue(
        3 * BATCH_SIZE,
        dtypes=[tf.float32, tf.uint8, tf.int32],
        shapes=[_OUTPUT_SHAPES, _ORIGINAL_OUTPUT_SHAPES, []]
    )
    num_threads = 1

    example_queue_op = example_queue.enqueue([new_input, input, label])
    tf.train.add_queue_runner(tf.train.queue_runner.QueueRunner(
        example_queue, enqueue_ops=[example_queue_op] * num_threads))

    new_inputs, inputs, labels = example_queue.dequeue_many(BATCH_SIZE)

    new_images = tf.unstack(new_inputs, axis=0)

    print(new_images[0])

    fx, fy = sobel(new_images[0])

    spax = tf.unstack(fx, axis=0)
    spay = tf.unstack(fy, axis=0)

    print(fx)
    print(fy)
    print(spax)

    with tf.Session() as sess:
        tf.train.start_queue_runners(sess)
        sx, sy, l = sess.run([spax[0], spay[0], labels])
        for i in range(sx.shape[2]):
            image.imsave('%d_fx%d' % (l[0], i), sx[:,:,i], cmap='gray')
            image.imsave('%d_fy%d' % (l[0], i), sy[:,:,i], cmap='gray') 
Example #8
Source File: Infer.py    From TFHubSample with GNU General Public License v3.0 5 votes vote down vote up
def _plot_and_save(self, src_path, class_entities, boxes):
        src_path = src_path.decode('ascii')
        img = mpimg.imread(src_path)
        shape = img.shape
        for ce, b in zip(class_entities, boxes):
            ce = ce.decode('ascii')
            s1, s2, s3, s4 = int(b[1] * shape[1]), int(b[0] * shape[0]), int(b[3] * shape[1]), int(b[2] * shape[0])
            cv2.rectangle(img, (s1, s2), (s3, s4), (0, 255, 0), 10)
            cv2.putText(img, ce, (s1, s2), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)

        dst_path = os.path.join(self._save_path, os.path.basename(src_path))
        mpimg.imsave(dst_path, img) 
Example #9
Source File: Infer.py    From TFHubSample with GNU General Public License v3.0 5 votes vote down vote up
def _save_images(self, images):
        for save_index, image in enumerate(images, self._save_index_at):
            save_path = os.path.join(self._save_path, '{:05d}.jpg'.format(save_index))
            mpimg.imsave(save_path, image)

        self._save_index_at += len(images) 
Example #10
Source File: Augment.py    From TFHubSample with GNU General Public License v3.0 5 votes vote down vote up
def _save_image(self, image, file_path, run_no):
        file_path = file_path.decode('ascii')
        file_name = os.path.splitext(os.path.basename(file_path))[0]
        dst_file_path = os.path.join(self._dst_folder_path, '{}_{}.jpg'.format(file_name, run_no + 1))
        mpimg.imsave(dst_file_path, image) 
Example #11
Source File: pyplot.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def imsave(*args, **kwargs):
    return _imsave(*args, **kwargs)