예제 #1
0
class IPTestCase(unittest.TestCase):
    def setUp(self):
        self.IP = ImageProcessor()

    def testOneImage(self):
        s = self.IP.process_image(
            'https://realpython.com/images/blog_images/ocr/sample5.jpg')
        self.assertEqual(s, "1234567890", "wrong at testcase 1")

        # s = self.IP.process_image('agungsukses.png')
        # self.assertEqual(s, "*****@*****.**", "wrong at testcase 2")

    # def testOnDirectorySample(self):
    #     s = self.IP.process_images_from_dir("sample_images")
    #     file = open("sample.txt", "w")
    #     for key, val in s.items():
    #         file.write("{} = {}".format(key, val))
    #     file.close
    #
    def testOnDirectorySample2(self):
        s = self.IP.process_images_from_dir("samples_images2")
        file = open("sample222.txt", "w")
        for key, val in s.items():
            file.write("{} = {}".format(key, val))
        file.close
 def test_CCI_whiteImage(self):
     """ Test to verify that the CCI is almost equal to 1, given a white image """
     way=os.path.abspath("TestComponents/white.jpg")
     img = Image(way)
     processor = ImageProcessor(img)
     cci = processor.get_CCI()
     self.assertAlmostEqual(round(cci, 2), 0.99) # Because the circle in its edges has like a lighthing
예제 #3
0
    def run(self):
        '''
            This is the method that is ran when the thread is initially created, it loads the ML model. 
            It then continually, checks for motion and if detected, feeds the processed images through 
            the ML model to determine if a face is detected. If a face is detected then a notification 
            is created.
        '''
        model = load_model(join("..", "model", self.settings["ModelName"]))

        while True:
            if self.firebase.is_enabled():
                if self.motionSensor.is_motion_detected():
                    print("Motion Detected")
                    img = self.camera.get_image_from_camera()

                    MLSize = (self.settings["MLImageWidth"],
                              self.settings["MLImageHeight"])
                    partitionedImages = ImageProcessor.partitionImage(img, MLSize, self.settings["PartitionImageWidthDelta"],\
                        self.settings["PartitionImageHieghtDelta"],(self.settings["PartitionWidth"], self.settings["PartitionHeight"]))

                    # sometimes false results return x.xx E-16 therefore we set a threshold to bypass this
                    faceDetected = np.sum(
                        model.predict(np.array(partitionedImages))
                    ) > self.settings["FaceDetectionThreshold"]
                    print("Face Detected?: " + str(faceDetected))

                    # if a face is detected send a notification
                    if (faceDetected):
                        self.firebase.sendNotifications(
                            ImageProcessor.convertImageToString(img))
                        time.sleep(
                            self.settings["FaceDetectionNotificationDownTime"])
예제 #4
0
파일: main.py 프로젝트: Lynux2142/python_ai
def main():
    img = IP()
    array = img.load('./42AI.png')
    img.display(array)
    img.display(CF.invert(array))
    img.display(array)
    img.display(CF.to_grayscale(array, 'w'))
예제 #5
0
 def __init__(self):
     super().__init__()
     self.img_proc = ImageProcessor()
     self.label = QLabel()
     self.extensions = "*.png *.jpg *.jpeg *.tiff *.bmp *.gif *.tfrecords"
     self.info = None
     self.init_()
예제 #6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--f', type=str, help='RDT image file path')
    args = parser.parse_args()
    imgProc = ImageProcessor()
    # imgProc.captureRDT(INPUT_IMAGE)
    imgProc.interpretResult(args.f)
 def test_CCI_blackImage(self):
     """ Test to verify that the CCI is equal to 0, given a black image """
     way=os.path.abspath("TestComponents/black.jpg")
     img = Image(way)
     processor = ImageProcessor(img)
     cci = processor.get_CCI()
     self.assertAlmostEqual(round(cci, 2), 0)
    def __init__(self, debug):
        self.my_image_processor = ImageProcessor()

        self.left_lane_line = LaneLine()

        self.right_lane_line = LaneLine()

        self.debug = debug
