Example #1
0
def test_pic_info():
    pic = novice.open(IMAGE_PATH)
    assert_equal(pic.format, "png")
    assert_equal(pic.path, os.path.abspath(IMAGE_PATH))
    assert_equal(pic.size, (451, 300))
    assert_equal(pic.width, 451)
    assert_equal(pic.height, 300)
    assert not pic.modified
Example #2
0
def test_pic_info():
    pic = novice.open(IMAGE_PATH)
    assert_equal(pic.format, "png")
    assert_equal(pic.path, os.path.abspath(IMAGE_PATH))
    assert_equal(pic.size, (451, 300))
    assert_equal(pic.width, 451)
    assert_equal(pic.height, 300)
    assert not pic.modified
Example #3
0
def image_interestingness(prefix):
    """Calculate how visually interesting a picture is."""
    img = novice.open(BASE_URL + prefix).xy_array

    red = img[:, :, 0].mean()
    green = img[:, :, 1].mean()
    blue = img[:, :, 2].mean()

    return (red + green) / 2 / blue
Example #4
0
def image_interestingness(prefix):
    """Calculate how visually interesting a picture is."""
    try:
        img = novice.open(BASE_URL + prefix).xy_array
    except (requests.HTTPError, urllib.error.HTTPError):
        return -1.

    red = img[:, :, 0].mean()
    green = img[:, :, 1].mean()
    blue = img[:, :, 2].mean()

    return (red + green) / 2 / blue
def set_new_image_size():
    global new_width
    global new_height
    
    image_properties = novice.open(image_path)
    
    if image_properties.width > image_properties.height:
        height_percentage = image_properties.height * 100 / image_properties.width
        new_width = int(max_image_size)
        new_height = int(new_width / 100 * height_percentage)
    elif image_properties.height > image_properties.width:
        width_percentage = image_properties.width * 100 / image_properties.height
        new_height = int(max_image_size)
        new_width = int(new_height / 100 * width_percentage)
Example #6
0
    def init_outline(self):
        # Take input image
        inp = io.imread(self.main_img)
        im = color.rgb2gray(inp)

        # Get coordinates of points in edge
        edges = sobel(im)
        indices = np.where(edges > 0.375)

        x_s = indices[1]
        y_s = indices[0]

        self.edge_size = len(x_s)
        self.path_progress.setMaximum(len(x_s))

        # Flip image
        picture = novice.open(self.main_img)
        self.max_x = int(picture.size[0])
        self.max_y = int(picture.size[1])
        self.margin_x = int(picture.size[0])
        self.margin_y = int(picture.size[1])

        for i in range(self.edge_size):
            y_s[i] = self.max_y - y_s[i]

        # Combine coordinate lists
        xy_list = zip(x_s, y_s)

        # Create closed loop path
        self.path = self.create_path(list(xy_list), self.initial, self.ban)

        # Compute FFT of points in edge
        self.N = float(len(self.path))
        self.runs = float(len(self.path))
        self.trace_progress.setMaximum(self.runs)

        x_list, y_list = zip(*self.path)

        edge_points = np.zeros((1, len(self.path)), dtype=np.complex_)

        for i in range(len(self.path)):
            edge_points[0][i] = x_list[i] + y_list[i] * 1j

        self.FFT = np.fft.fft(edge_points, n=int(self.N))
Example #7
0
def resizeImage(file_path, new_width=640, suffix='_med'):
	print '# resizeImage '+str(file_path)+' '+str(new_width)
	path = os.path.dirname(file_path);
	full_file_name = os.path.basename(file_path)
	file_name, file_extension = os.path.splitext(full_file_name)

	picture = novice.open(file_path)
	current_width =  picture.size[0]
	current_height = picture.size[1]
	
	factor = float(current_width)/ float(new_width);
	new_height = int(round(current_height / factor));
	
	print "#\tshape "+str(new_height)+' '+str(new_width)
	
	new_array = resize(picture.array, (new_height, new_width))	
	picture.array = new_array

	picture.save(os.path.join(path, file_name+suffix+'.png'))
Example #8
0
def test_modify():
    pic = novice.open(SMALL_IMAGE_PATH)
    assert_equal(pic.modified, False)

    for p in pic:
        if p.x < (pic.width / 2):
            p.red /= 2
            p.green /= 2
            p.blue /= 2

    for p in pic:
        if p.x < (pic.width / 2):
            assert p.red <= 128
            assert p.green <= 128
            assert p.blue <= 128

    s = pic.size
    pic.size = (pic.width / 2, pic.height / 2)
    assert_equal(pic.size, (int(s[0] / 2), int(s[1] / 2)))

    assert pic.modified
    assert pic.path is None
