python3 图形 编辑,将图像编辑为tensorflow tensor python

给定图像:

92i2e.png

(a)从图像中获取感兴趣的区域((440240),(5353380)):

roi_slice = tf.slice(

image_in,

[top_left_x, top_left_y, top_left_z],

[roi_len_x, roi_len_y, bottom_right_z]

)

ehYbn.png

获取与图像大小相同的ROI的布尔掩码

roi_mask = tf.ones_like(roi_slice)

mask_canvas = tf.image.pad_to_bounding_box(

[roi_mask],

top_left_x,

top_left_y,

np_image.shape[0],

np_image.shape[1]

)

bool_mask = tf.cast(mask_canvas, tf.bool)

QL65t.png

(b)在本例中,我使用的是假渐变,但您可以用真实渐变替换。

fake_gradients = tf.ones_like(image_in) * 0.2

(c)屏蔽梯度,以获得ROI所在的梯度,否则为0。

masked_gradients = tf.where(bool_mask[0], fake_gradients, mask_canvas[0])

(d)制作图像的可编辑副本,并使用遮罩的渐变进行更新

# Make an editable copy of the image

editable_image = tf.get_variable(

name='editable_image', shape=image_in.shape, dtype=tf.float32)

init_op = tf.assign(editable_image, image_in)

# Make sure we don't update the image before we've set its initial value.

with tf.control_dependencies([init_op]):

update_roi_op = tf.assign_add(editable_image, masked_gradients)

oS9F6.png

你可以找到一个完全有效的Colab示例

on GitHub

.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值