def AnglesFromFraction(which_fraction,
                       img_rgb,
                       mode='big',
                       show=False,
                       axis=True):

    #    print('AnglesFromFraction')
    """这个复制很有启发意义!!!"""
    #用于显示的rgb矩阵
    temp_img_rgb = cp.deepcopy(img_rgb)

    #定义目标点和点集
    that_content = which_fraction.edge
    that_point = which_fraction.center

    #可疑角点集合
    that_points = SuspiciousFromContent(that_content, that_point, mode, show)

    #显示吗
    if show:

        plt.figure()

        #显示fraction的边缘和极值点
        which_fraction.ShowEdge(temp_img_rgb, axis)

        #逐个显示角点
        for this_pos in that_points:

            Dis.ShowOnePoint(this_pos, temp_img_rgb)

        #是否显示坐标轴
        if not axis:

            plt.axis('off')
Ejemplo n.º 2
0
def AddCorners(which_content, corner_amount, img_rgb, show=False):

    #结果的集合
    corner_points = []

    #点击获取图像中的点的坐标
    for temp_point in plt.ginput(corner_amount):

        #转化一下
        point = [int(np.round(temp_point[1])), int(np.round(temp_point[0]))]

        #计算距离最短的点作为角点
        map_distances_points = Geom.DistancesMap(point, which_content)

        #最短的距离
        corner_points.append(map_distances_points[min(
            list(map_distances_points.keys()))])

    #索引列表
    corner_index = [
        which_content.index(corner_point) for corner_point in corner_points
    ]

    #显示吧
    if show:

        plt.figure()

        for this_pos in corner_points:

            Dis.ShowOnePoint(this_pos, img_rgb)

    return dict(zip(corner_index, corner_points))
Ejemplo n.º 3
0
def CheckGradient(which_content, offset, img_rgb, show=False):

    #建立content索引
    x_old = [k for k in range(len(which_content))]

    #偏移后的content索引
    x_new = x_old[-offset:] + x_old[:-offset]

    #索引的映射关系
    map_x_old_new = dict(zip(x_old, x_new))

    #索引和坐标的关系
    map_x_content = dict(zip(list(map_x_old_new.values()), which_content))

    #找峰值是没错的呢 哥哥
    #计算harris角点函数梯度
    SlideGradient(AverageEnergy(which_content, 5), offset, True)

    #从gradients中提取可疑点观察观察
    points = Ang.PickPointsFromPlot(5, map_x_content)

    #显示吗
    if show:

        plt.figure()

        for this_pos in points:

            Dis.ShowOnePoint(this_pos, img_rgb)

    return points
Ejemplo n.º 4
0
def AddCorners(which_layer, corner_amount, img_rgb, show=False):

    #从边界中寻找
    which_content = which_layer.edge

    #包围layer的faults
    #    border_faults=Pick.BorderFaults(which_layer,total_fractions)

    #结果的集合
    corner_points = []

    #点击获取图像中的点的坐标
    for temp_point in plt.ginput(corner_amount):

        #转化一下
        point = [int(np.round(temp_point[1])), int(np.round(temp_point[0]))]

        #计算距离最短的点作为角点
        map_distances_points = Geom.DistancesMap(point, which_content)

        #最短的距离
        corner_points.append(map_distances_points[min(
            list(map_distances_points.keys()))])

    #索引列表
    corner_index = [
        which_content.index(corner_point) for corner_point in corner_points
    ]

    #    #根据border_faults把点投上来
    #    #先找最近的fault
    #    for this_corner_point in corner_points:
    #
    #        #这个点到两个fault的距离列表
    #        faults_centers=[this_fault.center for this_fault in border_faults]
    #
    #        #计算距离最短的点作为角点
    #        #该点到fault们的距离列表
    #        distances_faults=Geom.Distances(this_corner_point,faults_centers)
    #
    #        #建立映射关系
    #        map_distances_faults=dict(zip(distances_faults,border_faults))
    #
    #        #距离最小的fault是最邻近的
    #        fault_near_this_corner_point=map_distances_faults[min(distances_faults)]
    #
    #        #
    #        this_corner_point

    #显示吧
    if show:

        plt.figure()

        for this_pos in corner_points:

            Dis.ShowOnePoint(this_pos, img_rgb)

    return dict(zip(corner_index, corner_points))
