def create_protos(coordinates, min_x, min_y, output_directory):
    align_data_proto = AlignData_pb2.AlignDataHierarchy()
    section_protos = {}
    tile_id = 0
    for key,value in coordinates.iteritems():
        filename = key.split("/")[-1]
        try:
            section_id, mfov_id, tile_index, junk = filename.split("_")
            section_id = int(section_id)
            tile_id = int(tile_id)
            mfov_id = int(mfov_id)
            tile_index = int(tile_index)
            if section_id not in section_protos:
                section_protos[section_id] = AlignData_pb2.SectionData()
                section_protos[section_id].section_id = section_id
            tile_proto = section_protos[section_id].tiles.add()
            tile_proto.tile_id = tile_id
            tile_proto.tile_mfov = mfov_id
            tile_proto.tile_index = tile_index
            tile_proto.section_id = section_id
            #TODO check this line
            value[0] -= min_x
            value[1] -= min_y
            tile_proto.x_start = value[0]
            tile_proto.x_finish = value[0]+image_width
            tile_proto.y_start = value[1]
            tile_proto.y_finish = value[1]+image_height
            tile_proto.tile_filepath = key
            tile_id +=1
        except ValueError as e:
            print "bad format", filename
            del section_protos[section_id].tiles[-1]
    for section, proto in section_protos.iteritems():
        print "in section", section,"we have",len(proto.tiles)
        proto.n_tiles = len(proto.tiles)
    

    #align_data_proto.sec_data.sort(key = lambda x: x.section_id)
    section_protos_list = list(section_protos.itervalues())
    section_protos_list.sort(key = lambda x: x.section_id)
    for item in section_protos_list:
        string = output_directory+"section_"+str(item.section_id)+".pbuf"
        f = open(string, 'wb')
        f.write(item.SerializeToString())
        f.close()
        align_data_proto.sec_data_location.append(string)


    align_data_proto.n_sections = len(section_protos)
    align_data_proto.base_section = min(section_protos.keys())

    f = open(output_directory+"stack.pbuf", 'wb')
    f.write(align_data_proto.SerializeToString())
    f.close()
def create_proto(coordinates, min_x, min_y):
    align_data_proto = AlignData_pb2.AlignData()
    section_protos = {}
    tile_id = 0
    for key, value in coordinates.iteritems():
        filename = key.split("/")[-1]
        try:
            section_id, mfov_id, tile_index, junk = filename.split("_")
            section_id = int(section_id)
            tile_id = int(tile_id)
            mfov_id = int(mfov_id)
            tile_index = int(tile_index)
            if section_id not in section_protos:
                section_protos[section_id] = align_data_proto.sec_data.add()
                section_protos[section_id].section_id = section_id
            tile_proto = section_protos[section_id].tiles.add()
            tile_proto.tile_id = tile_id
            tile_proto.tile_mfov = mfov_id
            tile_proto.tile_index = tile_index
            tile_proto.section_id = section_id
            #TODO check this line
            value[0] -= min_x
            value[1] -= min_y
            tile_proto.x_start = value[0]
            tile_proto.x_finish = value[0] + image_width
            tile_proto.y_start = value[1]
            tile_proto.y_finish = value[1] + image_height
            tile_proto.tile_filepath = key
            tile_id += 1
        except ValueError as e:
            print "bad format", filename
            del section_protos[section_id].tiles[-1]
    for section, proto in section_protos.iteritems():
        print "in section", section, "we have", len(proto.tiles)
        proto.n_tiles = len(proto.tiles)
    align_data_proto.n_sections = len(section_protos)
    align_data_proto.sec_data.sort(key=lambda x: x.section_id)
    align_data_proto.base_section = min(section_protos.keys())
    return align_data_proto
Beispiel #3
0
import os
import sys
import json
import AlignData_pb2

align_data = AlignData_pb2.AlignData()
#
align_data.ParseFromString(open(sys.argv[1]).read())

print align_data
Beispiel #4
0
import os
import sys
import json
import AlignData_pb2

align_data = AlignData_pb2.AlignDataHierarchy()

align_data.ParseFromString(open(sys.argv[1]).read())

print align_data

for section in align_data.sec_data_location:
    sec_data = AlignData_pb2.SectionData()
    sec_data.ParseFromString(open(section).read())
    print sec_data
import math
import random
from copy import deepcopy
import argparse
from statistics import mean

parser = argparse.ArgumentParser(
    description='makes a new proto with a smaller area from an old proto')