Example #9
0
def test_modify():
    pic = novice.open(SMALL_IMAGE_PATH)
    assert_equal(pic.modified, False)

    for p in pic:
        if p.x < (pic.width / 2):
            p.red /= 2
            p.green /= 2
            p.blue /= 2

    for p in pic:
        if p.x < (pic.width / 2):
            assert p.red <= 128
            assert p.green <= 128
            assert p.blue <= 128

    s = pic.size
    pic.size = (pic.width / 2, pic.height / 2)
    assert_equal(pic.size, (int(s[0] / 2), int(s[1] / 2)))

    assert pic.modified
    assert pic.path is None
Example #10
0
def combine_rows(dataframe):
    left = 1 << 30
    top = 1 << 30
    right = -1
    bottom = -1
    img = novice.open(os.path.join(image_path, dataframe.iloc[0].FileName))
    digits = dataframe['DigitLabel'].tolist()
    digits = [i if i != 10 else 0 for i in digits]

    number = dataframe.iloc[0].FileName[:-4]
    left = dataframe['Left'].min()
    top = dataframe['Top'].min()
    right = dataframe[['Left', 'Width']].sum(axis=1).max()
    bottom = dataframe[['Top', 'Height']].sum(axis=1).max()
    new_df = pd.DataFrame([[
        int(number),
        int(''.join(str(d) for d in digits)), digits,
        len(digits), img.width, img.height, [left, top, right, bottom]
    ]],
                          columns=[
                              'Number', 'Value', 'Digits', 'Length', 'Width',
                              'Height', 'Box'
                          ])
    return new_df
Example #11
0
def test_out_of_bounds_indexing():
    pic = novice.open(SMALL_IMAGE_PATH)
    pic[pic.width, pic.height]
Example #12
0
from skimage import novice  # special submodule for beginners

picture = novice.open('sample.png')  # create a picture object from a file
print picture.format  # pictures know their format...
print picture.path  # ...and where they came from...
print picture.size  # ...and their size
print picture.width  # 'width' and 'height' also exposed
picture.size = (200, 250)  # changing size automatically resizes
for pixel in picture:  # can iterate over pixels
    if ((pixel.red > 0.5) and  # pixels have RGB (values are 0.0-1.0)...
        (pixel.x < picture.width)):  # ...and know where they are
        pixel.red /= 2  # pixel is an alias into the picture

print picture.modified  # pictures know if their pixels are dirty
print picture.path  # picture no longer corresponds to file
picture[0:20, 0:20] = (0., 0., 0.)  # overwrite lower-left rectangle with black
picture.save('sample-bluegreen.jpg')  # guess file type from suffix
print picture.path  # picture now corresponds to file
print picture.format  # ...has a different format
print picture.modified  # ...and is now in sync
Example #13
0
training_data_list = training_data_file.readlines()
training_data_file.close()

epochs = 1
main_directory = "C:\\Users\\miair\\Desktop\\Data\\DataSetMail"
not_main_directory = os.listdir(main_directory)
count = 0
for e in range(epochs):
    # go through all records in the training data set
    images = os.listdir("C:\\Users\\miair\\Desktop\\Data\\DataSetMail" + "\\" +
                        "4")
    for i in images:
        im = "C:\\Users\\miair\\Desktop\\Data\\DataSetMail" + "\\" + "4" + "\\" + i
        # scale and shift the inputs
        try:
            picture = novice.open(im)
            picture.size = (28, 28)
            picture.save("1.png")
            img_array = scipy.misc.imread("1.png", flatten=True)
            img_data = 255.0 - img_array.reshape(784)
            img_data = (img_data / 255.0 * 0.99) + 0.01
            # create the target output values (all 0.01, except the desired label which is 0.99)
            targets = numpy.zeros(output_nodes) + 0.01
            # all_values[0] is the target label for this record
            targets[int(im[im.rfind('b') + 1:im.find('.')])] = 0.99
            n.train(img_data, targets)
        except:
            count += 1
            print(count)

import os
Example #14
0
def test_out_of_bounds_indexing():
    pic = novice.open(SMALL_IMAGE_PATH)
    pic[pic.width, pic.height]
Example #15
0
def test_pixel_iteration():
    pic = novice.open(SMALL_IMAGE_PATH)
    num_pixels = sum(1 for p in pic)
    assert_equal(num_pixels, pic.width * pic.height)
Example #16
0
def test_out_of_bounds_indexing():
    pic = novice.open(SMALL_IMAGE_PATH)
    with testing.raises(IndexError):
        pic[pic.width, pic.height]
Example #17
0
def test_pixel_iteration():
    pic = novice.open(SMALL_IMAGE_PATH)
    num_pixels = sum(1 for p in pic)
    assert_equal(num_pixels, pic.width * pic.height)
