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


Python Image.grayscale方法代码示例

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


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

示例1: generate_negative_examples

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [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

示例2: Camera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#! /usr/bin/python
#TODA  LAS FOTOS DEBEN TENER EL MISMO TEXTO ESCRITO SOLO SE CAMBIARA LA SUPERFICI
#DEL TEXTO
from SimpleCV  import Image, Camera, Display, time 
import matplotlib.pyplot as plt
#cam = Camera()
#asdf=cam.getImage()
#time.sleep(10)
#prueba=cam.getImage()
#prueba.save("prueba1.jpg")
prueba=Image("prueba1.jpg")
escalagris=prueba.grayscale()
escalagris.save("gray.jpg")
histograma=escalagris.histogram(255)
plt.subplot(4,1,1)
plt.plot(histograma)
plt.grid()
plt.title("Histograma Grayscale cuadriculado")
#una vez echo el filtro en gris se procede a hacerlo en RGB(RED GREEn BLUE)
(red,green,blue)=prueba.splitChannels(False)
red_histogram=red.histogram(255)
plt.subplot(4,1,2)
plt.plot(red_histogram)
plt.grid()
plt.title("Histograma red")
green_histogram=green.histogram(255)
plt.subplot(4,1,3)
plt.plot(green_histogram)
plt.grid()
plt.title("Histograma green")
blue_histogram=blue.histogram(255)
开发者ID:yavier123,项目名称:labpdi2,代码行数:33,代码来源:pdilab22.py

示例3: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#! /usr/bin/env python


from SimpleCV import Camera, Display, Image
import time
import matplotlib.pyplot as plt

# Fotos con letras
#     Foto con fondo Cuadrada
imgc = Image('/home/pi/Documents/Fotos_cuadradas/Cuadraditos.png')
imgGrayc = imgc.grayscale()
imgGrayc.save('/home/pi/Documents/Fotos_cuadradas/Cuadraditogris.png')

plt.figure()
histc = imgGrayc.histogram(255)
plt.subplot(3,1,1)
plt.title("Cuadrados gris")
plt.stem(histc)
plt.yticks([])
plt.axis('tight')

#     Foto con fondo Blanca
imgb = Image('/home/pi/Documents/Fotos_blancas/blanca.png')
imgGrayb = imgb.grayscale()
imgGrayb.save('/home/pi/Documents/Fotos_blancas/blancagris.png')

histb = imgGrayb.histogram(255)
plt.subplot(3,1,2)
plt.title("Blanca girs")
plt.stem(histb)
plt.yticks([])
开发者ID:Nano1993,项目名称:Lab-2-PDI,代码行数:33,代码来源:Codigogris.py

示例4:

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
from sklearn.cluster import KMeans
import time
import matplotlib.pyplot as plt
import numpy as np

from SimpleCV import Image,Camera,Display,Image,Color


img=Image("lunarr2.jpg")#importamos la imagen a la cual deseamos determinarle los bordes
foto=img.show()




#imagen en escala de grises
imgGray=img.grayscale()
imgGray.save("grayLab2.png")
hist=imgGray.histogram(255)

plt.figure(1)
plt.plot(hist)
plt.savefig("histogray.png")


#imagen en escala RGB
(red,green,blue)=img.splitChannels(False)

#Histograma imagen RGB
red_histogram=red.histogram(255)
plt.figure(2)
plt.plot(red_histogram)
开发者ID:franmir,项目名称:lab3-PDI,代码行数:33,代码来源:Bordes.py

示例5: Camera

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


c = Camera()

def foto(c):
    img = c.getImage()
    img.show()
    return img


#a=foto(c)


a=Image("hola42AGray.png")
imgGray=a.grayscale()
#imgGray.save("hola42AGray.png")
#a.save("holaA42.png")

def histograma(hist):
    
    hist=hist.histogram(255)
##    hist.save("hola4Hist.txt")
    pylab.plot(hist)
    pylab.draw()
    pylab.pause(0.0001)


b=histograma(imgGray)

(R,G,B)=a.splitChannels(False)
开发者ID:Wenarepo,项目名称:HOLArepo,代码行数:32,代码来源:cosa6.py

示例6: Camera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#! /usr/bin/env python

from SimpleCV import Image, Camera, Display, Image
import time
import matplotlib.pyplot as plt

cam = Camera()
img = cam.getImage()
img.save("cart.jpg")


imc = Image('cart.jpg')
imcGray = imc.grayscale()
imcGray.save('cartgris.jpg')

hist = imcGray.histogram(255)
plt.figure(1)
plt.stem(hist)
plt.axis('tight')
plt.savefig('hist.png')






开发者ID:nashoalfonso,项目名称:PDI,代码行数:22,代码来源:Lab2.py

示例7: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
from SimpleCV import Image
import cv2
import numpy as np
from sys import argv

if __name__ == "__main__":
    image_file = argv[1]

    # Load the Image
    raw_image = Image(image_file)

    # Remove color
    gray_image = raw_image.grayscale()

    # Smooth to remove speckle
    smooth_image = gray_image.gaussianBlur((5,5),0)

    # Convert to Numpy Array For OpenCV use
    cv_image = smooth_image.getGrayNumpyCv2()

    # Adaptive threshold does much better than linear
    raw_thresh_image = cv2.adaptiveThreshold(cv_image,255,1,1,11,2)

    # Convert back to a SimpleCV image
    thresh_image = Image(raw_thresh_image)

    # For some reason it gets rotated and flipped, reverse
    thresh_image = thresh_image.rotate90().flipVertical()

    # Find "blobs" which are interesting items in the image
    blobs = thresh_image.findBlobs()
开发者ID:jamescjackson,项目名称:cvarp-pytn,代码行数:33,代码来源:build_training_set.py

示例8: Image

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#!/usr/bin/python

from SimpleCV import Camera, Display, Image

img = Image("img4.png")
imggray =  img.grayscale().save("img4gray.png")
imggray = Image("img4gray.png")
(red, green, blue) = img.splitChannels(False)

# Edge detection with diferents algorithms on SCV.

# "Edges" Command.
imggray_edge = imggray.edges().save("img4gray_edges.png")
red_edge = red.edges().save("img4red_edges.png")
green_edge = green.edges().save("img4green_edges.png")
blue_edge = blue.edges().save("img4blue_edges.png")

# "morphGradient" Command
imggray_edge = imggray.morphGradient().save("img4gray_edges_morphGradient.png")
red_edge = red.morphGradient().save("img4red_edges_morphGradient.png")
green_edge = green.morphGradient().save("img4green_edges_morphGradient.png")
blue_edge = blue.morphGradient().save("img4blue_edges_morphGradient.png")

# "sobel" Command
imggray_edge = imggray.sobel().save("img4gray_edges_sobel.png")
red_edge = red.sobel().save("img4red_edges_sobel.png")
green_edge = green.sobel().save("img4green_edges_sobel.png")
blue_edge = blue.sobel().save("img4blue_edges_sobel.png")
开发者ID:Grupopdicyf,项目名称:PDI_2016,代码行数:30,代码来源:edge_detection_simplecv-commands.py

示例9: Camera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#! /usr/bin/python
from SimpleCV import Image, Camera, Color #nueva libreria color para los comandos de color
#cam = Camera()
#img = cam.getImage()
#img.save("lunar1.jpg")
pruebalunar=Image("lunar6nico.png") #nombre de lka imagen que quieres cargar
lunargris=pruebalunar.grayscale()
lunargris.save("fotoslunarprurba.png")
(red,green,blue)=pruebalunar.splitChannels(False) # la separo en RGB
red.save("fotoenrojo.png")
green.save("fotoenverde.png")
blue.save("fotoenazul.png")

#codigo para encontrarn manchas solo se a echo en escala de grises  
prueba69=green.binarize() #la binarizo por que se vera mejor asi 
mancha=prueba69.findBlobs() #ocupo el comando para encontrar lasmanchas (lunares)
mancha.show(Color.YELLOW)
prueba69.save("porfavorguardate3.png")


invertidos=green.invert()#se invierte la imagen para obtener manchas negras en la foto
blob=invertidos.findBlobs()#se ve si se encuentrasn las mannchas en la foto invertida
blob.show(width=2)
pruebalunar.addDrawingLayer(invertidos.dl())
pruebalunar.show()
pruebalunar.save("porfavorguardate2.png") #guardamos la imagen 


#enncontrar manchas por color especifico para el cual tenemos:
brown_distance=green.colorDistance(Color.BLACK).invert()##cmo buscamos de color negro , le pknemos black 
blobs2_=brown_distance.findBlobs()
开发者ID:yavier123,项目名称:lab3pdi2016,代码行数:33,代码来源:fotoslunar.py

示例10: Camera

# 需要导入模块: from SimpleCV import Image [as 别名]
# 或者: from SimpleCV.Image import grayscale [as 别名]
#!/usr/bin/python

from SimpleCV import Camera, Display, Image
import matplotlib.pyplot as plt
import time

cam = Camera()
img = cam.getImage().save("img.jpg")
img = Image("img.jpg")
img.show()
imgGray = img.grayscale().save("imgGray.jpg")
imgGray = Image("imgGray.jpg")
imgGray.show()
hist = imgGray.histogram(255)

(red, green, blue) = img.splitChannels(False)
red_histogram = red.histogram(255)
green_histogram = green.histogram(255)
blue_histogram = blue.histogram(255)
plt.figure(1)
plt.subplot(411)
plt.plot(hist)
plt.subplot(412)
plt.plot(red_histogram)
plt.subplot(413)
plt.plot(green_histogram)
plt.subplot(414)
plt.plot(blue_histogram)
plt.show()

print("Ingresar parametro para binarizar: ")
开发者ID:Grupopdicyf,项目名称:PDI_2016,代码行数:33,代码来源:Lab2PDI.py


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