parser.add_argument("orig", help="The original proto which created the data")
parser.add_argument("sec_num", help="which section number to shrink")
parser.add_argument("radius", type=int, help="radius of the new section")
args = parser.parse_args()
x_size = 3128
y_size = 2724

pre_align_data = AlignData_pb2.AlignDataHierarchy()
small_align_data = AlignData_pb2.AlignDataHierarchy()
pre_align_data.ParseFromString(open(args.orig).read())
section_number = int(args.sec_num)
section_location = pre_align_data.sec_data_location[section_number]
section = AlignData_pb2.SectionData()
section.ParseFromString(open(section_location).read())
radius = args.radius


def get_distance(vec1, vec2):
    return math.sqrt((vec1[0] - vec2[0])**2 + (vec1[1] - vec2[1])**2)


def get_center(tile1):
    tile1_x_start = tile1.x_start + tile1.offset_x
import os
import sys
import AlignData_pb2
import math

x_size = 3128
y_size = 2724

percent_cutoff = .008

post_align_data = AlignData_pb2.Saved2DAlignmentSection()
post_align_data.ParseFromString(open(sys.argv[1]).read())

section_num = int(sys.argv[2])

start_proto1 = AlignData_pb2.AlignData()
start_proto2 = AlignData_pb2.AlignData()
start_proto1.ParseFromString(open(sys.argv[3]).read())
start_proto2.ParseFromString(open(sys.argv[4]).read())
section1 = start_proto1.sec_data[section_num]
section2 = start_proto2.sec_data[section_num]


#SI = Max(0, Min(XA2, XB2) - Max(XA1, XB1)) * Max(0, Min(YA2, YB2) - Max(YA1, YB1))
def overlap(tile1, tile2):
    tile1_x_start = tile1.x_start + tile1.offset_x
    tile1_x_finish = tile1_x_start + x_size
    tile1_y_start = tile1.y_start + tile1.offset_y
    tile1_y_finish = tile1_y_start + y_size
    tile2_x_start = tile2.x_start + tile2.offset_x
    tile2_x_finish = tile2_x_start + x_size
Beispiel #7
0
import random
from copy import deepcopy
import argparse
from statistics import mean

parser = argparse.ArgumentParser(description='makes a new proto with a smaller area from an old proto')
parser.add_argument("orig", help="The original proto which created the data")
parser.add_argument("sec_num",help="which section number to shrink")
parser.add_argument("final",help="the output proto from the 2d alignment")
parser.add_argument("radius", type=int, help="radius of the new section")
args = parser.parse_args()
x_size = 3128
y_size = 2724


pre_align_data = AlignData_pb2.AlignData()
small_align_data = AlignData_pb2.AlignData()
post_align_data = AlignData_pb2.Saved2DAlignmentSection()
pre_align_data.ParseFromString(open(args.orig).read())
section_number = int(args.sec_num)
post_align_data.ParseFromString(open(args.final).read())
section = pre_align_data.sec_data[section_number]
radius = args.radius

if len(section.tiles) != len(post_align_data.tiles):
  print "their are different amounts of data the protos are probably wrong"
  exit()

def get_distance(vec1, vec2):
  return math.sqrt((vec1[0] - vec2[0])**2 + (vec1[1] - vec2[1])**2 )
Beispiel #8
0
import os
import sys
import AlignData_pb2
import math

x_size = 3128
y_size = 2724

percent_cutoff = .008

post_align_data1 = AlignData_pb2.Saved2DAlignmentSection()
post_align_data2 = AlignData_pb2.Saved2DAlignmentSection()
post_align_data1.ParseFromString(open(sys.argv[1]).read())
post_align_data2.ParseFromString(open(sys.argv[2]).read())


