当前位置: 首页>>代码示例>>Python>>正文


Python Image.resize方法代码示例

本文整理汇总了Python中SimpleCV.Image.resize方法的典型用法代码示例。如果您正苦于以下问题:Python Image.resize方法的具体用法?Python Image.resize怎么用?Python Image.resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleCV.Image的用法示例。


在下文中一共展示了Image.resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_blob

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
def query_blob(id):
    blob = Image("static\\img\\%d.jpg" % id).crop(
        int(request.form["x"]), int(request.form["y"]), int(request.form["width"]), int(request.form["height"])
    )
    if blob and "SK_MODEL" in app.config:
        if blob.height > blob.width:
            blob = blob.resize(h=app.config["PATCH_SIZE"])
        else:
            blob = blob.resize(w=app.config["PATCH_SIZE"])
        blob = blob.embiggen((app.config["PATCH_SIZE"], app.config["PATCH_SIZE"]))
        np_img = blob.getGrayNumpy().transpose().reshape(-1)
        pred = labels.inverse_transform(sk_model.predict(np_img))[0]
        return jsonify(prediction=pred)
    else:
        return jsonify(prediction="")
开发者ID:rolisz,项目名称:image_annotator,代码行数:17,代码来源:flask_annotator.py

示例2: Fish

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
class Fish():
    def __init__(self, image_url, mask_url):
        self.position = (10, 10)
        self.last_position = (0, 0)
        self.draw_position = (0, 0)
        self.direction = "left"
        self.orig_image = Image(image_url)
        self.orig_mask = Image(mask_url).invert()
        self.draw_image = self.orig_image.copy()
        self.draw_mask = self.orig_mask.copy()

    def update(self, x, y, w, h):
        self.update_dir()

        self.position = (x, y)

        self.draw_image = self.orig_image.resize(w=w, h=h)
        self.draw_mask = self.orig_mask.resize(w=w, h=h)
 
        if self.direction == "left":
            self.draw_position = self.position
        
        elif self.direction == "right":
            # TODO: setup offsets here for image when facing another direction
            self.draw_position = (self.position[0] + 0, self.position[1] + 0)
            pass

    def update_dir(self):
        hor_change = self.position[0] - self.last_position[0]
        # if the difference is more than 10 pixels
        if abs(hor_change) > 5:
            # TODO: can optimise this slightly by checking if == left && horchange is positive
            # (so doesnt flip it every time over 10 pixels in the same direction)
            if self.direction == "left":
                self.direction = "right"
                self.draw_image = self.orig_image.flipHorizontal().copy()
                self.draw_mask = self.orig_mask.flipHorizontal().copy()
            elif self.direction == "right":
                self.direction = "left"
                self.draw_image = self.orig_image.copy()
                self.draw_mask = self.orig_mask.copy()
            self.last_position = self.position

    def draw(self, parent):
        #self.draw_image.save(canvas)
        print self.draw_image
        print self.draw_position
        parent.canvas = parent.canvas.blit(self.draw_image, pos=self.draw_position, alphaMask=self.draw_mask)
开发者ID:mcteo,项目名称:interactive-fish-tank,代码行数:50,代码来源:fish_tank.py

示例3: parse_frame

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
def parse_frame(img):
    """
    Parses a SimpleCV image object of a frame from Super Hexagon.
    Returns a ParsedFrame object containing selected features.
    """

    img

    # helper image size variables
    w,h = img.size()
    midx,midy = w/2,h/2

    # Create normalized images for targeting objects in the foreground or background.
    # (This normalization is handy since Super Hexagon's colors are inverted for some parts of the game)
    # fg_img = foreground image (bright walls, black when binarized)
    # bg_img = background image (bright space, black when binarized)
    fg_img = img
    if sum(img.binarize().getPixel(midx,midy)) == 0:
        fg_img = img.invert()
    bg_img = fg_img.invert()

    # We need to close any gaps around the center wall so we can detect its containing blob.
    # The gaps are resulting artifacts from video encoding.
    # The 'erode' function does this by expanding the dark parts of the image.
    bimg = bg_img.binarize()
    bimg = black_out_GUI(bimg)

    blobs = bimg.findBlobs()
    cursor_blob = get_cursor_blob(blobs, h, midx, midy)

    if cursor_blob:
        cursor_point = map(int, cursor_blob.centroid())
        cursor_r, cursor_angle = cart_to_polar(cursor_point[0] - midx, midy - cursor_point[1])

        cursor_angle = int(cursor_angle * 360/ (2 * pi))
        cursor_angle = 180 - cursor_angle
        if cursor_angle < 0:
            a += 360

        bimg = black_out_center(bimg, cursor_r).applyLayers()
        arr = bimg.resize(100).getGrayNumpy() > 100
        rot_arr = arr_to_polar(arr)
        rot_img = Image(PIL.Image.fromarray(np.uint8(np.transpose(rot_arr)*255))).dilate(iterations=3)
        rot_arr = rot_img.getGrayNumpy() > 100
        rot_img = rot_img.resize(400).flipVertical()
        return ParsedFrame(img, bimg, arr, rot_arr, rot_img, cursor_r, cursor_angle)
    else:
        return None