Ejemplo n.º 5
0
def SeriesRecover(load_path, save_path):

    #导入图片,生成rgb矩阵
    img_rgb = Init.LoadImage(load_path, show=False)

    #生rgb相关的列表和字典
    #rgb_dict=Init.InitDict(img_rgb)
    rgb_dict = Init.InitDict(img_rgb, base_adjust=True, fault_exist=True)

    #改变图片尺寸增加padding
    img_tag, img_rgb = Init.AddPadding(img_rgb, rgb_dict, show=True)

    #初始化fractions,并显示
    total_fractions = Pick.PickFractions(img_rgb, img_tag, rgb_dict)

    #所有layer对象
    total_layers = Pick.DeleteFault(total_fractions)

    #恢复结果
    final_layers = []

    #temporary image
    temp_img_rgb = cp.deepcopy(img_rgb)

    for k in range(len(total_layers)):

        #fig name
        this_fig_name = str(k + 1) + '.png'

        if k == 0:

            final_layers.append(
                Len.LengthRecover(total_fractions, img_tag, img_rgb, rgb_dict))

        if k > 0:

            final_layers.append(
                Len.LengthRecover(total_fractions, img_tag,
                                  Img.BoundaryImg(final_layers[-1], img_rgb),
                                  rgb_dict))

        #new blank canvas
        temp_img_rgb[:, :] = np.array([255, 255, 255], dtype=np.uint8)

        #figure: for saving
        this_fig = plt.figure()
        Dis.ShowFractions(final_layers, temp_img_rgb, rgb_dict)

        #save this fig
        this_fig.savefig(save_path + '\\' + this_fig_name, dpi=300)

        plt.close()

    return final_layers
Ejemplo n.º 6
0
def PickFractions(img_rgb,
                  img_tag,
                  rgb_dict,
                  show=False,
                  axis=True,
                  text=False,
                  output=False,
                  base='off'):

    #基底tag
    base_tag = -2

    #拾取出tag为2,3,4的层
    fraction_rgb_dict = cp.deepcopy(rgb_dict)

    #删除空白rgb索引
    del fraction_rgb_dict[0]

    #是否要基底的那个tag
    if base == 'off':

        if base_tag in list(fraction_rgb_dict.keys()):

            del fraction_rgb_dict[base_tag]

    #图像中的所有fraction对象列表
    total_fractions = []

    #拾取断层和地层并显示
    for this_tag in list(fraction_rgb_dict.keys()):

        that_fraction = Tar.PickSomething(img_rgb, img_tag, this_tag,
                                          fraction_rgb_dict, show, axis, text,
                                          output)

        total_fractions += that_fraction

    #显示total_fractions
    if show:

        Dis.ShowFractions(total_fractions, img_rgb, rgb_dict, axis, text,
                          output)

    return total_fractions