예제 #9
0
 def __init__(self):
     self.camera_device = 0
     self.__logger = ConsoleLogger()
     self.__logger.log('Init start...')
     self.__recognition = Recognition()
     self.__image_processor = ImageProcessor()
     self.__wait_ms = 20
     self.__logger.log('Init end')
예제 #10
0
    def __init__(self, imgFile, config):
        #print('Reading {}'.format(imgFile))
        #self.imgData = shelve.open(imgFile, flag='r', protocol=pickle.HIGHEST_PROTOCOL)

        self.config = config
        self.classToAnsMap = config.classToAnsMap
        self.classToAnsMap[-1] = -1
        self.mapWordToID = config.mapWordToID
        self.imageProcessor = ImageProcessor()
예제 #11
0
def load_image_png(file):
    """

    :param file: name of file that needs to be read in from png file
    :return: image in numpy array
    """
    img = imread(path + file)
    pro = ImageProcessor()
    img_con = pro.adaptiveEqualization(img)
    return img_con
예제 #12
0
 def transmit_livefeed(self, liveFeedImageRef):
     '''
         Transmit the livefeed from the camera to the database
     '''
     print("Transmitting Live Feed")
     img = self.camera.get_image_from_camera()
     img = ImageProcessor.resizeImage(
         img, (self.settings["LiveFeedImageWidth"],
               self.settings["LiveFeedImageHeight"]))
     imgString = ImageProcessor.convertImageToString(img)
     self.firebase.update_live_feed(liveFeedImageRef, imgString)
예제 #13
0
    def recognize(self, image):
        tempImage = cv2.medianBlur(image.copy(), 15)
        returnValue, tempImage = cv2.threshold(tempImage, 127, 255,
                                               cv2.THRESH_BINARY)

        im2, contours, hierarchy = cv2.findContours(tempImage, cv2.RETR_TREE,
                                                    cv2.CHAIN_APPROX_SIMPLE)

        if len(contours) > 0:
            contour = max(contours, key=cv2.contourArea)

            try:
                [x, y, w, h] = cv2.boundingRect(contour)

                # image = cv2.adaptiveThreshold(image, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
                image = image[y:(y + h), x:(x + w)]

                ImageProcessor.storeImage(
                    Utility.getAbsolutePath(
                        "data\\optical-character-recognition\\temporary-files\\temp.jpg"
                    ), image)

                if os.name == "nt":
                    text = pytesseract.image_to_string(
                        Image.open(
                            Utility.getAbsolutePath(
                                "data\\optical-character-recognition\\temporary-files\\temp.jpg"
                            )),
                        lang="eng",
                        config=
                        "--tessdata-dir \"C:/Program Files (x86)/Tesseract-OCR/tessdata\""
                    ).strip()
                else:
                    text = pytesseract.image_to_string(
                        Image.open(
                            Utility.getAbsolutePath(
                                "data\\optical-character-recognition\\temporary-files\\temp.jpg"
                            ))).strip()

                if len(text) != 0:
                    try:
                        print text

                        # textToSpeech.speak(text);

                    except Exception:
                        pass

                ImageProcessor.showPreview("OCR", image)

                if cv2.waitKey(1) == 27:
                    pass
            except Exception:
                pass
    def buildDatabase(self):
        print "initializing..."

        ID = 0
        facesDetected = 0
        subdirectoryNames = os.listdir(
            Utility.getAbsolutePath("data\\face-recognition\\faces"))
        listIDs = []
        listFaces = []

        faceRecognizer = self.createFaceRecognizer()

        print "organizing database..."

        for subdirectoryName in subdirectoryNames:
            files = os.listdir(
                Utility.getAbsolutePath("data\\face-recognition\\faces\\" +
                                        subdirectoryName))

            for _file in files:
                image = ImageProcessor.loadImage(
                    Utility.getAbsolutePath("data\\face-recognition\\faces\\" +
                                            subdirectoryName + "\\" + _file))
                grayImage = ImageProcessor.convertImageToGrayscale(image)
                faces = self.detectFaces(grayImage)
                facesDetected = self.countFaces(faces)

                print "faces detected = ", facesDetected

                if facesDetected == 1:  # the image must contain only one face...
                    print ID, "data\\faces\\" + subdirectoryName + "\\" + _file
                    listIDs.append(ID)
                    croppedImage = self.cropFaces(faces, grayImage)[0]
                    listFaces.append(numpy.array(croppedImage, 'uint8'))

                facesDetected = 0
            # loop ends here...

            ID += 1
        # loop ends here...

        faceRecognizer.train(listFaces, numpy.array(listIDs))

        if cv2.__version__ >= "3.3.0":
            faceRecognizer.write(
                Utility.getAbsolutePath(
                    "data\\face-recognition\\face-recognition-database.xml"))
        else:
            faceRecognizer.save(
                Utility.getAbsolutePath(
                    "data\\face-recognition\\face-recognition-database.xml"))

        print "operation completed successfully..."
