def execute(outputsize):
    
    faces_dir_path = "data/train_set/48_48_faces_web_augmented"
    bkgs_dir_path = "data/train_set/48_48_nonfaces_aflw"
    
    target_path = "data/train_set/13"
    
    
    faces_dir=join(target_path,"faces")
    nonfaces_dir = join(target_path,"nonfaces") 
    
    
 
    os.makedirs(nonfaces_dir)
    os.makedirs(faces_dir)
    
    img_faces = [ f for f in listdir(faces_dir_path) if isfile(join(faces_dir_path,f)) and f.endswith("png") ]
    img_bkgs =  [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path,f)) and f.endswith("jpg") ]
    
    for i, img_name in enumerate(img_faces):
        img_path = join(faces_dir_path,img_name)
        img = imread(img_path)
        resized_img = resize(img,outputsize)     
        ubyte_img = img_as_ubyte(resized_img)   
        imsave(join(faces_dir,img_name), ubyte_img)
        print "processed "+ img_path
        
    for i, img_name in enumerate(img_bkgs):
        img_path = join(bkgs_dir_path,img_name)
        img = imread(img_path)
        gray_img = rgb2gray(img)  
        resized_img = resize(gray_img,outputsize)    
        ubyte_img = img_as_ubyte(resized_img)            
        imsave(join(nonfaces_dir,img_name), ubyte_img)
        print "processed "+ img_path
def convert_to_gray():
    bkgs_dir_path = "data/train_set/13/nonfaces"
    target_path = "data/train_set/13/nonfaces_gray"
     
    os.makedirs(target_path)
    img_bkgs =  [ f for f in listdir(bkgs_dir_path) if isfile(join(bkgs_dir_path,f)) and f.endswith("jpg") ]
     
     
    for i, img_name in enumerate(img_bkgs):
        img_path = join(bkgs_dir_path,img_name)
        img = imread(img_path)
        gray_img = rgb2gray(img)
        imsave(join(target_path,img_name), gray_img)
def execute(outputsize):

    faces_dir_path = "data/train_set/48_48_faces_web_augmented"
    bkgs_dir_path = "data/train_set/48_48_nonfaces_aflw"

    target_path = "data/train_set/13"

    faces_dir = join(target_path, "faces")
    nonfaces_dir = join(target_path, "nonfaces")

    os.makedirs(nonfaces_dir)
    os.makedirs(faces_dir)

    img_faces = [
        f for f in listdir(faces_dir_path)
        if isfile(join(faces_dir_path, f)) and f.endswith("png")
    ]
    img_bkgs = [
        f for f in listdir(bkgs_dir_path)
        if isfile(join(bkgs_dir_path, f)) and f.endswith("jpg")
    ]

    for i, img_name in enumerate(img_faces):
        img_path = join(faces_dir_path, img_name)
        img = imread(img_path)
        resized_img = resize(img, outputsize)
        ubyte_img = img_as_ubyte(resized_img)
        imsave(join(faces_dir, img_name), ubyte_img)
        print "processed " + img_path

    for i, img_name in enumerate(img_bkgs):
        img_path = join(bkgs_dir_path, img_name)
        img = imread(img_path)
        gray_img = rgb2gray(img)
        resized_img = resize(gray_img, outputsize)
        ubyte_img = img_as_ubyte(resized_img)
        imsave(join(nonfaces_dir, img_name), ubyte_img)
        print "processed " + img_path
def convert_to_gray():
    bkgs_dir_path = "data/train_set/13/nonfaces"
    target_path = "data/train_set/13/nonfaces_gray"

    os.makedirs(target_path)
    img_bkgs = [
        f for f in listdir(bkgs_dir_path)
        if isfile(join(bkgs_dir_path, f)) and f.endswith("jpg")
    ]

    for i, img_name in enumerate(img_bkgs):
        img_path = join(bkgs_dir_path, img_name)
        img = imread(img_path)
        gray_img = rgb2gray(img)
        imsave(join(target_path, img_name), gray_img)
def main():
    img = imread("HJoceanSmall.png")
#     imshow(img)
    reduced_img = img
    start_time = time.time()
    i = 10
    while i > 0:
        seam = find_seam(reduced_img)
        reduced_img = remove_seam(reduced_img, seam)