Ejemplo n.º 7
0
def GetCorners(which_content,
               offset,
               energy_mode,
               img_tag,
               img_rgb,
               show=False):

    #滑动窗口求取梯度诶
    #平均值
    if energy_mode is 'mean':

        gradients = SlideGradient(AverageEnergy(which_content, 5, img_tag),
                                  offset)

    #最大值法
    if energy_mode is 'max':

        gradients = SlideGradient(MaximalEnergy(which_content, 5, img_tag),
                                  offset)

    #压制非极值点点,使它们为0
    peak_content = PickPeak(gradients, True)

    #寻找脉冲极值点的办法
    temp_peak_index = []

    for k in range(len(peak_content)):

        if peak_content[k] != 0:

            temp_peak_index.append(k)

    #极值窗口
    open_length = 10

    #在这个自定义区间内的都是极值
    temp_peak_index.sort()

    #定义一个字典
    #索引和周边索引的对应关系
    map_index_neighbor = {}

    #索引和他身边被录用的索引
    map_index_indexes = {}

    #开始创造其中元素
    for this_index in temp_peak_index:

        #单个的索引
        map_index_neighbor[this_index] = [
            this_index + k for k in range(-open_length, +open_length)
        ]

        #被录用的索引(肯定有自己)
        map_index_indexes[this_index] = []

    #判断每个索引和索隐门邻域的对应关系
    for this_index in temp_peak_index:

        for this_neighbor in list(map_index_neighbor.values()):

            #判断在哪里
            if this_index in this_neighbor:

                map_index_indexes[Dict.DictKeyOfValue(
                    map_index_neighbor, this_neighbor)].append(this_index)

    #print(map_index_indexes)

    #真假索引了
    temp_indexes = list(map_index_indexes.values())

    #真实的indexes集合
    indexes = []

    #唯一识别
    map_sum_indexes = {}

    #迭代合并同类项
    for this_indexes in temp_indexes:

        indexes.append(sorted(list(set(this_indexes))))

        #它们的和
        map_sum_indexes[sum(indexes[-1])] = indexes[-1]

    #print(indexes)
    #print(map_sum_indexes)

    #用于加工的indexes列表
    true_indexes = list(map_sum_indexes.values())

    #求取小区间里的最大值噢
    #消除偏移距之前的peak索引
    peak_index = []

    for this_indexes in true_indexes:

        #建立小区间内的索引与值的对应关系哦
        map_index_value = {}

        for this_index in this_indexes:

            map_index_value[this_index] = gradients[this_index]

        #找到最大值噢
        peak_value = np.max(list(map_index_value.values()))

        #获取最大值的索引
        peak_index.append(Dict.DictKeyOfValue(map_index_value, peak_value))

    #在gradients曲线上显示计算结果
    plt.figure()
    plt.plot(gradients)

    #画出峰值点吧
    for this_index in peak_index:

        plt.plot(this_index, gradients[this_index], marker='o', color='red')

    plt.axis('tight')

    #即将消除偏移距
    map_new_old_index = Dict.SortFromStart(which_content, offset)[1]

    #还原到真实的叻
    corner_index = [map_new_old_index[this_index] for this_index in peak_index]

    #在图像上还原真实的角点儿
    corner_points = [which_content[this_index] for this_index in corner_index]

    #显示吧
    if show:

        plt.figure()

        for this_pos in corner_points:

            Dis.ShowOnePoint(this_pos, img_rgb)

    return Dict.DictSortByIndex(dict(zip(corner_index, corner_points)),
                                sorted(corner_index))
Ejemplo n.º 8
0
def CurvedLinesLength(which_content, map_corner_points, lines_amount, img_rgb):

    #按索引排序
    map_corner_points = Dict.DictSortByIndex(
        map_corner_points, sorted(list(map_corner_points.keys())))

    #    print(map_corner_points)

    #计算出几个点的曲线距离
    #索引
    corner_index = list(map_corner_points.keys())

    #索引列表做一下
    curve_points = []

    for k in range(len(corner_index)):

        #第一段特殊处理
        if k == 0:

            curve_points.append(which_content[corner_index[-1]:] +
                                which_content[:corner_index[0] + 1])

        #其他正常
        else:

            curve_points.append(
                which_content[corner_index[k - 1]:corner_index[k] + 1])

