How to use the scipy.misc.imread 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 MarvinTeichmann / tensorflow-fcn / test_fcn8_vgg.py View on Github external
import numpy as np
import logging
import tensorflow as tf
import sys

import fcn8_vgg
import utils

logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                    level=logging.INFO,
                    stream=sys.stdout)

from tensorflow.python.framework import ops

img1 = scp.misc.imread("./test_data/tabby_cat.png")

with tf.Session() as sess:
    images = tf.placeholder("float")
    feed_dict = {images: img1}
    batch_images = tf.expand_dims(images, 0)

    vgg_fcn = fcn8_vgg.FCN8VGG()
    with tf.name_scope("content_vgg"):
        vgg_fcn.build(batch_images, debug=True)

    print('Finished building Network.')

    logging.warning("Score weights are initialized random.")
    logging.warning("Do not expect meaningful results.")

    logging.info("Start Initializing Variabels.")
github pmneila / morphsnakes / tests.py View on Github external
def test_lakes():
    logging.info('running: test_lakes...')
    # Load the image.
    imgcolor = imread(PATH_IMG_LAKES)/255.0
    img = rgb2gray(imgcolor)
    
    # MorphACWE does not need g(I)
    
    # Morphological ACWE. Initialization of the level-set.
    macwe = morphsnakes.MorphACWE(img, smoothing=3, lambda1=1, lambda2=1)
    macwe.levelset = circle_levelset(img.shape, (80, 170), 25)
    
    # Visual evolution.
    fig = plt.figure()
    morphsnakes.evolve_visual(macwe, fig, num_iters=200, background=imgcolor)