开发者ID:david-crespo,项目名称:py-super-hexagon,代码行数:50,代码来源:parse.py

示例4: generate_negative_examples

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
def generate_negative_examples(argv):
    image_dirs = argv[4:]

    images = []
    for image_dir in image_dirs:
        # grab all images
        images.extend(glob(path.join(image_dir, '*.jpg')))
        images.extend(glob(path.join(image_dir, '*.JPG')))
        images.extend(glob(path.join(image_dir, '*.png')))
        images.extend(glob(path.join(image_dir, '*.PNG')))

    images = set(images)

    if len(images) < N:
        print 'Not enough images! (got %d, need %d)' % (len(images), N)
        return

    width, height, output_dir = int(argv[1]), int(argv[2]), argv[3]

    if path.exists(output_dir) and (not path.isdir(output_dir)):
        print '%s is not a directory' % output_dir
        return
    elif not path.exists(output_dir):
        os.mkdir(output_dir)

    for i in xrange(N):
        print 'generating %3d/%d...' % ((i+1), N)
        img = Image(images.pop())
        img = img.grayscale()
        if img.width > MAX_WIDTH:
            img = img.resize(MAX_WIDTH, int(1.0*img.height*MAX_WIDTH/img.width))

        x, y = random.randint(0, img.width-width), random.randint(0, img.height-height)
        img = img.crop(x, y, width, height)

        path_to_save = path.join(output_dir, '%d.png' % (i+1))
        img.save(path_to_save)
开发者ID:kavinyao,项目名称:airplane-recognition,代码行数:39,代码来源:generate_negative.py

示例5: fancify

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]

