How to use the scipy.misc function in scipy

To help you get started, we’ve selected a few scipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ray0809 / Text-detector-for-Chinese-ID / test_demo.py View on Github external
def preprocess_img(img):
    img = im.imresize(img,(480,576,),interp='nearest')
    #print target.shape
    img = img / 255. - 0.5
    if img.mean() < 0:
        img = -img
    img = img.transpose(2,0,1)
    img = np.expand_dims(img,0)
    return img.astype('float32')
github jason887 / Using-Deep-Learning-Neural-Networks-and-Candlestick-Chart-Representation-to-Predict-Stock-Market / dataset.py View on Github external
label = suffix.split("/")[0]
            d[label].append(file_path)

    tags = sorted(d.keys())
    # print("classes : {}".format(tags))
    processed_image_count = 0
    useful_image_count = 0

    X = []
    y = []

    for class_index, class_name in enumerate(tags):
        filenames = d[class_name]
        for filename in filenames:
            processed_image_count += 1
            img = scipy.misc.imread(filename)
            height, width, chan = img.shape
            assert chan == 3
            X.append(img)
            y.append(class_index)
            useful_image_count += 1
    # print("processed {}, used {}".format(processed_image_count,useful_image_count))

    X = np.array(X).astype(np.float32)

    y = np.array(y)

    return X, y, tags
github cameronfabbri / Underwater-Color-Correction / embedding / embedding.py View on Github external
# now that we have the embeddings, interpolate between them
      alpha = np.linspace(0,1, num=5)
      latent_vectors = []
      x1 = c_embedding
      x2 = d_embedding
      for a in alpha:
         vector = x1*(1-a) + x2*a
         latent_vectors.append(vector)
      latent_vectors = np.asarray(latent_vectors)

      cc = 0
      for e in latent_vectors:
         e = np.random.normal(-1.5e-6, 7e-6, size=[1,1,1,512]).astype(np.float32)
         int_img = np.squeeze(sess.run(gen_image2, feed_dict={embedding_p:e, image_u:batch_cimages}))
         misc.imsave('./'+str(cc)+'.png', int_img)
         cc+=1
      exit()
github ANTsX / ANTsPy / ants / viz / volume.py View on Github external
os.rename(rotation_filenames[0][0], outfile)
    else:
        if verbose:
            print('Stitching images together..')
        # read first image to calculate shape of stitched image
        first_actual_file = None
        for rowidx in range(nrow):
            for colidx in range(ncol):
                if rotation_filenames[rowidx][colidx] is not None:
                    first_actual_file = rotation_filenames[rowidx][colidx]
                    break

        if first_actual_file is None:
            raise ValueError('No images were created... check your rotation argument')

        mypngimg = scipy.misc.imread(first_actual_file)
        img_shape = mypngimg.shape
        array_shape = (mypngimg.shape[0]*nrow, mypngimg.shape[1]*ncol, mypngimg.shape[-1])
        mypngarray = np.zeros(array_shape).astype('uint8')

        # read each individual image and place it in the larger stitch
        for rowidx in range(nrow):
            for colidx in range(ncol):
                ij_filename = rotation_filenames[rowidx][colidx]
                if ij_filename is not None:
                    mypngimg = scipy.misc.imread(ij_filename)
                else:
                    mypngimg = np.zeros(img_shape) + int(255*bg_grayscale)
                
                row_start = rowidx*img_shape[0]
                row_end   = (rowidx+1)*img_shape[0]
                col_start = colidx*img_shape[1]
github lmhieu612 / ADNET_demo / vis.py View on Github external
def visdir2(imdir,GT,maskdir,visdir):
    sdmkdir(visdir)    
    imlist=[]
    imnamelist=[]
    for root,_,fnames in sorted(os.walk(maskdir)):
        for fname in fnames:
            if fname.endswith('.png'):
                pathA = os.path.join(imdir,fname)
                pathGT = os.path.join(GT,fname)
                pathmask = os.path.join(maskdir,fname)
                imlist.append((pathA,pathGT,pathmask,fname))
                imnamelist.append(fname)
    for pathA,pathB,pathmask,fname in imlist:
        A = misc.imread(pathA).astype(np.uint8)
        GT = misc.imread(pathB)
        mask = misc.imread(pathmask)
        fpr, tpr, thresholds = metrics.roc_curve(GT.ravel(), mask.ravel(), pos_label=255)
        auc =  metrics.auc(fpr, tpr)
        GTv = show_plainmask_on_image(A,GT)
        #maskv = show_plainmask_on_image(A,mask)
        maskv = show_heatmap_on_image(A,mask)
        maskv = draw(maskv,auc)
        misc.imsave(os.path.join(visdir,fname),np.hstack((A,maskv,GTv)))#np.append(np.append(A,GTv,axis=1),maskv,axis=1))
        #misc.imsave(os.path.join(visdir,fname),A)#np.append(np.append(A,GTv,axis=1),maskv,axis=1))