예제 #15
0
def write_itk_png(img):
    """

    :param img: image in numpy array form
    :return: image with pixel depth of 4 in itk image type. Can be used with simple itk
    """
    pro = ImageProcessor()
    img_con = pro.adaptiveEqualization(img)
    img_1 = sitk.GetImageFromArray(
        np.repeat(img_con[np.newaxis, :, :], 4, axis=0))
    # img_1.SetSpacing([slat, sax, 1])
    return img_1
예제 #16
0
파일: Formula.py 프로젝트: flotre/formulapi
 def __init__(self, carnumber):
     self.client_socket = None
     self.latestimage = None
     self.controlthread = None
     self.process = True
     self.carnumber = carnumber
     self.targetspeed = 0
     self.targetlane = 0
     self.racestarted = False
     self.lapcount = 0
     self.logger = logging.getLogger('formulapi')
     self.imgprocess = ImageProcessor()
예제 #17
0
def s3process(params, filename):
    options = parse_options(params)
    preset_filename = None

    if 'p' in options:
        preset = options['p']
        # We have a preset - check if we have options for it
        if preset not in PRESETS:
            # Don't have such preset - abort
            abort(404)

        options = parse_options(PRESETS[preset])
        name, ext = os.path.splitext(filename)

        # Preset filename will be like this: 'image.p_stc.jpg'
        preset_filename = ''.join((name, '.p_', preset, ext))

        try:
            s3.head_object(Bucket=AWS_S3_BUCKET, Key=preset_filename)
            return redirect('https://{0}.s3.amazonaws.com/{1}'.format(
                AWS_S3_BUCKET, preset_filename))
        except ClientError as e:
            # No preset file
            pass

    local_file = os.path.join(S3_BUCKET_LOCAL_DIR, filename)

    if os.path.exists(local_file):
        fileobj = open(local_file, 'rb')
    else:
        fileobj = BytesIO()
        try:
            s3.download_fileobj(AWS_S3_BUCKET, filename, fileobj)
        except ClientError as e:
            if e.response['Error']['Code'] == '404':
                abort(404)
        fileobj.seek(0)
    p = ImageProcessor(fileobj)
    buff = p.process(options)
    fileobj.close()

    if preset_filename:
        # Upload preset file to S3
        s3.upload_fileobj(buff,
                          AWS_S3_BUCKET,
                          preset_filename,
                          ExtraArgs=dict(ACL='public-read'))
        return redirect('https://{0}.s3.amazonaws.com/{1}'.format(
            AWS_S3_BUCKET, preset_filename))

    return send_file(buff, mimetype='image/jpg')