from skimage import novice
from skimage import data
import numpy as np
import math
from skimage.novice import Picture
from skimage import filters, io

img = novice.open('sobel.png')

#print(img)

width = img.width
heigth = img.height

#print(width)
#print(heigth)

KernelX = [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]]
print(KernelX)

KernelY = [[-1, -2, -1], [0, 0, 0], [1, 2, 1]]

print(KernelY)

widthWeigths = len(KernelX)
heigthWeights = len(KernelX)

matrizGx = Picture.from_size((heigth, width), color=(255, 255, 255))
matrizGy = Picture.from_size((heigth, width), color=(255, 255, 255))
imageFinal = Picture.from_size((heigth, width), color=(255, 255, 255))
Example #19
0
from skimage import data, novice

img = novice.open('static/images/munch.png')
print("W, H : ", img.width, img.height)
i = 0
for px in img.xy_array:
    print(i, px)
    i = i + 1

img.show()
Example #20
0
from skimage import novice            # special submodule for beginners

picture = novice.open('sample.png')   # create a picture object from a file
print picture.format                  # pictures know their format...
print picture.path                    # ...and where they came from...
print picture.size                    # ...and their size
print picture.width                   # 'width' and 'height' also exposed
picture.size = (200, 250)             # changing size automatically resizes
for pixel in picture:                 # can iterate over pixels
    if ((pixel.red > 128) and         # pixels have RGB (values are 0-255)...
        (pixel.x < picture.width)):   # ...and know where they are
        pixel.red /= 2                # pixel is an alias into the picture
   
print picture.modified                # pictures know if their pixels are dirty
print picture.path                    # picture no longer corresponds to file
picture[0:20, 0:20] = (0, 0, 0)       # overwrite lower-left rectangle with black
picture.save('sample-bluegreen.jpg')  # guess file type from suffix
print picture.path                    # picture now corresponds to file
print picture.format                  # ...has a different format
print picture.modified                # ...and is now in sync
from skimage import novice
from skimage import data
import numpy as np
from skimage.novice import Picture

img = novice.open('flower.jpg')

#print(img)

width = img.width
heigth = img.height

#print(width)
#print(heigth)

matrizWeigths = [[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]]

widthWeigths = len(matrizWeigths)
heigthWeights = len(matrizWeigths[1])

newImage = np.zeros(shape=(width, heigth, 3), dtype=np.uint8)

print(img[0, 1])


def getElementCenter(matrizWeigths):
    x = len(matrizWeigths)
    y = len(matrizWeigths[0])
    return matrizWeigths[x - 1][y - 1]

from skimage import novice
from skimage import data
import numpy as np
from skimage.novice import Picture
from skimage import filters, io

img = novice.open('imgvin.jpg')

width = img.width
heigth = img.height

imageFinal = Picture.from_size((heigth, width), color=(255, 255, 255))


def calcLine(value):
    return value * 2 + 1


pixelsR = []
pixelsG = []
pixelsB = []

pad = 1
line = calcLine(pad)

for i in range(width):
    for j in range(heigth):
        for x in range(line):
            Xpos = i + (x - pad)
            for y in range(line):
                Ypos = y + (j - pad)
Example #23
0
filetotal = 75
#if filetotal = 0 , change filename to the name of the image file to be processed
filename = 'leather (6)rag_sigma230-slic_sigma0.55-n_seg1800-compactness90'

fileindex = 1
while fileindex < (filetotal + 1):

    print("----------------------")

    #step 1: load the image
    if (filetotal != 0):
        #filename = 'leather (' + str(fileindex) + ')' +'rag_sigma230-slic_sigma0.55-n_seg1800-compactness90'
        filename = 'misc (' + str(
            fileindex
        ) + ')' + 'rag_sigma230-slic_sigma0.55-n_seg1800-compactness90'

    path = 'output/' + str(filename) + '.png'
    print('processing ' + str(filename))
    img1 = imread(path)
    img1_prop = novice.open(path)
    img1_prop.size
    img1_width = img1_prop.width
    img1_height = img1_prop.height
    x1 = (img1_width / 2) - 50
    x2 = (img1_width / 2) + 50
    y1 = (img1_height / 2) - 50
    y2 = (img1_height / 2) + 50
    cropped = img1[x1:x2, y1:y2]
    scipy.misc.imsave('cropped/cropped-' + str(filename) + '.png', cropped)
    fileindex += 1
Example #24
0
def test_out_of_bounds_indexing():
    pic = novice.open(SMALL_IMAGE_PATH)
    with pytest.raises(IndexError):
        pic[pic.width, pic.height]