#.........这里部分代码省略.........
                    bottom_of_nose = y_nose + (nose.height() * 4 / 5)
                    top_of_mouth = y_mouth
                    # if top_of_mouth > bottom_of_nose:
                    #    top_of_mouth = bottom_of_nose
                    y_must = y_face + ((bottom_of_nose + top_of_mouth) / 2) - (cur_stache.height / 2)

                    middle_of_nose = nose.x
                    middle_of_mouth = mouth.x
                    x_must = x_face + ((middle_of_nose + middle_of_mouth) / 2) - (cur_stache.width / 2)

                if right_eye:
                    x_right_eye = right_eye.x - (right_eye.width() / 2)
                    y_right_eye = right_eye.y - (right_eye.height() / 2)

                    # Setup Monocle Image
                    cur_mono = monocle.copy()
                    scale_factor = ((right_eye.width() / 65.0) + (face.width() / 200.0)) / 2.0
                    cur_mono = cur_mono.scale(scale_factor)
                    mono_mask = cur_mono.createAlphaMask(hue_lb=0, hue_ub=100).invert()

                    # Calculate Monocle Position
                    x_mono = x_face + x_right_eye
                    y_mono = y_face + y_right_eye
                    img = img.blit(cur_mono, pos=(x_mono, y_mono), alphaMask=mono_mask)

                img = img.blit(cur_stache, pos=(x_must, y_must), alphaMask=stache_mask)

                if debug:
                    noselayer = DrawingLayer((img.width, img.height))
                    nosebox_dimensions = (nose.width(), nose.height())
                    center_point = (face.x - (face.width() / 2) + nose.x,
                                    face.y - (face.height() / 2) + nose.y)
                    nosebox = noselayer.centeredRectangle(center_point, nosebox_dimensions, width=3)
                    img.addDrawingLayer(noselayer)
                    img = img.applyLayers()

            else:
                print "Face culled:"
                if not nose:
                    print "  No Nose"
                if not mouth:
                    print "  No mouth"
                if not right_eye:
                    print "  No right eye"
                    print

            if debug:
                face_left_edge = face.x - (face.width() / 2)
                face_top_edge = face.y - (face.height() / 2)

                facelayer = DrawingLayer((img.width, img.height))
                facebox_dimensions = (face.width(), face.height())
                center_point = (face.x, face.y)
                facebox = facelayer.centeredRectangle(center_point, facebox_dimensions, Color.BLUE)
                img.addDrawingLayer(facelayer)

                if noses:
                    for nose in noses:
                        noselayer = DrawingLayer((img.width, img.height))
                        nosebox_dimensions = (nose.width(), nose.height())
                        center_point = (face.x - (face.width() / 2) + nose.x,
                                    face.y - (face.height() / 2) + nose.y)
                        nosebox = noselayer.centeredRectangle(center_point, nosebox_dimensions)
                        img.addDrawingLayer(noselayer)

                if mouths:
                    for mouth in mouths:
                        mouthlayer = DrawingLayer((img.width, img.height))
                        mouthbox_dimensions = (mouth.width(), mouth.height())
                        center_point = (face.x - (face.width() / 2) + mouth.x,
                                face.y - (face.height() / 2) + mouth.y)
                        mouthbox = mouthlayer.centeredRectangle(center_point, mouthbox_dimensions, Color.GREEN)
                        img.addDrawingLayer(mouthlayer)

                if eyes:
                    for right_eye in eyes:
                        right_eyelayer = DrawingLayer((img.width, img.height))
                        right_eyebox_dimensions = (right_eye.width(), right_eye.height())
                        right_eye_center_point = (face_left_edge + right_eye.x, face_top_edge + right_eye.y)
                        right_eyebox = right_eyelayer.centeredRectangle(right_eye_center_point, right_eyebox_dimensions)
                        img.addDrawingLayer(right_eyelayer)

                img = img.applyLayers()

    img = img.scale(0.5)
    w_ratio = img.width / 800.0
    h_ratio = img.height / 600.0

    if h_ratio > 1.0 or w_ratio > 1.0:
        if h_ratio > w_ratio:
            img = img.resize(h=600)
        else:
            img = img.resize(w=800)

    output = StringIO.StringIO()
    img.getPIL().save(output, format="JPEG") #, quality=85, optimize=True)
    img_contents = output.getvalue()

    mimetype = "image/jpeg"
    return app.response_class(img_contents, mimetype=mimetype, direct_passthrough=False)
开发者ID:chadnickbok,项目名称:fancify,代码行数:104,代码来源:fancify.py

示例6: scale_down

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
	def scale_down(self, img_path):
		new_file_path = self.nfn('scale-down')
		img = Image(img_path)
		img = img.resize(h=1024)
		img.save(new_file_path)
		return new_file_path
开发者ID:jenglert,项目名称:cleat-align,代码行数:8,代码来源:shoe.py

示例7: rotateAntiClockWise

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
def rotateAntiClockWise( image, min_angle, max_angle ):
    x = image.width / 2
    y = image.height / 2
    index = os.path.basename( image.filename ).split( "." )[ 0 ][ -1 ]
    for angle in xrange( min_angle, max_angle + 1 ):
        rotated_image = image.rotate( angle, ( x, y ) )
        rotated_image.resize( 64, 64 )        
        rotated_image.save( str( index ) + str( angle ) + "l.jpg" )
        print "rotated %s through %s angle,anticlockwise." % ( index, angle )


size = 10
filename = ""
target = "dataset"
image_list = []
for index in xrange( 0, size ):
    filename = "../" + str( index ) + ".jpg"
    image = Image( filename )
    image.resize( 64, 64 ).save( str( index ) + ".jpg" )
    image_list.append( image.filename )
    print "%s thumbnail created." % ( image.filename )

# create rotated images.
# functions will create images at the current directory labeled by number and angle.format: [ angle ][ number ].jpg
os.chdir( target )
for image in image_list:
    rotateClockWise( Image( image ), min_angle = 0, max_angle = 45  )    
    rotateAntiClockWise( Image( image ), min_angle = 0, max_angle = 45 )

开发者ID:bhimsen92,项目名称:digit-sorting,代码行数:30,代码来源:create_dataset.py

示例8: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
from SimpleCV import Image
img = Image('ahmedabad.jpg')
bigImg = img.resize(img.width * 2, img.height)
bigImg.show()
raw_input()
开发者ID:SamarthShah,项目名称:SciPy.In-2013,代码行数:7,代码来源:2-Image+Resize.py