예제 #18
0
 def valuta_sito_web(self, sito):
     crawler = Crawler()
     img_processor = ImageProcessor()
     # img_worker = ImageWorker()
     report_pagine = crawler.generate_reportpagine(sito)
     print(report_pagine.toJSON())
     # TODO: generazione report foto
     report_foto = img_processor.generate_report_foto('web')
     # report_foto = img_worker.generate_reportfoto()
     # TODO: cancellare directory foto
     report = self.evaluate_report(sito, report_pagine, report_foto)
     # TODO: valuta report
     # report = Report(sito, report_pagine, report_foto, valutazione)
     return report
def test_add_plant_2():
    print("\n")
    cam = Camera(dummy=True, dummy_img=Path(__file__).parent /\
                 "data/imgs/plants/2/2-ze-0.jpg")
    img_proc = ImageProcessor(Path(__file__).parent / 'plant_model.pth')
    img_proc._assign_camera(cam)
    # Before it switches should be nothing present
    assert img_proc.currentPlant() == img_proc.neural_net.NO_PLANT
    assert img_proc.plantPresent() == False
    img_proc.resetDetected()
    assert img_proc.currentPlant() == 1
    assert img_proc.plantPresent() == True
    print(f"Plant {img_proc.currentPlant()} detected after update")
    print("\n")
예제 #20
0
 def celluloid(img):
     row = img.shape[0]
     for i in range(0, row):
         for j in range(0, row):
             boundary = (0.2126 * img[i][j][0] + 0.7152 * img[i][j][1] +
                         0.0722 * img[i][j][2])
             boundary = round(boundary)
             img[i][j][0] = (boundary - 0.7152 * img[i][j][1] -
                             0.0722 * img[i][j][2]) / 0.2126
             img[i][j][1] = (boundary - 0.2126 * img[i][j][0] -
                             0.0722 * img[i][j][2]) / 0.7152
             img[i][j][2] = (boundary - 0.2126 * img[i][j][0] -
                             0.7152 * img[i][j][1]) / 0.0722
     ImageProcessor.display(img)
def userImageUpload(username):

    file = request.files['file']
    #jsonObject = request.get_json()
    billDate = request.form['billDate']
    print billDate
    #print filename

    if (file and allowed_file(file.filename)):
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        imageOutput = ImageProcessor(username, filename, billDate)
        print imageOutput

    return jsonify(imageOutput.getImageContents())
예제 #22
0
    def __init__(self,use_smoothing=True, camera = None):
        '''
        Parameters
        use_smoothing: Apply the KF or ignore
        camera: Pickle file for camera calibration
        '''
        self.left_line = Line()

        self.right_line = Line()

        self.camera = camera

        self.use_smoothing = use_smoothing

        self.ImageProcessor = ImageProcessor(camera = camera, use_smoothing= use_smoothing)
예제 #23
0
def main():
    imp = ImageProcessor()
    arr = imp.load("day03/ex03/test.png")
    cf = ColorFilter()
    imp.display(arr)
    # imp.display(cf.invert(arr))
    # imp.display(cf.to_blue(arr))
    # imp.display(cf.to_green(arr))
    # imp.display(cf.to_red(arr))
    # imp.display(cf.to_celluloid(arr, 4))
    imp.display(cf.to_grayscale(arr, 'm'))
    imp.display(cf.to_grayscale(arr, 'weighted'))
예제 #24
0
 def valuta_instagram_profile(self, profilo):
     crawler = CrawlerSocial()
     img_processor = ImageProcessor()
     report = crawler.instagram_crawler(profilo, img_processor)
     # TODO: cancellare directory foto
     # TODO: valuta report
     return report
