コード例 #1
0
ファイル: main.py プロジェクト: SchmitzAndrew/Flur
def cat_detection():
    input_image = "images/black_cat.jfif"
    catImg = Cat(input_image, catCascade)
    faces = catImg.detect_face()
    img = catImg.draw_rectangle(faces)
    blur(input_image, faces, 10)
    catImg.show_img(img)
コード例 #2
0
ファイル: main.py プロジェクト: SchmitzAndrew/Flur
def facial_blur():
    input_image = "images/lcd_soundsystem.jpg"
    faceImg = Img(input_image, faceCascade)
    faces = faceImg.detect_face()
    img = faceImg.draw_rectangle(faces)
    blur(input_image, faces, 5)
    faceImg.show_img(img)
コード例 #3
0
ファイル: pixelImage.py プロジェクト: hellosnousdd/CPE101
def main():

    if len(args) == 2:
        puzzle()
    elif len(args) == 5:
        fade()
    elif len(args) == 3:
        blur()
    else:
        print('Error: Incorrect Number of Arguments')
コード例 #4
0
ファイル: blur-png.py プロジェクト: zfnmxt/futhark-website
def main(infile, outfile, iterations):
    b = blur.blur()
    img = misc.imread(infile, mode='RGB')
    (height, width, channels) = img.shape
    blurred = b.main(iterations, img)
    # The .get() is to retrieve a Numpy array from the PyOpenCL array
    # being returned.
    misc.imsave(outfile, blurred.get().astype(numpy.uint8))
コード例 #5
0
ファイル: blur-png.py プロジェクト: nqpz/futhark-website
def main(infile, outfile, iterations):
    b = blur.blur()
    img = misc.imread(infile, mode='RGB')
    (height, width, channels) = img.shape
    blurred = b.main(iterations, img)
    w = png.Writer(width, height, greyscale=False, alpha=False, bitdepth=8)
    with open(outfile, 'wb') as f:
        w.write(f, numpy.reshape(blurred.astype(numpy.uint8), (height, width*3)))
コード例 #6
0
ファイル: blur-png.py プロジェクト: HIPERFIT/futhark-website
def main(infile, outfile, iterations):
    b = blur.blur()
    img = misc.imread(infile, mode='RGB')
    (height, width, channels) = img.shape
    blurred = b.main(iterations, img)
    # The .get() is to retrieve a Numpy array from the PyOpenCL array
    # being returned.
    misc.imsave(outfile, blurred.get().astype(numpy.uint8))
コード例 #7
0
    def testBlurDistanceIsSmall(self):
        n = 40
        A, b, x = blur.blur(n, 3, 0.8)
        diff = A * x - b
        sum_squares_diff = numpy.sum(diff ** 2) / (n ** 2)
        sum_squares_b = numpy.sum(b ** 2) / (n ** 2)
        epsilon = 0.01
        print("square error", sum_squares_b, sum_squares_diff, file=sys.stderr)

        self.assertGreater(epsilon * sum_squares_b, sum_squares_diff)
コード例 #8
0
def main():
    global OUTPUT_FILES
    use_squirrel = ("squirrel" in sys.argv)
    use_squirrel = True
    # Don't allow output if could not import matplotlib
    OUTPUT_FILES = ("output" in sys.argv) and ('plt' in globals())
    OUTPUT_FILES = True
    N = 128
    A, b, real_x = blur.blur(N, 3, 0.8, use_squirrel)
    if OUTPUT_FILES:
        blur.save_array_as_img(b, "blurred")
        blur.save_array_as_img(real_x, "real")
    solve_gradient_descent(use_squirrel, A, b)
    solve_conjugate_gradient_method(use_squirrel, A, b)
コード例 #9
0
 def testLineSearch(self):
     n = 50
     A, b, _ = blur.blur(n, 3, 0.7)
     search = q3_gradient_descent.GradientDescent(A, b)
     for i in xrange(20):
         print 'i', i
         x0 = numpy.random.normal(128, 50, size=n ** 2)
         self.assertEqual(b.shape, x0.shape)
         gradient_x0 = search.gradient(x0)
         best_alpha = search.line_search(x0, gradient_x0)
         value_at_alpha = search.value(x0 + best_alpha * gradient_x0)
         print 'best_alpha', best_alpha
         for other_alpha in (best_alpha * 0.98, best_alpha * 1.02):
             print other_alpha / best_alpha
             value_at_other_alpha = search.value(x0 + other_alpha * gradient_x0)
             print value_at_other_alpha, value_at_alpha
             self.assertGreater(value_at_other_alpha, value_at_alpha)
