Exemple #1
0
def test_tags():
    f = Image([1, 2, 3], foo='bar', sigma='delta')
    g = Image([3, 2, 1], sun='moon')
    h = Image([1, 1, 1])

    assert_equal(f.tags['foo'], 'bar')
    assert_array_equal((g + 2).tags['sun'], 'moon')
    assert_equal(h.tags, {})
Exemple #2
0
def test_repr_png_roundtrip():
    # Use RGB-like shape since some backends convert grayscale to RGB
    original_array = 255 * np.ones((5, 5, 3), dtype=np.uint8)
    image = Image(original_array)
    array = imread(BytesIO(image._repr_png_()))
    # Force output to ubyte range for plugin compatibility.
    # For example, Matplotlib will return floats even if the image is uint8.
    assert_array_equal(img_as_ubyte(array), original_array)
    def scaled_image(self, scale=1):
        """
        Returns a nearest-neighbor upscaled scaled version of the image.

        Parameters
        ----------
        scale : int
            Upscaling using nearest neighbor, e.g. a scale of 5 will make each
            pixel a 5x5 rectangle in the output.

        Returns
        -------
        scaled_image : skimage.io.Image, (height, width, 3)
            Returns a scaled up RGB image. If you do not have scikit-image, it
            will be returned as a regular Numpy array. The benefit of wrapping
            it in `Image`, is so that it will be automatically displayed in
            IPython notebook, without having to issue any drawing calls.
        """
        if scale == 1:
            return self._data
        else:
            from skimage.transform import resize
            data = resize(self._data, tuple([self._data.shape[i] * scale
                                             for i in range(2)]), order=0)
            return Image(data)
 def image(self):
     """
     Returns the image as a skimage.io.Image class.
     """
     return Image(self._data)
Exemple #5
0
 def image(self):
     """
     Returns the image as a skimage.io.Image class.
     """
     Image = _load_image_class()
     return Image(self._data)
Exemple #6
0
from pylab import *
#from skimage.io import Image
from skimage.morphology import square
import skimage as si
import numpy as np
from numpy import array
import matplotlib.pyplot as pl

def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.144])

# #canny + sobel
if __name__ == '__main__':
    picture_table=['samolot17.jpg','samolot05.jpg','samolot10.jpg','samolot11.jpg','samolot12.jpg','samolot01.jpg']
    wyn_table = ['wynik.jpg','wynik1.jpg','wynik2.jpg','wynik3.jpg','wynik4.jpg','wynik5.jpg']
    new_im = Image.new('RGB', (600,600))
    i=0
    j=0
    for index,image in enumerate(picture_table):
        im = Image.open(image)

        img = img_as_float(data.imread(image))
        tmp = rgb2gray(img)
        global_thresh = threshold_otsu(tmp)
        binary_global = tmp > global_thresh
        # block_size = 5
        # binary_adaptive = threshold_adaptive(tmp, block_size, offset=10)
        sob = filters.sobel(binary_global)**0.9
        #final= skimage.feature.canny(sob, sigma=1)

        #
meanshape = ((meanshape-mean)+[cropsize[0]/2,cropsize[1]/2])

imshape = (cropsize[0], cropsize[1], 3)
avim = np.zeros(imshape)
imlen = len(data_pca.keys())

# for each imaged
count = 0
for filename, values in data_pca.iteritems():
  # warp to meanshape
  im = imread( os.path.join(data_folder, "cropped/", filename) )
  
  tform = PiecewiseAffineTransform()
  tform.estimate(meanshape, values+[cropsize[0]/2,cropsize[1]/2])
  # store in array
  outim = warp(im, tform, output_shape=cropsize)
  #imsave("./averageface/test.bmp", outim)
  avim += skimage.util.img_as_float(outim)
  count += 1
  print str(count)

avim /= imlen
avim *= 255  
avim = avim.astype(np.uint8)
imsave("./average.bmp", Image(avim))

if cleanUp:
  import shutil
  if os.path.exists(os.path.join(config.data_folder, "cropped")):
    shutil.rmtree(os.path.join(config.data_folder, "cropped"))