#    print(curve_points)
    '''简单算法(用于检验)'''
    #    #所有的
    #    curve_distances=[]
    #
    #    #计算每一条曲线的曲线长度
    #    curve_distances=[ContinuousDistance(this_curve_points) for this_curve_points in curve_points]
    #
    #    print(curve_distances)
    '''拾取算法'''
    curve_points_up_and_down = []

    #获取两个点的坐标,确定两条层长线
    for temp_point in plt.ginput(lines_amount):

        #点击获取曲线中的点的坐标并转化一下
        point = [int(np.round(temp_point[1])), int(np.round(temp_point[0]))]

        #        print(point)

        #多条线到这个点的距离
        #以及用坐标集合当返回值
        map_distance_curve_points = {}

        #先求每条线的中点
        for this_curve_points in curve_points:

            #重心
            center = CalculateBaryCenter(this_curve_points)

            #收录进映射关系
            map_distance_curve_points[Distance(center,
                                               point)] = this_curve_points

        curve_points_up_and_down.append(map_distance_curve_points[min(
            list(map_distance_curve_points.keys()))])

    #上下两条边的点集合
    curve_points_up, curve_points_down = curve_points_up_and_down

    return curve_points_up, curve_points_down

    #上下两条边的长度
    curve_length_up = ContinuousDistance(curve_points_up)
    curve_length_down = ContinuousDistance(curve_points_down)

    #    print(curve_length_up)
    #    print(curve_length_down)

    Dis.Line2Red(curve_points_up + curve_points_down, img_rgb)

    return (curve_length_up + curve_length_down) / 2
Ejemplo n.º 9
0
 def Show(self,img_rgb,rgb_dict,text=False,output=False):
     
     Dis.ShowFractions(self.fractions,img_rgb,rgb_dict,text,output)   