github MarvinTeichmann / KittiSeg / model / segmentation / kitti_seg_input.py View on Github external
The generator outputs the image and the gt_image.
    """
    base_path = os.path.realpath(os.path.dirname(data_file))
    files = [line.rstrip() for line in open(data_file)]

    for epoche in itertools.count():
        shuffle(files)
        for file in files:
            image_file, gt_image_file = file.split(" ")
            image_file = os.path.join(base_path, image_file)
            assert os.path.exists(image_file), \
                "File does not exist: %s" % image_file
            gt_image_file = os.path.join(base_path, gt_image_file)
            assert os.path.exists(gt_image_file), \
                "File does not exist: %s" % gt_image_file
            image = scipy.misc.imread(image_file)
            # Please update Scipy, if mode='RGB' is not avaible
            gt_image = scp.misc.imread(gt_image_file, mode='RGB')

            yield image, gt_image
github 3Scan / 3scan-skeleton / runscripts / coronalSlicesDownsample.py View on Github external
#     cv2.line(image,(x1,y1),(x2,y2),(0,0,255),2)

# cv2.imwrite('houghlines3.jpg',image)
# transverseSlice = imread("transverseSlice2767.png")
# for coords in validCenters:
#     transverseSlice[coords[1] - 1: coords[1] + 2, int((coords[2] + 6) / 7) - 1: int((coords[2] + 6) / 7) + 2] = 1

root = '/home/pranathi/dsby7-CS/'
formatOfFiles = 'png'
listOfJpgs = [os.path.join(root, files) for files in os.listdir(root) if formatOfFiles in files]
listOfJpgs.sort()
count = 0
saggitalSlicearr = np.zeros((112, 864, 1725), dtype=np.uint8)
for index in range(0, len(listOfJpgs)):
    for countSlice, value in enumerate(list(range(0, 1113, 10))):
        image = imread(root + 'downSampledSlice%i.png' % index)
        saggitalSlicearr[countSlice, :, index] = image[:, value]
for i in range(0, saggitalSlicearr.shape[0]):
    imsave(root + "saggitalSlices/" + "saggitalSlice%i.jpg" % i, saggitalSlicearr[i])

maskArtVein = np.load('/home/pranathi/maskArtVein.npy')
root = '/home/pranathi/subsubVolumethresholdNew_28/'
formatOfFiles = 'npy'
listOfNpys = [os.path.join(root, files) for files in os.listdir(root) if formatOfFiles in files]
listOfNpys.sort()
transverseSlice = imread("transverseSlice2767.png")
for npyIndex in listOfNpys:
    npyIndex = npyIndex.replace('.npy', '')
    strs = npyIndex.split('/')[-1].split('_')
    i, j, k = [int(s) for s in strs if s.isdigit()]
    i = i - 160
    if maskArtVein[(int((i + 9) / 10.0), int((j + 6) / 7.0), int((k + 6) / 7.0))] != 255:
github rinkstiekema / PDF-Table-Structure-Recognition-using-deep-learning / pipeline / combine.py View on Github external
def combine_images(location):
	images_list = os.listdir(location)
	count = 0
	for image in images_list:
		try:
			base_name = "-".join(".".join(image.split(".")[0:-1]).split("-")[0:-1])
			#print(image, location+base_name+"-A.png")
			# img_A = Image.open(location+base_name+"-A.png")
			# img_B = Image.open(location+base_name+"-B.png")
			img_A = scipy.misc.imread(location+base_name+"-A.png", mode='RGB').astype(np.float)
			img_B = scipy.misc.imread(location+base_name+"-B.png", mode='RGB').astype(np.float) 
			
			img_A = pad(img_A, (1024, 1024, 3))
			img_B = pad(img_B, (1024, 1024, 3))

			old_size = img_A.size
			new_size = img_B.size
			combined = np.hstack((np.array(new_A), np.array(new_B)))
			scipy.misc.imsave(location+base_name+".png", combined)
			count += 1
			if(count % 100 == 0):
				print(count, " out of ", len(images_list), " combined")
		except:
			continue
github RobotLocomotion / spartan / src / DepthSim / python / common / util.py View on Github external
def get_images(num,max_digits,path):
    depth_suffix = "_depth.png"
    color_suffix = "_rgb.png"
    reflec_suffix = "_rgb_r.png"
    shade_suffix = "_rgb_s.png"
    norm_suffix = "normal_ground_truth.png"
    ground_truth_suffix = "depth_ground_truth.png"
    prefix = str(num).zfill(max_digits)
    img_d=misc.imread(path+prefix+depth_suffix)
    img_c=misc.imread(path+prefix+color_suffix)
    img_s=misc.imread(path+prefix+shade_suffix)
    img_r=misc.imread(path+prefix+reflec_suffix)
    img_n=misc.imread(path+prefix+norm_suffix)
    img_gt=misc.imread(path+prefix+ground_truth_suffix)
    return [img_d,img_c,img_s,img_r,img_n,img_gt]
github ignaciorlando / refuge-evaluation / evaluation_metrics / evaluation_metrics_for_segmentation.py View on Github external
segmentation = segmentation[:,:,0]
        # read the gt
        if is_training:
            gt_filename = path.join(gt_folder, 'Glaucoma', image_filenames[i])
            if path.exists(gt_filename):
                gt_label = misc.imread(gt_filename)
            else:
                gt_filename = path.join(gt_folder, 'Non-Glaucoma', image_filenames[i])
                if path.exists(gt_filename):
                    gt_label = misc.imread(gt_filename)
                else:
                    raise ValueError('Unable to find {} in your training folder. Make sure that you have the folder organized as provided in our website.'.format(image_filenames[i]))
        else:
            gt_filename = path.join(gt_folder, image_filenames[i])
            if path.exists(gt_filename):
                gt_label = misc.imread(gt_filename)
            else:
                raise ValueError('Unable to find {} in your ground truth folder. If you are using training data, make sure to use the parameter is_training in True.'.format(image_filenames[i]))

        # evaluate the results and assign to the corresponding row in the table
        cup_dices[i], disc_dices[i], ae_cdrs[i] = evaluate_binary_segmentation(segmentation, gt_label)

    # return the colums of the table
    return image_filenames, cup_dices, disc_dices, ae_cdrs
github furkanbiten / SelectiveTextStyleTransfer / twoStage / magenta / image_utils.py View on Github external
def load_np_image_uint8(image_file):
  """Loads an image as a numpy array.

  Args:
    image_file: str. Image file.

  Returns:
    A 3-D numpy array of shape [image_size, image_size, 3] and dtype uint8,
    with values in [0, 255].
  """
  with tempfile.NamedTemporaryFile() as f:
    f.write(tf.gfile.GFile(image_file, 'rb').read())
    f.flush()
    image = scipy.misc.imread(f.name)
    # Workaround for black-and-white images
    if image.ndim == 2:
      image = np.tile(image[:, :, None], (1, 1, 3))
    return image
github CSAILVision / miniplaces / model / tensorflow / DataLoader.py View on Github external
def next_batch(self, batch_size):
        images_batch = np.zeros((batch_size, self.fine_size, self.fine_size, 3)) 
        labels_batch = np.zeros(batch_size)
        for i in range(batch_size):
            image = scipy.misc.imread(self.list_im[self._idx])
            image = scipy.misc.imresize(image, (self.load_size, self.load_size))
            image = image.astype(np.float32)/255.
            image = image - self.data_mean
            if self.randomize:
                flip = np.random.random_integers(0, 1)
                if flip>0:
                    image = image[:,::-1,:]
                offset_h = np.random.random_integers(0, self.load_size-self.fine_size)
                offset_w = np.random.random_integers(0, self.load_size-self.fine_size)
            else:
                offset_h = (self.load_size-self.fine_size)//2
                offset_w = (self.load_size-self.fine_size)//2

            images_batch[i, ...] =  image[offset_h:offset_h+self.fine_size, offset_w:offset_w+self.fine_size, :]
            labels_batch[i, ...] = self.list_lab[self._idx]
github paarthneekhara / neural-vqa-tensorflow / utils.py View on Github external
def load_image_array(image_file):
	img = misc.imread(image_file)
	# GRAYSCALE
	if len(img.shape) == 2:
		img_new = np.ndarray( (img.shape[0], img.shape[1], 3), dtype = 'float32')
		img_new[:,:,0] = img
		img_new[:,:,1] = img
		img_new[:,:,2] = img
		img = img_new

	img_resized = misc.imresize(img, (224, 224))
	return (img_resized/255.0).astype('float32')