コード例 #10
0
 def testConverge(self):
     n = 128
     A, b, real_x = blur.blur(n, 3, 0.8)
     search = q3_gradient_descent.GradientDescent(A, b)
     x0 = numpy.zeros(b.shape)
     num_iters = 100
     x = x0
     gradient_norms = []
     values = []
     for i in xrange(num_iters):
         gradient = search.gradient(x)
         gradient_norms.append(numpy.linalg.norm(gradient))
         values.append(search.value(x))
         x = search.step(x, gradient)
     gradient_x = search.gradient(x)
     gradient_size = numpy.linalg.norm(gradient_x)
     epsilon = 10
     self.assertGreater(epsilon, gradient_size)
コード例 #11
0
ファイル: sharpen.py プロジェクト: jamesh1999/Programming
def getMask(img):
    blurred = blur.blur(img, RADIUS)
    mask = img.copy()

    size = img.get_size()

    for x in range(size[0]):
        for y in range(size[1]):
            old = mask.get_at((x, y))
            blurred_col = blurred.get_at((x, y))
            mask.set_at(
                (x, y),
                (
                    min(math.sqrt((old[0] - blurred_col[0]) ** 2) * MASK, 255),
                    min(math.sqrt((old[1] - blurred_col[1]) ** 2) * MASK, 255),
                    min(math.sqrt((old[2] - blurred_col[2]) ** 2) * MASK, 255),
                ),
            )

    return mask
コード例 #12
0
 def testGradient(self):
     n = 50
     A, b, _ = blur.blur(n, 3, 0.7)
     search = q3_gradient_descent.GradientDescent(A, b)
     x0 = numpy.random.normal(128, 50, size=n ** 2)
     h = numpy.zeros(shape=x0.shape)
     f_x0 = search.value(x0)
     gradient_x0 = search.gradient(x0)
     num_tests = 20
     epsilon = 0.01
     delta = numpy.linalg.norm(gradient_x0) / gradient_x0.size * 0.1
     for i in xrange(num_tests):
         print 'i', i
         coordinate = numpy.random.randint(0, len(x0))
         h[coordinate] += epsilon
         f_delta = search.value(x0 + h) - f_x0
         gradient_approx = f_delta / epsilon
         print gradient_approx, gradient_x0[coordinate]
         h[coordinate] -= epsilon
         self.assertAlmostEqual(gradient_approx, gradient_x0[coordinate], delta=delta)
コード例 #13
0
def main():
    n = 128
    A, b, real_x = blur.blur(n, 3, 0.8)
    x0 = numpy.zeros(b.shape)
    b_new = A.T.dot(b)
    search = ConjugateGradient(A, b_new, x0)
    num_iters = 100

    gradient_norms = []
    values = []
    for i in xrange(num_iters):
        gradient = search.gradient()
        gradient_norms.append(numpy.linalg.norm(gradient))
        values.append(search.value())
        search.step()
    x = search.state()
    plt.plot(values[2:], 'ro')
    plt.savefig('values_cgm.png')
    plt.cla()
    plt.plot(gradient_norms[2:], 'b+')
    plt.savefig('gradient_norms_cgm.png')
    blur.save_array_as_img(b, "converge_test_b_cgm")
    blur.save_array_as_img(x, "converge_test_found_x_cgm")
    blur.save_array_as_img(real_x, "converge_test_real_x_cgm")
コード例 #14
0
import Contrasts
import HSVcounts

root_train = 'E:/ImageDataset_AVA/train/'
root_test = 'E:/ImageDataset_AVA/test/'
paths_train, counts_train = getPath.getPath(root_train)
paths_test, counts_test = getPath.getPath(root_test)

root_trainhigh = 'E:/ImageDataset_AVA/train/train_high'
root_trainlow = 'E:/ImageDataset_AVA/train/train_low'
root_testhigh = 'E:/ImageDataset_AVA/test/test_high'
root_testlow = 'E:/ImageDataset_AVA/test/test_low'

paths_trainhigh, counts_trainhigh = getPath.getPath(root_trainhigh)
paths_trainlow, counts_trainlow = getPath.getPath(root_trainlow)
paths_testhigh, counts_testhigh = getPath.getPath(root_testhigh)
paths_testlow, counts_testlow = getPath.getPath(root_testlow)

layoutComposition.layout(paths_trainhigh, paths_testhigh, paths_trainlow,
                         paths_testlow, paths_train, paths_test)
edgeComposition.EC(paths_trainhigh, paths_testhigh, paths_trainlow,
                   paths_testlow, paths_train, paths_test)