github mcogswell / cnn_treevis / app.py View on Github external
def send_img(img, fname):
    '''
    Serve a numpy array as a jpeg image

    # Args
        img: Image (numpy array)
        fname: Name of the sent file
    '''
    f = io.BytesIO()
    scipy.misc.imsave(f, img, format='jpeg')
    f.seek(0)
    return send_file(f, attachment_filename=fname,
                     mimetype='image/jpeg')
github mpSchrader / gym-sokoban / gym_sokoban / envs / render_utils.py View on Github external
"""
    Creates an RGB image of the room.
    :param room:
    :param room_structure:
    :return:
    """
    resource_package = __name__

    room = np.array(room)
    if not room_structure is None:
        # Change the ID of a player on a target
        room[(room == 5) & (room_structure == 2)] = 6

    # Load images, representing the corresponding situation
    box_filename = pkg_resources.resource_filename(resource_package, '/'.join(('surface', 'box.png')))
    box = misc.imread(box_filename)

    box_on_target_filename = pkg_resources.resource_filename(resource_package,
                                                             '/'.join(('surface', 'box_on_target.png')))
    box_on_target = misc.imread(box_on_target_filename)

    box_target_filename = pkg_resources.resource_filename(resource_package, '/'.join(('surface', 'box_target.png')))
    box_target = misc.imread(box_target_filename)

    floor_filename = pkg_resources.resource_filename(resource_package, '/'.join(('surface', 'floor.png')))
    floor = misc.imread(floor_filename)

    player_filename = pkg_resources.resource_filename(resource_package, '/'.join(('surface', 'player.png')))
    player = misc.imread(player_filename)

    player_on_target_filename = pkg_resources.resource_filename(resource_package,
                                                                '/'.join(('surface', 'player_on_target.png')))
github Impavidity / pbase / infrastructure / src / main / python / pbase / papp / logger.py View on Github external
def image_summary(self, tag, images, step):
        """Log a list of images."""

        img_summaries = []
        for i, img in enumerate(images):
            # Write the image to a string
            try:
                s = StringIO()
            except:
                s = BytesIO()
            scipy.misc.toimage(img).save(s, format="png")

            # Create an Image object
            img_sum = tf.Summary.Image(encoded_image_string=s.getvalue(),
                                       height=img.shape[0],
                                       width=img.shape[1])
            # Create a Summary value
            img_summaries.append(tf.Summary.Value(tag='%s/%d' % (tag, i), image=img_sum))

        # Create and write Summary
        summary = tf.Summary(value=img_summaries)
        self.writer.add_summary(summary, step)
        self.writer.flush()
github pablorpalafox / semantic-depth / dist2fence.py View on Github external
[tf.nn.softmax(self.logits)],
                {self.keep_prob: 1.0, self.input_image: [frame]})

        # Road
        im_softmax_road = im_softmax[0][:, 0].reshape(self.input_shape[0], self.input_shape[1])
        segmentation_road = (im_softmax_road > 0.5).reshape(self.input_shape[0], self.input_shape[1], 1)
        road_mask = np.dot(segmentation_road, np.array([[128, 64, 128, 64]]))
        road_mask = scipy.misc.toimage(road_mask, mode="RGBA")
        #scipy.misc.imsave('road.png', road_mask)
        street_im.paste(road_mask, box=None, mask=road_mask)

        # Fence
        im_softmax_fence = im_softmax[0][:, 1].reshape(self.input_shape[0], self.input_shape[1])
        segmentation_fence = (im_softmax_fence > 0.5).reshape(self.input_shape[0], self.input_shape[1], 1)
        fence_mask = np.dot(segmentation_fence, np.array([[190, 153, 153, 64]]))
        fence_mask = scipy.misc.toimage(fence_mask, mode="RGBA")
        #scipy.misc.imsave('fence.png', fence_mask)
        street_im.paste(fence_mask, box=None, mask=fence_mask)

        return segmentation_road, segmentation_fence, np.array(street_im)
github rl-lang-grounding / rl-lang-ground / game_Env.py View on Github external
def add_pos_block(self,pos,size,img,reward,ID,map_val,resize = True) :
			
		# self.game[start_x:start_x+self.step_x-1,start_y:start_y+self.step_y-1,:] = board
		self.game_map[pos[0]:pos[0]+size[0],pos[1]:pos[1]+size[1]] = map_val
		if resize :
			img = scipy.misc.imresize(img,(size[0]*self.step_h,size[1]*self.step_w))
		
		self.game[pos[0]*self.step_h:(pos[0]+size[0])*self.step_h,pos[1]*self.step_w:(pos[1]+size[1])*self.step_w,:] = img
		self.reward_map[pos[0]:pos[0]+size[0],pos[1]:pos[1]+size[1]] = reward
		self.ids[pos[0]:pos[0]+size[0],pos[1]:pos[1]+size[1]] = ID
		self.x_position[pos[0]:pos[0]+size[0],pos[1]:pos[1]+size[1]] = pos[0]
		self.y_position[pos[0]:pos[0]+size[0],pos[1]:pos[1]+size[1]] = pos[1]