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)
示例#2
0
#! /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)
示例#3
0
#! /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([])
示例#4
0
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)
示例#5
0
#!/usr/bin/env python
#import the necessary packages

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)
plt.savefig("histogred.png")
示例#6
0
文件: Lab2.py 项目: nashoalfonso/PDI
#! /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')






示例#7
0


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)
示例#8
0
#! /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)
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()
from SimpleCV import Image
import time
img = Image('/home/pi/book/test_set/4.2.05.tiff')
img.show()
time.sleep(5)
img.grayscale().show()
time.sleep(5)
#!/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")
示例#12
0
from SimpleCV import Image
import time
img = Image('/home/pi/book/test_set/1.5.01.tiff')
img.grayscale().findCorners().show()
time.sleep(5)
示例#13
0
#! /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()
示例#14
0
#!/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: ")