Пример #1
0
def processLine(i, w, index, inputImage, tileSize, channels):
    for j in range(0, w / tileSize):
        roi = inputImage[i * tileSize:(i + 1) * tileSize, j * tileSize:(j + 1) * tileSize]
        fts = features.extractFeature(roi)
        patch = preparePatch(getIndexImage(fts, index, channels), tileSize)
        inputImage[i * tileSize:(i + 1) * tileSize, j * tileSize:(j + 1) * tileSize] = patch
        cv2.imshow("Progress", inputImage)
        cv2.waitKey(1)
Пример #2
0
def CalcLine(i, w, index, inputImage, number_of_tiles, channels):
    for j in range(0, w // number_of_tiles):
        roi = inputImage[i * number_of_tiles:(i + 1) * number_of_tiles, j * number_of_tiles:(j + 1) * number_of_tiles]
        fts = features.extractFeature(roi)
        patcher = startpatching(importImage_index(fts, index, channels), number_of_tiles)
        inputImage[i * number_of_tiles:(i + 1) * number_of_tiles, j * number_of_tiles:(j + 1) * number_of_tiles] = patcher
        cv2.imshow("Progress", inputImage)
        cv2.waitKey(1)
Пример #3
0
def processLine(i, w, index, inputImage, tileSize, channels):
    for j in range(0, w / tileSize):
        roi = inputImage[i * tileSize:(i + 1) * tileSize, j * tileSize:(j + 1) * tileSize]
        fts = features.extractFeature(roi)
        patch = preparePatch(getIndexImage(fts, index, channels), tileSize)
        inputImage[i * tileSize:(i + 1) * tileSize, j * tileSize:(j + 1) * tileSize] = patch
        cv2.imshow("Progress", inputImage)
        cv2.waitKey(1)
Пример #4
0
def return_avgs(imgfile_imgbytes, bucketBroadcast):
    file_bytes = np.asarray(bytearray(imgfile_imgbytes[1]), dtype=np.uint8)
    img = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
    min_distance = 277
    small_img_avg = features.extractFeature(img)
    buckets = bucketBroadcast.value

    dominant_colour_bucket = buckets[0]
    for bucket in buckets:
        current_distance = calcEuclideanColourDistance(bucket[1],
                                                       small_img_avg)
        if (current_distance < min_distance):
            min_distance = current_distance
            dominant_colour_bucket = bucket
    #  return tile/bucket's average color, (name of current small img, distance to bucket,
    # .. average of current small image, coordinates of tile (for the final stitch step))
    return (dominant_colour_bucket[1], (imgfile_imgbytes[0], min_distance,
                                        features.extractFeature(img),
                                        dominant_colour_bucket[0]))
Пример #5
0
def processLine(i, w, index, inputImage, tileSize, channels, mosaic_tiles):
    mosaic_tiles.append([])
    for j in range(0, w / tileSize):
        roi = inputImage[i * tileSize:(i + 1) * tileSize,
                         j * tileSize:(j + 1) * tileSize]
        fts = features.extractFeature(roi)
        index_image = getIndexImage(fts, index, channels)
        mosaic_tiles[-1].append(index_image)
        patch = preparePatch(index_image, tileSize)
        inputImage[i * tileSize:(i + 1) * tileSize,
                   j * tileSize:(j + 1) * tileSize] = patch
        cv2.imshow("Progress", inputImage)
Пример #6
0
def main():
    index = []
    if not os.path.exists(INDEX_PATH):
        os.makedirs(INDEX_PATH)
    files = glob.glob(DB_PATH + "/" + "*.jpg")

    entry = []
    fileName = []

    for file in files:
        print "Processing file: " + file
        image = convertImage(file)
        entry = features.extractFeature(image)
        print(entry)
        #entry["file"] = ntpath.basename(file)
        index.append(entry)
        fileName.append(ntpath.basename(file))

    trained_model = cluster_img(index)

    print("Train Model COMPLETED! Showing the result..")
    for mCenter in trained_model.centers:
        print(mCenter)
    print("Now Saving the K Measns Model")
    trained_model.save(sc, "myModelPath")

    #with open(INDEX_PATH + "histogram.index", 'w') as outfile:
    #json.dump(index, outfile, indent=4)

    #rdd = sc.parallelize(index)
    #print rdd.collect()
    #rdd.saveAsTextFile("historgam")

    i = 0

    text_file = open("images_cluster.txt", "w")
    for image in index:
        result = trained_model.predict(image)
        text_file = open("images_cluster.txt", "a")
        text_file.write(fileName[i] + ":" + str(result) + "\n")
        text_file.close()
        print(fileName[i] + ":" + str(result))
        i += 1

    print("Index written to: " + INDEX_PATH + "histogram.index")
Пример #7
0
def main():
    index = []
    if not os.path.exists(INDEX_PATH):
        os.makedirs(INDEX_PATH)
    files = glob.glob(DB_PATH + "/" + "*.jpg")

    entry = {}

    for file in files:
        print "Processing file: " + file
        image = convertImage(file)
        entry = features.extractFeature(image)
        entry["file"] = ntpath.basename(file)
        index.append(entry)

    with open(INDEX_PATH + "histogram.index", 'w') as outfile:
        json.dump(index, outfile, indent=4)

    print("Index written to: " + INDEX_PATH + "histogram.index")
Пример #8
0
def main():
    index = []
    if not os.path.exists(path_index):
        os.makedirs(path_index)
    files = glob.glob(IMAGE_PATH + "/" + "*.jpg")

    access = {}

    for file in files:
        print("File Processing: " + file)
        image = Convert(file)
        access = features.extractFeature(image)
        access["file"] = ntpath.basename(file)
        index.append(access)

    with open(path_index + "histogram.index", 'w') as outfile:
        json.dump(index, outfile, indent=4)

    print("Written to: " + path_index + "histogram.index")
Пример #9
0
def main():
    index = []
    if not os.path.exists(INDEX_PATH):
        os.makedirs(INDEX_PATH)
    files = glob.glob(DB_PATH + "/" + "*.jpg")
    
    entry = {}
    
    for file in files:
        print "Processing file: " + file
        image = convertImage(file)
        entry = features.extractFeature(image)
        entry["file"] = ntpath.basename(file)
        index.append(entry)

    with open(INDEX_PATH + "histogram.index", 'w') as outfile:
        json.dump(index, outfile, indent=4)
        
    print ("Index written to: " + INDEX_PATH + "histogram.index")
Пример #10
0
def compute_tile_avgs(cvimg):
    block_width = gcd(cvimg.shape[0], cvimg.shape[1])
    block_height = block_width

    numrows = int(cvimg.shape[0] / block_height)
    numcols = int(cvimg.shape[1] / block_width)

    tile_avgs = []

    for row in range(0, numrows):
        for col in range(0, numcols):
            y0 = row * block_height
            y1 = y0 + block_height
            x0 = col * block_width
            x1 = x0 + block_width
            tile_avg = features.extractFeature(cvimg[y0:y1, x0:x1])
            tile_coords = [y0, y1, x0, x1]
            tile_stats = [tile_coords, tile_avg]
            tile_avgs.append(tile_stats)

    return tile_avgs