#         imsave(str(i), reduced_img)
        i = i-1
    stop_time = time.time()
    plot_seam(reduced_img)
    show()
    print "Time taken :", stop_time - start_time
def resize_imgs_in_dir(outputsize):
    
    img_dir_path = "data/newnonfaces/48_48_non_faces_aflw"
    
    target_path = "data/newnonfaces/13/nonfaces"
        
    os.makedirs(target_path)
    
    img_faces = [ f for f in listdir(img_dir_path) if isfile(join(img_dir_path,f)) and f.endswith("jpg") ]
    
    for i, img_name in enumerate(img_faces):
        img_path = join(img_dir_path,img_name)
        img = imread(img_path)
        resized_img = resize(img,outputsize)     
        ubyte_img = img_as_ubyte(resized_img)   
        imsave(join(target_path,img_name), ubyte_img)
        print "processed "+ img_path
def resize_imgs_in_dir(outputsize):

    img_dir_path = "data/newnonfaces/48_48_non_faces_aflw"

    target_path = "data/newnonfaces/13/nonfaces"

    os.makedirs(target_path)

    img_faces = [
        f for f in listdir(img_dir_path)
        if isfile(join(img_dir_path, f)) and f.endswith("jpg")
    ]

    for i, img_name in enumerate(img_faces):
        img_path = join(img_dir_path, img_name)
        img = imread(img_path)
        resized_img = resize(img, outputsize)
        ubyte_img = img_as_ubyte(resized_img)
        imsave(join(target_path, img_name), ubyte_img)
        print "processed " + img_path
Example #8
0
i = img_as_ubyte(i_f2)

# To display this image
plt.imshow(i, cmap=plt.cm.gray)  # For showing gray-scale images
#ndim(i)
plt.show()

# <headingcell level=3>

# 2. Importing & displaying using io.imread() and io.imshow()

# <codecell>

phantom = img_as_ubyte(
    io.imread(
        '/Users/chintak/Repositories/scikit-image/skimage/data/phantom.png',
        as_grey=True))
# 'as_grey=True' ensures that the image is taken as a 2D rather than a 3D array with equal R,G,B values for a point
io.imshow(phantom)
plt.show()

# <headingcell level=2>

# EROSION

# <rawcell>

# Usage : erosion(image, selem, out=None, shift_x=False, shift_y=False)
#
# Return greyscale morphological erosion of an image.
#
Example #9
0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

from skimage import data
from skimage.filters import threshold_otsu
from skimage.segmentation import clear_border
from skimage.measure import label
from skimage.morphology import closing, square, disk
from skimage.measure import regionprops
from skimage.color import label2rgb
import skimage.io._io as io

image = io.imread('test.jpg', as_grey=True)

# apply threshold
thresh = threshold_otsu(image)
bw = closing(image > thresh, disk(15))

# remove artifacts connected to image border
cleared = bw.copy()
clear_border(cleared)

# label image regions
label_image = label(cleared)
borders = np.logical_xor(bw, cleared)
label_image[borders] = -1
image_label_overlay = label2rgb(label_image, image=image)

fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
ax.imshow(image_label_overlay)
Example #10
0
 def load_func(fname, **kwargs):
     kwargs.setdefault('dtype', dtype)
     return imread(fname, **kwargs)
i_f2 = i_f[:,:,0]
# To convert to uint8 data type
i = img_as_ubyte(i_f2)

# To display this image
plt.imshow(i, cmap=plt.cm.gray)  # For showing gray-scale images
#ndim(i)
plt.show()

# <headingcell level=3>

# 2. Importing & displaying using io.imread() and io.imshow()

# <codecell>

phantom = img_as_ubyte(io.imread('/Users/chintak/Repositories/scikit-image/skimage/data/phantom.png', as_grey=True))
# 'as_grey=True' ensures that the image is taken as a 2D rather than a 3D array with equal R,G,B values for a point
io.imshow(phantom)
plt.show()

# <headingcell level=2>

# EROSION

# <rawcell>

# Usage : erosion(image, selem, out=None, shift_x=False, shift_y=False)
# 
# Return greyscale morphological erosion of an image.
# 
# Morphological erosion sets a pixel at (i,j) to the **minimum over all pixels