示例9: Camera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
from SimpleCV import Image, Camera, Display
from time import sleep

camera = Camera(prop_set={'width':320, 'height':240})
display = Display(resolution=(320, 240))

mustacheImage = Image("/Users/jharms/Desktop/Mustache.jpg")
mustacheImage = mustacheImage.resize(w=120, h=80)
stacheMask = mustacheImage.createBinaryMask(color1=(10,10,10), color2=(255,255,255))
stacheMask = stacheMask.invert()
#i.save(myDisplay)

def mustachify(frame):
    faces = None
    print frame.listHaarFeatures()
    faces = frame.findHaarFeatures('face')
    if faces:
        for face in faces:
            print "Gesicht bei " + str(face.coordinates())
            frame = frame.blit(mustacheImage, pos=face.coordinates(), mask=stacheMask)
    return frame
    
while not display.isDone():
    frame = camera.getImage()
    frame = mustachify(frame)
    frame.save(display)
    sleep(.1)
开发者ID:tyunkeow,项目名称:raspi_python,代码行数:29,代码来源:camera.py

示例10: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
from SimpleCV import Image
import time
img = Image('ladies.jpg')
#img.live()
# Gets the information for the pixel located at
# x coordinate = 120, and y coordinate = 150
pixel = img[120, 150]
# or
pixelll = img.getPixel(120, 150)
print pixel
print pixelll
print img.getGrayPixel(120, 150)

print img.height
print img.width

# Retrieve the RGB triplet from (120, 150)
(red, green, blue) = img.getPixel(223, 82)
# Change the color of the pixel+
img[215:230, 82:85] = (0, 0, 0)
# Resize the image so it is 5 times bigger then it's original size
bigImg = img.resize(img.width*1, img.height*1)
bigImg.show()
#img.show()
time.sleep(10)
开发者ID:popsonebz,项目名称:lesson1,代码行数:27,代码来源:helloWorld11.py

示例11: ROI

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
roi = ROI(img.width*0.45,img.height*0.45,img.width*0.1,img.height*0.1,img)
tct.train(cam,roi=roi,maxFrames=250,pkWndw=20)

# Matplot Lib example plotting
plotc = {'r':'r','g':'g','b':'b','i':'m','h':'y'}
for key in tct.data.keys():
    plt.plot(tct.data[key],plotc[key])
    for pt in tct.peaks[key]:
        plt.plot(pt[0],pt[1],'r*')
    for pt in tct.valleys[key]:
        plt.plot(pt[0],pt[1],'b*')
    plt.grid()
plt.show()

disp = Display((800,600))
while disp.isNotDone():
    img = cam.getImage()
    result = tct.recognize(img)
    plt.plot(tct._rtData,'r-')
    plt.grid()
    plt.savefig('temp.png')
    plt.clf()
    plotImg = Image('temp.png')    
    
    roi = ROI(img.width*0.45,img.height*0.45,img.width*0.1,img.height*0.1,img)
    roi.draw(width=3)
    img.drawText(str(result),20,20,color=Color.RED,fontsize=32)
    img = img.applyLayers()
    img = img.blit(plotImg.resize(w=img.width,h=img.height),pos=(0,0),alpha=0.5)
    img.save(disp)
开发者ID:AndersonYangOh,项目名称:SimpleCV,代码行数:32,代码来源:TestTemporalColorTracker.py

示例12: Rho

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
#se prueba distintos metodos para ver si detecta los bellos en la piel
ed=imagen.edges()
edg=imagen+ed
edg.save('bordes_edge.png')

grad = imagen.morphGradient()
grd = imagen+grad
grd.save('bordes_gradiente.png')

lineas=imagen.findLines()
lineas.draw(Color.RED,width=3)
#imagen.show()
imagen.save("linbeas.png")

resu = imagen.resize(320,240) #se redefine la imagen para que tenga un menor tiempo 
                             #de procesamiento
gray=resu.grayscale()
inv=gray.invert()
sumimg=resu+inv
res=(resu*1.5)-(gray/2)
res.save('muestras/imagen_tratada.png')

[red, green, blue]=res.splitChannels(False)

def Rho(A,B): # A es el color del lunar y B es el color de la piel
   Ar=A[0]; Ag=A[1]; Ab=A[2]
   Br=B[0]; Bg=B[1]; Bb=B[2]
   r=np.array([Ar/Br,Ar/Bg,Ar/Bb,Ag/Br,Ag/Bg,Ag/Bb,Ab/Br,Ab/Bg,Ab/Bb])

   return r