GT_layout.GT_layout(paths_train, paths_test)
GT_edge.GT_edge(paths_train, paths_test)
blur.blur(paths_train, paths_test)
dark.dark(paths_train, paths_test)
Contrasts.contrast(paths_train, paths_test)
HSVcounts.hsvcounts(paths_train, paths_test)

#colorPalette.colorPalette(paths_train,paths_test)
コード例 #15
0
parser.add_argument('--color_filter', action='store_true')
parser.add_argument('--color',
                    help='red,green,blue,brown',
                    type=str,
                    default="red")
parser.add_argument("input_file", help="The input image file.")
parser.add_argument("output_file", help="The output image file.")
args = parser.parse_args()

img = imageIO.readImage(args.input_file)

if img is not None:
    startTime = time.time()
    log.status("proccessing image")
    if args.blur:
        blurImage = blur(img, args.sigma)
        imageIO.writeImage(blurImage, args.output_file)
    elif args.edge:
        edgeImage = edgeDetection(img)
        imageIO.writeImage(edgeImage, args.output_file)
    elif args.invert_colors:
        invertImage = basicFilters.invertColors(img)
        imageIO.writeImage(invertImage, args.output_file)
    elif args.grayscale:
        grayscaleImage = basicFilters.grayscaleFilter(img)
        imageIO.writeImage(grayscaleImage, args.output_file)
    elif args.color_filter:
        color = colors.getColor(args.color)
        if color is not None:
            colorImage = basicFilters.colorFiler(img, color)
            imageIO.writeImage(colorImage, args.output_file)
コード例 #16
0
def main(infile, outfile, iterations):
    b = blur.blur()
    img = misc.imread(infile, mode='RGB')
    (height, width, channels) = img.shape
    blurred = b.main(iterations, img)
    misc.imsave(outfile,blurred.get())
コード例 #17
0
ファイル: image_blur_parallel.py プロジェクト: fangohr/mpimag
)

# Halo part two: and repeat in opposite direction
cart_comm.Sendrecv(
    sendbuf=imgLocal[xGhostsAbove : xGhostsAbove + blur_factor],
    dest=above_rank,
    recvbuf=imgLocal[xGhostsAbove + xLocal :],
    source=below_rank,
)

# -----------------------------------------------------------------------------
# Blur, plot and save local data
# -----------------------------------------------------------------------------

# blurring including blurred ghosts
imgLocalBlurred = blur(imgLocal, blur_factor=blur_factor)

f, axarr = plt.subplots(2)

axarr[0].imshow(imgLocal)
axarr[0].set_title("Original Image, rank {}".format(rank))

axarr[1].imshow(imgLocalBlurred)
axarr[1].set_title("Blurred Image, rank {}".format(rank))

# turn off axis
axarr[0].get_xaxis().set_visible(False)
axarr[0].get_yaxis().set_visible(False)
axarr[1].get_xaxis().set_visible(False)
axarr[1].get_yaxis().set_visible(False)
コード例 #18
0
 def applyBlur(self):
     self._blur = blur.blur(self._picref)
     self._pixref = self._blur.load()  # Override
コード例 #19
0
import pygame
import sys
import blur

pygame.init()

canvas = pygame.display.set_mode([400, 400], pygame.NOFRAME)

HWND = pygame.display.get_wm_info()["window"]

blur.blur(HWND)

while True:
    pygame.display.update()
    canvas.fill([0, 0, 0])
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()

    screen = pygame.Surface([400, 400])

    # pygame.display.

    pygame.draw.circle(screen, [255, 0, 0], [100, 100], 50)

    canvas.blit(screen, [0, 0], special_flags=(pygame.BLEND_RGBA_ADD))

コード例 #20
0
def blurButton():
    blur.blur()
コード例 #21
0
ファイル: image_blur_serial.py プロジェクト: fangohr/mpimag
import matplotlib.pyplot as plt
import numpy as np
from skimage import io

from blur import blur

#---------------------------------------------
# greyscale image blur
#---------------------------------------------

blur_factor = 3

image = io.imread("start.png")
image_blurred = blur(image, blur_factor=blur_factor)

# create plot comparing original and blurred image
f, axarr = plt.subplots(2)

axarr[0].imshow(image, cmap=plt.cm.Greys_r)
axarr[0].set_title('Original Image')

axarr[1].imshow(image_blurred, cmap=plt.cm.Greys_r)
axarr[1].set_title('Blurred Image')