def PickSomething(img_rgb,
                  img_tag,
                  this_tag,
                  rgb_dict,
                  show=False,
                  axis=True,
                  text=False,
                  output=False):

    #content_sum=Content[0]+Content[1]+...
    content_sum = []

    #method=1代表方法1,method=2代表方法2
    method = 2

    #复制生成临时的img_tag,用于标记已上色的像素点
    temp_img_tag = cp.deepcopy(img_tag)

    #是否继续遍历的标志
    content_flag = this_tag in temp_img_tag

    #块体tag a part b的重心坐标
    Center = {}

    #Center字典增加一个新的tag列表
    Center[this_tag] = []

    #that_fractions是生成的fraction对象的集合
    that_fractions = []

    #    #已知对象数量时可以这么干
    #    number=3
    #    for kk in range(number):
    """1 内部膨胀的方法增加像素点"""
    if method == 1:

        #以下部分进行循环
        while content_flag:

            #fault像素点集合的生成
            content = []

            #寻找第一个特征值值点
            fault_edge, content_flag = Find1stPixel(this_tag, img_tag,
                                                    content_sum)

            #追踪fault的边界
            fault_edge = EdgeTracing(this_tag, fault_edge, img_tag)

            #内部膨胀的方法增加像素点
            neighbordict = {
                0: (0, -1),
                1: (1, -1),
                2: (1, 0),
                3: (1, 1),
                4: (0, 1),
                5: (-1, 1),
                6: (-1, 0),
                7: (-1, -1)
            }

            #将边界存入fault列表当中
            new_edge = fault_edge
            content += new_edge

            #只要每一轮添加的点的数量不为0就执行循环
            while len(new_edge):

                #上一轮添加的点
                last_edge = new_edge

                #这一轮新添加的点坐标的列表
                new_edge = []

                for k in range(len(last_edge)):

                    #建立新的pixel对象
                    temp_pixel = pixel()
                    temp_pixel.ypos = last_edge[k][0]
                    temp_pixel.xpos = last_edge[k][1]

                    #生成邻居列表,起始迭代邻居的索引
                    temp_pixel.GenerateNeighbor(img_tag)

                    for i in range(len(neighbordict)):

                        #判断标签为tag
                        if temp_pixel.neighbor[i] == this_tag:

                            #邻居的坐标
                            new_y = temp_pixel.ypos + neighbordict[i][0]
                            new_x = temp_pixel.xpos + neighbordict[i][1]

                            pos = [new_y, new_x]

                            #新的点在不在fault列表内
                            if pos not in new_edge:

                                new_edge.append(pos)

                #将新捕捉的点存入fault列表当中
                content += new_edge
    """2 阿华法增加像素点"""
    if method == 2:

        #以下部分进行循环
        while content_flag:

            #        已知个数的情况
            #        number=2
            #        for kk in range(number):

            #装逼用
            print('')
            print('...')
            print('......')
            print('.........')
            print('tag', this_tag, 'part', len(that_fractions), ':')

            #寻找第一个特征值值点
            edge = Find1stPixel(this_tag, img_tag, content_sum)

            #追踪content的边界
            edge = EdgeTracing(this_tag, edge, img_tag)

            #this_fraction表示正在处理的fraction

            #如果tag=-1,则fraction为fault
            if this_tag == -1:

                this_fraction = fault()
            else:
                this_fraction = layer()

            #对tag属性赋值
            this_fraction.tag = this_tag

            #给part属性赋值
            this_fraction.part = len(that_fractions)

            #给edge属性赋值
            this_fraction.edge = edge

            #求对象的范围矩阵
            #left right bottom top 这几个重要的参数
            I = list(set([pos[0] for pos in edge]))
            J = list(set([pos[1] for pos in edge]))

            #增加边缘
            #            for item in edge:
            #
            #                if item[0] not in I:
            #
            #                    I.append(item[0])
            #
            #                if item[1] not in J:
            #
            #                    J.append(item[1])

            #初始生成的I,J不是按顺序的,需要对其进行排序
            I.sort()
            J.sort()

            left, right = min(J), max(J)
            bottom, top = min(I), max(I)

            #获取块体的中点
            center_x = np.mean(J)
            center_y = np.mean(I)

            #标注的坐标,即块体Content[part]的中点
            center = (center_x, center_y)

            #对center属性赋值
            this_fraction.center = center

            Center[this_tag].append(center)

            #建立某特殊的数据结构,用于存放像素点的行对应的列
            row_column = []
            column_row = []
            """is和==不一样"""
            for i in range(top - bottom + 1):

                #行对应的列的列表
                column = []

                for item in edge:

                    if item[0] == I[i]:

                        column.append(item[1])

                column.sort()

                #列表添加至大列表当中
                row_column.append(column)

            for j in range(right - left + 1):

                #列对应的行的列表
                row = []

                for item in edge:

                    if item[1] == J[j]:

                        row.append(item[0])

                row.sort()

                #列表添加至大列表当中
                column_row.append(row)

            #检验这两个数组的正确性
            sum_i, sum_j = 0, 0

            for item in row_column:

                sum_j += len(item)

            for item in column_row:

                sum_i += len(item)

            #设置验证门槛
            #J
            if sum_j == len(edge):

                print('row_column is OK')
                flag_j = True

            #I
            if sum_i == len(edge):

                print('column_row is OK')
                flag_i = True

            #IJ
            if sum_j == sum_i:

                if flag_i and flag_j:

                    flag = True

            if flag is True:
                """
                注意:
                过一个点做垂线和水平线可能会碰到交点是三个以上,如果其中有轮廓线的切点,就会出现判断失误 
                
                设置节点:
                每个节点两段点之间遍历,若符合tag要求即加入集合当中
                """
                #在row_column和column_row当中建立合适的节点,将相邻的像素点用其中头尾节点来表示

                #content像素点集合
                content = []

                #row_column
                row_column_node = []
                for r in range(len(row_column)):

                    #要删除的列表
                    column_to_delete = []

                    if len(row_column[r]) > 2:

                        #元素数量大于2时才成立
                        for c in range(1, len(row_column[r]) - 1):

                            bool_former = (row_column[r][c + 1] -
                                           row_column[r][c] == 1)
                            bool_latter = (row_column[r][c] -
                                           row_column[r][c - 1] == 1)

                            #直接删除中间元素
                            if bool_former and bool_latter:

                                #建立需要删除元素的列表
                                column_to_delete.append(row_column[r][c])

                    #要增加的节点列表
                    column_node = []
                    """若不加这步骤,则没法把孤苦伶点的点收录进来"""
                    if len(row_column[r]) == 1:

                        column_node = row_column[r] * 2

                    else:
                        #将某些元素删除

                        for item in row_column[r]:

                            if item not in column_to_delete:

                                column_node.append(item)

                    row_column_node.append(column_node)

                #修复方法
                fix = False

                #确认是否存在两个以下的节点
                if fix:

                    for item in row_column_node:

                        if len(item) != 2:

                            print(item)

                #进行轮廓内部填充
                fashion = 'new'

                #老办法,用于检验,在不特殊的情况下能得到正确答案
                #如果只有两个节点时直接用老方法填充,比较快
                if fashion == 'old':

                    for i in range(top - bottom + 1):

                        for j in range(right - left + 1):

                            #用abcd代替更简便
                            a, b = min(row_column[i]), max(row_column[i])
                            c, d = min(column_row[j]), max(column_row[j])

                            #绝对坐标
                            absolute_i = bottom + i
                            absolute_j = left + j

                            #判断是否在区域内
                            if a <= absolute_j <= b and c <= absolute_i <= d:

                                pos = [absolute_i, absolute_j]
                                content.append(pos)

                                #对上色过的像素点赋予tag=0
                                temp_img_tag[int(pos[0]), int(pos[1])] = 0

                #适用于所有情况
                if fashion == 'new':

                    for i in range(top - bottom + 1):

                        #行坐标欸
                        row = bottom + i

                        #列坐标
                        for ii in range(len(row_column_node[i]) - 1):

                            #这个列坐标区间内的tag进行判断
                            #column=(row_column[i][ii],row_column[i][ii+1])

                            start_j = row_column_node[i][ii]
                            stop_j = row_column_node[i][ii + 1]

                            #如果区间内全是符合tag的点,则加如集合
                            """用向量进行赋值速度快"""
                            if list(img_tag[row,
                                            start_j:stop_j]) == [this_tag] * (
                                                stop_j - start_j):

                                #对上色过的像素点赋予tag
                                temp_img_tag[row, start_j:stop_j] = 0

                                for column in range(start_j, stop_j):

                                    pos = [row, column]

                                    if pos not in content:
                                        content.append(pos)

                            #确保边缘被收录
                            for column in row_column_node[i]:

                                pos = [row, column]

                                if pos not in content:

                                    content.append(pos)

                                    #对上色过的像素点赋予tag=0
                                    temp_img_tag[int(pos[0]), int(pos[1])] = 0

                #复制结果
                content_row_column = cp.deepcopy(content)

                #重新定义content像素点集合
                content = []

                #column_row
                column_row_node = []

                for c in range(len(column_row)):

                    #要删除的列表
                    row_to_delete = []

                    if len(column_row[c]) > 2:

                        #元素数量大于2时才成立
                        for r in range(1, len(column_row[c]) - 1):

                            bool_former = (column_row[c][r + 1] -
                                           column_row[c][r] == 1)
                            bool_latter = (column_row[c][r] -
                                           column_row[c][r - 1] == 1)

                            #直接删除中间元素
                            if bool_former and bool_latter:

                                #建立需要删除元素的列表
                                row_to_delete.append(column_row[c][r])

                    #要增加的节点列表
                    row_node = []

                    #把孤苦伶点的点收录进来
                    if len(column_row[c]) == 1:

                        row_node = column_row[c] * 2

                    else:

                        #将某些元素删除
                        for item in column_row[c]:

                            if item not in row_to_delete:

                                row_node.append(item)

                    column_row_node.append(row_node)

                #进行轮廓内部填充
                #适用于所有情况
                for j in range(right - left + 1):

                    #行坐标欸
                    column = left + j

                    #列坐标
                    for jj in range(len(column_row_node[j]) - 1):

                        #这个列坐标区间内的tag进行判断
                        #row=(column_row[j][jj],column_row[j][jj+1])

                        start_i = column_row_node[j][jj]
                        stop_i = column_row_node[j][jj + 1]

                        #如果区间内全是符合tag的点,则加如集合
                        """用向量进行赋值速度快"""
                        if list(img_tag[start_i:stop_i,
                                        column]) == [this_tag
                                                     ] * (stop_i - start_i):

                            #对上色过的像素点赋予tag
                            temp_img_tag[start_i:stop_i, column] = 0

                            for row in range(start_i, stop_i):

                                pos = [row, column]

                                if pos not in content:

                                    content.append(pos)

                        #确保边缘被收录
                        for row in column_row_node[j]:

                            pos = [row, column]

                            if pos not in content:

                                content.append(pos)

                                #对上色过的像素点赋予tag=0
                                temp_img_tag[int(pos[0]), int(pos[1])] = 0

                #复制结果
                content_column_row = cp.deepcopy(content)

                #互相验证两种收集模式的结果:比较两集合结果是否相等
                verification = True

                for item in content_column_row:

                    if item not in content_row_column:

                        verification = False

                if verification:

                    #判断结果的count
                    count_for_judge = 0

                    #判断content是否包含了edge
                    for item in edge:

                        if item in content:

                            count_for_judge += 1

                    #判断列表长度是否相等
                    if count_for_judge == len(edge):

                        print('content includes edge')

                    #对content属性赋值
                    this_fraction.content = content

                    #                    print(len(this_fraction.content))

                    #初始化id
                    this_fraction.InitId()
                    this_fraction.InitCenter()

                    #content_sum=Content[0]+Content[1]+...
                    content_sum += content

                    #Content[0],Content[1]是每个块体像素点的集合
                    that_fractions.append(this_fraction)

                    #判断循环是否需要中止:1和2代表不同方法
                    method_for_stop = 2
                    """1 判断条件为新的img_tag是否还存在标签值"""
                    #这种方法要特别久
                    if method_for_stop == 1:

                        #符合条件的tag不在content_sum中的数量
                        count_for_stop = 0

                        for i in range(np.shape(img_tag)[0]):

                            for j in range(np.shape(img_tag)[1]):

                                if img_tag[i, j] == this_tag:

                                    pos = [i, j]
                                    if pos not in content_sum:

                                        count_for_stop += 1

                        #循环结束的判断条件
                        if count_for_stop == 0:

                            #继续遍历的标志关闭
                            content_flag = False
                    """2 判断条件为temp_img_tag是否存在tag"""
                    if method_for_stop == 2:

                        content_flag = this_tag in temp_img_tag

                        if content_flag:

                            print('picking is not complete')

                        #判断类型并输出
                        else:

                            if isinstance(this_fraction, fault):

                                name = 'fault'

                            if isinstance(this_fraction, layer):

                                name = 'layer'

                            print(name, 'id:', this_fraction.id)
                            print('everything is OK')

    #检查'everything is OK'是否成立
    check = False

    if check:

        count = 0

        for i in range(np.shape(temp_img_tag)[0]):

            for j in range(np.shape(temp_img_tag)[1]):

                if temp_img_tag[i, j] == this_tag:

                    count += 1

        print(count)

    #显示一下Content的位置
    if show:

        Dis.ShowFractions(that_fractions, img_rgb, rgb_dict, axis, text,
                          output)

    return that_fractions