开发者ID:nashoalfonso,项目名称:PDI,代码行数:32,代码来源:l4.py

示例13: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
# -*- coding: utf-8 -*-

from SimpleCV import Image

imgJPG = Image("ex8.jpg")
imgJPG.save("ex8PNG.png")


imgPNG = Image("ex8PNG.png")
imgPNG.resize(800,600).show()



开发者ID:italofernandes84,项目名称:Python-SimpleCV_Course_Examples,代码行数:12,代码来源:ex8.py

示例14: __init__

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
class Window2:
    generation = 0

    def __init__(self, filename, scale=1):
        filename = os.path.expanduser(filename)
        self.img = Image(filename)
        self.max_x, self.max_y = self.img.width, self.img.height
        self.scale = scale

        self.array_map = np.array([[0 for y in range(self.max_y)] for x in range(self.max_x)])
        for x in range(self.max_x):
            for y in range(self.max_y):
                pixel = self.img.getPixel(x, y)
                self.array_map[x][y] = (pixel == (255, 255, 255))

        # scale image
        self.img = self.img.resize(self.img.width*scale, self.img.height*scale)
        self.img_size = self.img.width, self.img.height

        self.display = Display(self.img_size)
        self.img.save(self.display)

    def dot(self, p, color=Color.WHITE, size=0):
        x, y = p[0], p[1]
        #print "Drawing robot particle at {}, {}".format(x, y)
        if x < 0 or x >= self.max_x:
            print "Oh my god! x=", x
            raise RuntimeError
        if y < 0 or y >= self.max_y:
            print "Oh shit! y=", y
            raise RuntimeError
        else:
            self.img.dl().circle(center=(x*self.scale, y*self.scale), radius=size, color=color, width=1, filled=True)

    def dot_red(self, p, color=Color.RED):
        self.dot(p, color, 2)

    def dots(self, coords, color=Color.WHITE, size=0):
        for (x, y) in coords:
            self.dot((x, y), color, size)

    def clear(self):
        self.img = Image(self.img_size)
        #self.display.clear()
        self.img.save(self.display)

    def clear_dl(self):
        self.img.clearLayers()
        self.img.save(self.display)

    def show(self):
        self.img.save(self.display)
        self.generation += 1
        print "Generation = {}".format(self.generation)
        self.wait_for_mouse()
        print "Mouse pressed!"

    def draw_robot(self, position, orientation):
        color = Color.RED
        #self.img.drawRectangle(p[0], p[1], 20, 40, color, 1)
        self.dot(position, color, 2)

        length = 20
        bx = int(round(position[0] + cos(orientation) * length))
        by = int(round(position[1] + sin(orientation) * length))

        self.vector(position, orientation, length, detect_collision=False, color=color)
        self.vector((bx, by), orientation - 3*pi/4, length=8, detect_collision=False, color=color)
        self.vector((bx, by), orientation + 3*pi/4, length=8, detect_collision=False, color=color)

    def vector(self, x, orientation, length, detect_collision=True, color=Color.FORESTGREEN):
        bx = int(round(x[0] + cos(orientation) * length))
        by = int(round(x[1] + sin(orientation) * length))
        #self.dot_red((bx, by))
        return self.line(x, (bx, by), detect_collision=detect_collision, color=color)
        #return bx, by

    # a = startpunkt, b = endpunkt
    #@profile
    def line(self, a, b, detect_collision=True, color=Color.BLUE):
        """http://en.wikipedia.org/wiki/Bresenham's_line_algorithm"""

        # performance => use local vars
        max_x = self.max_x
        max_y = self.max_y
        array_map = self.array_map

        x0, y0 = a
        x1, y1 = b
        dx = abs(x1-x0)
        dy = -abs(y1-y0)
        if x0 < x1:
            sx = 1
        else:
            sx = -1

        if y0 < y1:
            sy = 1
        else:
            sy = -1
#.........这里部分代码省略.........
开发者ID:tyunkeow,项目名称:raspi_python,代码行数:103,代码来源:robot_window.py

示例15: scale_down

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import resize [as 别名]
def scale_down(si, image_path):
	new_file_path = step_file_path(si, 'scale-down')
	img = Image(image_path)
	img = img.resize(h=1024)
	img.save(new_file_path)
	return new_file_path
开发者ID:jenglert,项目名称:cleat-align,代码行数:8,代码来源:align.py


注:本文中的SimpleCV.Image.resize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。