#SI = Max(0, Min(XA2, XB2) - Max(XA1, XB1)) * Max(0, Min(YA2, YB2) - Max(YA1, YB1))
def overlap(tile1, tile2):
    tile1_x_start = tile1.x_start + tile1.offset_x
    tile1_x_finish = tile1_x_start + x_size
    tile1_y_start = tile1.y_start + tile1.offset_y
    tile1_y_finish = tile1_y_start + y_size
    tile2_x_start = tile2.x_start + tile2.offset_x
    tile2_x_finish = tile2_x_start + x_size
    tile2_y_start = tile2.y_start + tile2.offset_y
    tile2_y_finish = tile2_y_start + y_size

    si = max(
        0,
        min(tile1_x_finish, tile2_x_finish) -
        max(tile1_x_start, tile2_x_start)) * max(
Beispiel #9
0
import os
import sys
import AlignData_pb2
import math
import random
from copy import deepcopy
import argparse

parser = argparse.ArgumentParser(
    description='create a new proto by copying one section many times')
parser.add_argument("orig", help="The original proto")
parser.add_argument("sec_num", help="which section to copy")
parser.add_argument("copies", type=int, help="How many times to copy the data")
args = parser.parse_args()

pre_align_data = AlignData_pb2.AlignDataHierarchy()
copied_align_data = AlignData_pb2.AlignDataHierarchy()
pre_align_data.ParseFromString(open(args.orig).read())
section_number = int(args.sec_num)
section_location = pre_align_data.sec_data_location[section_number]
section = AlignData_pb2.SectionData()
section.ParseFromString(open(section_location).read())
copies = args.copies

output_directory = "copied_section_" + str(section_number) + "_" + str(
    copies) + "_times"
os.system("mkdir " + output_directory)

copied_align_data.n_sections = copies
for i in range(copies):
    section.section_id = i
def write_txt_input(output_filename, tilespecs):

    #txt_data = ''
    #txt_data += '%s %d\n' % (MAGIC_STR_TOTAL_TILES, len(tilespecs))

    sections = {}

    for i, ts in enumerate(tilespecs):
        #tile_data = ''
        #
        #tile_data += '%s [%d]\n' % (MAGIC_STR_TILE_START, i)
        #
        #tile_data += '\t%s %d\n' % (MAGIC_STR_TILE_SECTION, ts['layer'])
        #tile_data += '\t%s %d\n' % (MAGIC_STR_TILE_MFOV, ts['mfov'])
        #tile_data += '\t%s %d\n' % (MAGIC_STR_TILE_INDEX, ts['tile_index'])

        #(x_start, x_finish, y_start, y_finish) = ts['bbox']
        #tile_data += '\t%s [%d][%d][%d][%d]\n' % (MAGIC_STR_TILE_BBOX,
        #    x_start, x_finish, y_start, y_finish)

        #tile_path = ts["mipmapLevels"]["0"]["imageUrl"]
        #tile_path = tile_path.replace('file://', '')
        #tile_data += '\t%s %s\n' % (MAGIC_STR_TILE_FILEPATH, tile_path)

        #tile_data += '%s [%d]\n' % (MAGIC_STR_TILE_END, i)

        #txt_data += tile_data
        ts["id"] = i

        if ts['layer'] not in sections:
            sections[ts['layer']] = []
        sections[ts['layer']].append(ts)
    align_data_proto = AlignData_pb2.AlignData()

    sorted_section = sorted(sections.keys())
    the_count = 0
    for i, sec in enumerate(sorted_section):
        print sec

        section_proto = align_data_proto.sec_data.add()
        section_proto.section_id = i
        for j, ts in enumerate(sections[sec]):
            the_count += 1
            tile_proto = section_proto.tiles.add()
            tile_proto.tile_id = ts["id"]
            tile_proto.tile_mfov = ts["mfov"]
            tile_proto.tile_index = ts["tile_index"]
            tile_proto.section_id = section_proto.section_id
            tile_proto.x_start, tile_proto.x_finish, tile_proto.y_start, tile_proto.y_finish = [
                int(item) for item in ts["bbox"]
            ]
            tile_filepath = ts["mipmapLevels"]["0"]["imageUrl"]
            if j == 0:
                print tile_filepath
            tile_proto.tile_filepath = tile_filepath.replace('file://', '')

    print '  - write: %s' % (output_filename, )
    f = open(output_filename, 'wb')
    f.write(align_data_proto.SerializeToString())
    f.close()
    print "The count is " + str(the_count)
import random
from copy import deepcopy
import argparse

parser = argparse.ArgumentParser(
    description='create a new proto by copying one section many times')
parser.add_argument("orig", help="The original proto")
parser.add_argument("sec_num", help="which section to copy")
parser.add_argument(
    "copies",
    type=int,
    help="How many times to copy the data",
)
args = parser.parse_args()

pre_align_data = AlignData_pb2.AlignData()
copied_align_data = AlignData_pb2.AlignData()
pre_align_data.ParseFromString(open(args.orig).read())
section_number = int(args.sec_num)
section = pre_align_data.sec_data[section_number]
copies = args.copies

copied_align_data.n_sections = copies
for i in range(copies):
    new_sec = copied_align_data.sec_data.add()
    new_sec.CopyFrom(section)
    copied_align_data.sec_data[i].section_id = i
copied_align_data.base_section = 0

f = open(
    "copied_section_" + str(section_number) + "_" + str(copies) +