예제 #25
0
    def recognizeCharacters(self, image):
        global RESIZED_IMAGE_WIDTH, RESIZED_IMAGE_HEIGHT, kNearest

        self.text = ""
        informations = []

        grayBlurredImage = cv2.GaussianBlur(
            ImageProcessor.convertImageToGray(image), (5, 5),
            0)  # convert the image to gray and blur it...
        thresholdedImage = cv2.adaptiveThreshold(
            grayBlurredImage, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
            cv2.THRESH_BINARY_INV, 11, 2)
        image, contours, hierarchy = cv2.findContours(thresholdedImage.copy(),
                                                      cv2.RETR_EXTERNAL,
                                                      cv2.CHAIN_APPROX_SIMPLE)

        for contour in contours:
            information = Information()
            information.contour = contour
            information.contourArea = cv2.contourArea(information.contour)

            if information.isContourValid():
                information.boundingRectangle = cv2.boundingRect(
                    information.contour)

                information.calculateRectangle()
                informations.append(information)

        informations.sort(key=operator.attrgetter(
            "rectangle.x"))  # sort contours from left to right...

        del self.rectangles[:]  # clearing the list "rectangles"...

        for information in informations:
            image = thresholdedImage[
                information.rectangle.y:information.rectangle.y +
                information.rectangle.height,
                information.rectangle.x:information.rectangle.x +
                information.rectangle.width]
            image = cv2.resize(image,
                               (RESIZED_IMAGE_WIDTH, RESIZED_IMAGE_HEIGHT))
            numpyArray = numpy.float32(
                image.reshape(
                    (1, RESIZED_IMAGE_WIDTH * RESIZED_IMAGE_HEIGHT
                     )))  # convert type of numpy array from int to float...
            returnValue, result, neighborResponse, distance = kNearest.findNearest(
                numpyArray, k=1
            )  # result = vector with results of prediction (regression or classification) for each input sample... it is a single-precision floating-point vector with number_of_samples elements...

            if distance > 4712875:
                continue

            self.text = self.text + str(chr(int(result[0][0])))

            self.rectangles.append(information.rectangle)

            print "=" + str(distance) + "="  # for debugging purpose...

        if len(self.text.strip()) != 0:
            print self.text + "\n"
def test_init_bad_camera():
    """
    Test of initialization of ImageProcessor with a bad camera object.
    Test fails if the _assign_camera() function fails to realize that
    the camera object is not good.
    """
    print("\n")
    img_proc = ImageProcessor(Path(__file__).parent / 'plant_model.pth')
    try:
        print("Trying to assign bad camera object to processor")
        img_proc._assign_camera(None)
        assert False
    except TypeError:
        print("Assignment failed successfuly")
        assert True
    print("\n")
예제 #27
0
    def __transmit(self, camera):
        print "starting transmission..."

        byteArray = bytearray()
        counter = 0

        while camera.isStarted:
            if len(self.addresses) > 0:
                buffer = ImageProcessor.getBufferFromImage(camera.image)
                remaining = bufferLength = len(buffer)

                for i in range(0, bufferLength):
                    byteArray.append(buffer[i])

                    remaining = remaining - 1

                    if (counter == Utility.bufferLength) or (remaining == 0):
                        for address in self.addresses:
                            self._socket.sendto(byteArray, address)

                            if remaining == 0:
                                self._socket.sendto(
                                    "reset", address
                                )  # "reset" is a flag to let client know that one frame is sent...

                        byteArray = bytearray()
                        counter = 0

                    counter = counter + 1
                    i = i + 1

        self._socket.close()
def test_init_good_camera():
    """
    Test of initialization of ImageProcessor with a good camera object
    """
    print("\n")
    print("Trying to find camera")
    try:
        cam = Camera()
        assert (False)
    except:
        print("No physical camera found, using software camera")
        cam = Camera(dummy=True, dummy_img=Path(__file__).parent /\
                    "data/imgs/plants/1/1-cc-0.jpg")
    img_proc = ImageProcessor(Path(__file__).parent / 'plant_model.pth')
    img_proc._assign_camera(cam)
    assert isinstance(img_proc, ImageProcessor)
    assert isinstance(img_proc.camera, Camera)
    print("Camera successfully bound to image processor")
    print("\n")