Ejemplo n.º 11
0
def PickLayer(total_fractions, img_rgb, show=False, axis=True):

    print('')
    print('here comes a new layer')
    print('......')
    print('please pick the layer')

    #点击获取像素点坐标
    layer_point_pos = plt.ginput(1)[0]

    print('......')
    print('picking the layer')

    #注意反过来,因为是xy坐标
    pos_xy = [int(layer_point_pos[0]), int(layer_point_pos[1])]

    pos_IJ = cp.deepcopy(pos_xy)

    #IJ形式是xy形式的颠倒
    pos_IJ.reverse()

    #所有fault的列表
    total_layers = []

    #这个点到所有fault的距离列表
    distance_total_layers = []

    #建立所有fault的列表
    #计算这个点到fault中心的远近
    for this_fraction in total_fractions:

        if isinstance(this_fraction, layer):

            #上车上车
            total_layers.append(this_fraction)

            #计算距离
            distance_this_layer = Geom.Distance(this_fraction.center, pos_xy)
            distance_total_layers.append(distance_this_layer)

    #队距离和fault对象建立索引你关系
    map_distance_total_layers = dict(zip(distance_total_layers, total_layers))

    #    print(total_faults)

    for this_layer in total_layers:

        #首先直接判断是否位于content内部
        if pos_IJ in this_layer.content:

            print('......')
            print('picking of the layer is over')

            if show:

                Dis.ShowEdge(this_layer, img_rgb, axis)

            return this_layer

    #其次如果第一下没点上,通过计算距离远近来判断
    that_fraction = map_distance_total_layers[min(distance_total_layers)]

    print('......')
    print('picking of the layer is over')

    if show:

        Dis.ShowEdge(that_fraction, img_rgb, axis)

    return that_fraction
