栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用TensorFlow对图像中的点进行插值采样

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用TensorFlow对图像中的点进行插值采样

没有内置的op可以执行这种插值,但是您应该能够使用现有TensorFlow op的组合来做到这一点。对于双线性情况,我建议采用以下策略:

  1. 根据

    C
    索引张量,计算与四个角点相对应的整数张量。例如(名称假设原点在左上方):

    top_left = tf.cast(tf.floor(C), tf.int32)

    top_right = tf.cast(
    tf.concat(1, [tf.floor(C[:, 0:1]), tf.ceil(C[:, 1:2])]), tf.int32)

    bottom_left = tf.cast(
    tf.concat(1, [tf.ceil(C[:, 0:1]), tf.floor(C[:, 1:2])]), tf.int32)

    bottom_right = tf.cast(tf.ceil(C), tf.int32)

  2. 从代表特定拐角点的每个张量中,从

    I
    这些点处提取值的向量。例如,对于以下功能,在二维情况下执行此操作:

    def get_values_at_coordinates(input, coordinates):

    input_as_vector = tf.reshape(input, [-1])
    coordinates_as_indices = (coordinates[:, 0] * tf.shape(input)[1]) + coordinates[:, 1]
    return tf.gather(input_as_vector, coordinates_as_indices)

    values_at_top_left = get_values_at_coordinates(I, top_left)
    values_at_top_right = get_values_at_coordinates(I, top_right)
    values_at_bottom_left = get_values_at_coordinates(I, bottom_left)
    values_at_bottom_right = get_values_at_coordinates(I, bottom_right)

  3. 首先在水平方向上计算插值:

    # Varies between 0.0 and 1.0.

    horizontal_offset = C[:, 0] - tf.cast(top_left[:, 0], tf.float32)

    horizontal_interpolated_top = (
    ((1.0 - horizontal_offset) * values_at_top_left)
    + (horizontal_offset * values_at_top_right))

    horizontal_interpolated_bottom = (
    ((1.0 - horizontal_offset) * values_at_bottom_left)
    + (horizontal_offset * values_at_bottom_right))

  4. 现在计算垂直方向的插值:

    vertical_offset = C[:, 1] - tf.cast(top_left[:, 1], tf.float32)

    interpolated_result = (
    ((1.0 - vertical_offset) * horizontal_interpolated_top)
    + (vertical_offset * horizontal_interpolated_bottom))



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号