예제 #29
0
 def test_instgram_scraper(self):
     db = DBmanager()
     db.start_connection()
     proc = ImageProcessor()
     socialCrawl = CrawlerSocial()
     # target = 'https://www.instagram.com/lube_marseille_store/'
     # target = 'https://www.instagram.com/molteni_matteo/'
     target = 'https://www.instagram.com/cucinelubenapoli/'
     report = socialCrawl.instagram_crawler(target, proc)
     print(report.toJSON())
    def addNewFace(self, ID, name, image):  # improvement needed...
        Utility.createDirectory(
            Utility.getAbsolutePath("data\\face-recognition\\faces\\" + name))

        grayImage = ImageProcessor.convertImageToGrayscale(image)
        cv2.equalizeHist(grayImage, grayImage)
        faces = self.detectFaces(grayImage)
        facesDetected = self.countFaces(faces)

        if facesDetected == 1:
            croppedImage = self.cropFaces(faces, grayImage)[0]
            croppedImage = ImageProcessor.resizeImage(200, croppedImage)
            cv2.imwrite(
                Utility.getAbsolutePath("data\\face-recognition\\faces\\" +
                                        name + "\\" + str(ID) + ".jpg"),
                croppedImage)

            print Utility.getAbsolutePath("data\\face-recognition\\faces\\" +
                                          name + "\\" + str(ID) + ".jpg")
예제 #31
0
def main():
    #
    rasterToPrinterQueue = Queue.Queue()
    quitEvent = threading.Event()
    printer=SimpleThermalPrinter(quitEvent,rasterToPrinterQueue)  
    
    import sys,select,Image,ImageOps
    from ImageProcessor import ImageProcessor
    im=ImageProcessor()
    print "loading image"
    img=Image.open("test.jpg")
    print "resizing image"
    img=im.resizeForPrinter(img)
    tmptmp=im.rasterForPrinter(img)
    
    print "s or d for lines"
    try:
        while True:
            time.sleep(1)
            while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
                c = sys.stdin.readline()
                c=c[0:1]
                if(c=='s'): 
                    printer.printPixelArray(tmptmp)
                 
#                    for i in range(0,len(tmptmp),384):
                        
 #                       printer.writePixelLine(tmptmp[i:i+384])
  #                  printer.feed()
  
                    print "done - press s or d for lines"
                    
    except KeyboardInterrupt:
        print("exiting")
        pass
    printer.feed()
    
    printer.close()
class RosImgToOpenCVImageConvertor:
	'''
		This class does:
			OPENCV ROS Image bridge by initializing sidewalk_detector node
			Initializes Deep Learning classifier
			subscribes image from  topic /camera/color/image_raw
			publishes Image data onto /sidewalk_detector/color/image_raw TOPIC
	'''
	def __init__(self):

		
		# initialize OpenCV Bridge
		self.bridge = CvBridge()

		curRosPackage = rospkg.RosPack()
		self.curModulePath = curRosPackage.get_path('hello_real_sense')

		# initialize classifier
		print 'initializing the classifier'
		self.imgProcessor = ImageProcessor()

		# set subscriber
		self.imageSubscriber = rospy.Subscriber("/camera/color/image_raw",Image, self.processMyImage, queue_size= 20)

		# set publisher
		self.imagePublisher = rospy.Publisher("/sidewalk_detector/color/image_raw",Image, queue_size= 20)
		self.imgCount = 0
		pass

	def processMyImage(self, data):
		try:
			# get image
			opencvImg = self.bridge.imgmsg_to_cv2(data, "bgr8")

			# original image is upside down (looking at the rviz of the rosbag visualized image)

			imgToProcess = cv2.flip(opencvImg, -1)

			# use classifier to process image
			processedImg = self.imgProcessor.processMyImage(imgToProcess)
			# publish the processed image using the publisher

			self.imagePublisher.publish(self.bridge.cv2_to_imgmsg(processedImg, "bgr8"))
			# cv2.imwrite(self.curModulePath+"/examples/"+str(self.imgCount)+'.jpg', processedImg)
			# self.imgCount += 1
			# cv2.waitKey(5)
		except CvBridgeError as e:
			print e
	def __init__(self):

		
		# initialize OpenCV Bridge
		self.bridge = CvBridge()

		curRosPackage = rospkg.RosPack()
		self.curModulePath = curRosPackage.get_path('hello_real_sense')

		# initialize classifier
		print 'initializing the classifier'
		self.imgProcessor = ImageProcessor()

		# set subscriber
		self.imageSubscriber = rospy.Subscriber("/camera/color/image_raw",Image, self.processMyImage, queue_size= 20)

		# set publisher
		self.imagePublisher = rospy.Publisher("/sidewalk_detector/color/image_raw",Image, queue_size= 20)
		self.imgCount = 0
		pass