Ejemplo n.º 12
0
def PickAndGeneratePlate(total_fractions, img_rgb):

    print('')
    print('here comes a new plate')

    #建立fractions的content
    Content = []

    #建立pos总集合
    for this_fraction in total_fractions:

        Content += this_fraction.content

    #这个plate中所有的fractions
    that_fractions = []

    count = 0

    import copy

    #像素矩阵
    img_rgb_temp = copy.deepcopy(img_rgb)

    #循环呗
    while True:

        print('......')
        print('please pick the layer')

        #点击获取像素点坐标
        layer_point_pos = plt.ginput(1)[0]

        #注意反过来,因为是xy坐标
        pos_xy = [int(layer_point_pos[0]), int(layer_point_pos[1])]

        pos_IJ = copy.deepcopy(pos_xy)

        #IJ形式是xy形式的颠倒
        pos_IJ.reverse()

        #    print('......')
        #    print(pos_IJ)

        #如果点到外面,此plate的fraction提取结束
        if pos_IJ not in Content:

            print('......')
            print('layer picking of this plate is over')

            break

        #判断这个坐标合理与否
        for this_fraction in total_fractions:

            #判断他在哪
            if pos_IJ in this_fraction.content:

                #且不在已收录的fraction对象集中
                if this_fraction in that_fractions:

                    print('......')
                    print('this layer is already picked')

                    break

                if this_fraction not in that_fractions:

                    count += 1

                    print('......')
                    print('picking the layer' + '' + str(count))

                    Dis.ShowEdge(this_fraction, img_rgb_temp)

                    that_fractions.append(this_fraction)

                    break

    #显示一下呗
    plt.figure()
    plt.imshow(img_rgb_temp)

    #生成的plate对象
    that_plate = plate()

    #初始化
    that_plate.Init(that_fractions)

    return that_plate
Ejemplo n.º 13
0
        if [cross_points[0][0], cross_points[0][1] + 1] in which_layer.content:

            #            print('0')

            right_attachment_point = cp.deepcopy(cross_points[0])
            left_attachment_point = cp.deepcopy(cross_points[-1])

        if [cross_points[0][0], cross_points[0][1] - 1] in which_layer.content:

            #            print('1')

            right_attachment_point = cp.deepcopy(cross_points[-1])
            left_attachment_point = cp.deepcopy(cross_points[0])

        #确认一下它们的位置?
        Dis.ShowOnePoint(right_attachment_point, img_rgb, 5)
        Dis.ShowOnePoint(left_attachment_point, img_rgb, 10)

        #所有的faults,不能复制地址
        total_faults = cp.copy(neighbor_faults)

        #删除这个fault
        total_faults.remove(this_fault)

        #this_fault的左右衔接fault
        other_faults = cp.deepcopy(total_faults)
        '''找左右faults集合'''
        left_other_faults = [
            this_other_fault for this_other_fault in other_faults
            if this_other_fault.center[1] < this_fault.center[1]
        ]