# turn off axis
axarr[0].get_xaxis().set_visible(False)
axarr[0].get_yaxis().set_visible(False)
axarr[1].get_xaxis().set_visible(False)
axarr[1].get_yaxis().set_visible(False)

f.savefig('image_blur_compare_greyscale.png')
コード例 #22
0
import numpy as np
import cv2
from blur import blur
"""
image = cv2.imread("test.jpg")
new_image = blur(image, [(0,0,image.shape[0],image.shape[1])], 10)

cv2.imshow("image", image)
cv2.imshow("new", new_image)

cv2.waitKey()
"""

image = cv2.imread("test.jpg")
districts = [(800, 1400, 400, 400), [100, 1400, 300, 300]]
new_image = blur(image, districts, 10)

i = 0
for district in districts:
    cv2.imshow(
        "image" + str(i), image[district[0]:district[0] + district[2],
                                district[1]:district[1] + district[3], :])
    cv2.imshow(
        "new" + str(i), new_image[district[0]:district[0] + district[2],
                                  district[1]:district[1] + district[3], :])
    i += 1

cv2.waitKey()
コード例 #23
0
desampleTime = np.zeros(200)
desampleRealSignal = np.zeros(200)
realSignal = np.transpose(np.matrix(realSignal))
for i in range(0, 200):
    desampleTime[i] = t[i * 5]
    desampleRealSignal[i] = realSignal[i * 5]

#Signal: sinusoid1 50 Hz, amplitude 0.7 ; sinudois2 120 Hz, amplitude1
#s=np.zeros(1000)
#for i in range (0,999):
#   s[i]=(0.7*math.sin(2*math.pi*50*t[i]) + math.sin(2*math.pi*120*t[i]))

##Blur it
(desampleConvolvedNoise, A, kernel, sigma, convolvedNoise,
 desampleConvolved) = blur(t, realSignal)
desampleRealSignal = np.transpose(np.matrix(desampleRealSignal))
onlyNoisy = desampleRealSignal + np.transpose(
    np.matrix(np.random.normal(0, 1, 200)))

# TwIST parameters

#Empirical setting for smoothing parameter, tau
#tau = 2*math.e**-2*sigma/(0.56**2)
#lamb=1e-4;
# TwIST is not very sensitive to this parameter
# rule of thumb: lam1=1e-4 for severyly ill-conditioned% problems
#              : lam1=1e-1 for mildly  ill-conditioned% problems
#              : lam1=1    when A = Unitary matrix

#bestLamb=denoiseCheck(realSignal)
コード例 #24
0
ファイル: image_blur_parallel.py プロジェクト: fangohr/mpimag
                   dest=below_rank,
                   recvbuf=imgLocal[0:xGhostsAbove],
                   source=above_rank)

# Halo part two: and repeat in opposite direction
cart_comm.Sendrecv(sendbuf=imgLocal[xGhostsAbove:xGhostsAbove + blur_factor],
                   dest=above_rank,
                   recvbuf=imgLocal[xGhostsAbove + xLocal:],
                   source=below_rank)

#-----------------------------------------------------------------------------
# Blur, plot and save local data
#-----------------------------------------------------------------------------

# blurring including blurred ghosts
imgLocalBlurred = blur(imgLocal, blur_factor=blur_factor)

f, axarr = plt.subplots(2)

axarr[0].imshow(imgLocal)
axarr[0].set_title('Original Image, rank {}'.format(rank))

axarr[1].imshow(imgLocalBlurred)
axarr[1].set_title('Blurred Image, rank {}'.format(rank))

# turn off axis
axarr[0].get_xaxis().set_visible(False)
axarr[0].get_yaxis().set_visible(False)
axarr[1].get_xaxis().set_visible(False)
axarr[1].get_yaxis().set_visible(False)
コード例 #25
0
for n in range(len(checkerboard_Imgs)):
    if n == 0:
        CornerListSortedXY_stacked = []

    filename = filename_Imgs[n]
    img = checkerboard_Imgs[n]

    offset = int(windowSize / 2)

    x_size = filename.shape[1] - offset
    y_size = filename.shape[0] - offset

    nul = np.zeros((img.shape[0], img.shape[1]), np.uint8)

    # mean blur
    blur = bl.blur(filename)

    # Partial differentiation hvor ** = ^2
    Iy, Ix = np.gradient(blur)

    # Representation of the M matrix
    Ixx = Ix ** 2
    Ixy = Iy * Ix
    Iyy = Iy ** 2

    CornerCoordinate = []
    # Fra offset til y_size og offset til x_size
    print("Start running corner detection . . . ")

    for y in range(offset, y_size):
        for x in range(offset, x_size):