from ImageProcessor import ImageProcessor
import cv2
import glob

imgProcessor = ImageProcessor()

for eachIndex in range(181):
	img = cv2.imread('/home/jason/catkin_realsense_ws/src/hello_real_sense/scripts/data/img'+str(eachIndex)+'.jpg',1)
	processedImg = imgProcessor.processMyImage(img)
	cv2.imwrite('/home/jason/catkin_realsense_ws/src/hello_real_sense/examples/img'+str(eachIndex)+'.jpg', processedImg)
'''
Created on Nov 16, 2014
@author: Etienne
'''


from ImageProcessor import ImageProcessor
from Segmenter import Segmenter
import matplotlib.pyplot as plt

IP = ImageProcessor()
imgSize = IP.getSize("5.jpg")
imgSpace = IP.process("5.jpg")
# print imgSpace[:766,3:5]
S = Segmenter()
K = 108


#Test pick centers
#Should give S points evenly spaced across the space
gridInterval = S.calcGridInterval(imgSpace.shape, K)
centers = S.pickCenters(K, gridInterval, imgSpace, imgSize)
print centers.shape


# print centers
X0 = centers[:,3]
Y0 = centers[:,4]
# print X,Y
plt.plot(X0,Y0,"rx")
from matplotlib import pyplot as plt
from ImageProcessor import ImageProcessor
import Declarations

s = ImageProcessor("/Volumes/Files/10Noise.png")

args = {'theta': 15, 'rho': 3}
procedure = [(Declarations.THRESHOLD_ITERATIVE, None)]
s.generateBinaryImage(procedure)
noise10 = s.original
result10 = s.working

s = ImageProcessor("/Volumes/Files/5Noise.png")

args = {'theta': 15, 'rho': 3}
procedure = [(Declarations.THRESHOLD_ITERATIVE, None)]
s.generateBinaryImage(procedure)
noise5 = s.original
result5 = s.working

images = [noise10, 0, result10,
          noise5, 0, result5,
          ]

titles = ['STDEV: 10 Noise', '', "Iterative Thresholding",
          'STDEV: 5 Noise', '', "Iterative Thresholding",
          ]

numimages = len(images)/3
for i in xrange(numimages):
    plt.subplot(numimages, 3, i*3+1), plt.imshow(images[i*3], 'gray')
'''
Created on Nov 10, 2014
@author: Etienne
'''

from ImageProcessor import ImageProcessor
from Segmenter import Segmenter
import matplotlib.pyplot as plt
import numpy as np

path = "lena.bmp"

#Read and process image
IP = ImageProcessor()
img = IP.getImg(path)/256.
imgSize = IP.getSize(path)
imgSpace = IP.process(path)


#Segment image
S = Segmenter()
K = 300 #number of clusters
errorThreshold = 0.01
clusters = S.segment(K, imgSpace, imgSize, errorThreshold)

#Get back clusters into image shape
width, height = imgSize[0],imgSize[1]
clusters = np.flipud(clusters.reshape((width,height)))


#Plot image