如何使用“转换"撤消或删除绘制的矩形? [英] How to undo or remove the drawn rectangle using Convert?

查看:114
本文介绍了如何使用“转换"撤消或删除绘制的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用转换将其在图像上绘制矩形,现在我想撤消该怎么做?帮助吗?

I have used convert this to draw a rectangle on image now i want to undo this the how? help?

convert Image1.jpg -fill black -draw "rectangle 135,55 155,60" Image2.jpg

推荐答案

在图像上绘制矩形后,它将用矩形颜色替换图像中的像素.您无法撤消该操作.您可以使用Imagemagick中的形态技术,通过对同一矩形制作遮罩,然后将形态处理过的图像或经过中值滤波的图像与具有矩形的图像混合,从而用附近的图像像素的某种解释替换矩形的颜色. 但是更好的方法是使用一些修复工具.但是Imagemagick没有后者.有关详情,请参见OpenCV或Skimage.

Once you draw a rectangle onto an image, it has replace the pixels in the image with the color of rectangle. You cannot undo that. You can replace the color of the rectangle with some interpretation of the image pixels nearby using morphology techniques in Imagemagick by making a mask from the same rectangle and using that to blend the morphology processed image or a median filtered image with the one with a rectangle. But a better method is some inpainting tool. But Imagemagick does not have the latter. See OpenCV or Skimage for that.

这是如何使用形态学(或中值滤波)在Imagemagick中减轻它的方法.

Here is how to mitigate it in Imagemagick using morphology (or median filtering).

创建测试图像

convert lena.png -fill none -stroke black -strokewidth 1 -draw "translate 128,128 rectangle -50,-50 50,50" -alpha off lena_rect.png


使用形态学关闭(或者可以只使用-statistics中位数5x5)

Use morphology close (or one could just use -statistics median 5x5)

convert lena_rect.png -morphology close:3 diamond:1 lena_rect_close.png


为遮罩创建矩形(比图像粗一点)

convert -size 256x256 xc:white -fill none -stroke black -strokewidth 2 -draw "translate 128,128 rectangle -50,-50 50,50" -alpha off -negate rect.png


合成

convert lena_rect.png lena_rect_open.png rect.png -compose over -composite result.png


添加:

为比较起见,这是来自opencv和skimage的3种修复方法.

For comparison, here are 3 inpainting methods from opencv and skimage.

#!/opt/local/bin/python3.7

import cv2
import numpy as np
import skimage.io
import skimage.restoration
import skimage.exposure

# method choice: biharmonic, Navier-Stokes, Telea
method = 'biharmonic'
#method = 'Navier-Stokes'
#method = 'Telea'


if method == 'biharmonic':
    print('biharmonic')

    img = skimage.io.imread('/Users/fred/desktop/lena_rect.png')

    msk = skimage.io.imread('/Users/fred/desktop/rect.png')
    msk = skimage.exposure.rescale_intensity(msk, in_range='image', out_range=(0,1))

    newimg = skimage.restoration.inpaint_biharmonic(img, msk, multichannel=True)

    skimage.io.imsave('/Users/fred/desktop/lena_rect_inpaint_biharmonic.png', newimg)

elif method == 'Navier-Stokes':
    print('Navier-Stokes')

    img = cv2.imread('/Users/fred/desktop/lena_rect.png')

    msk = cv2.imread('/Users/fred/desktop/rect.png',0)

    newimg = cv2.inpaint(img, msk, 3, cv2.INPAINT_NS)

    cv2.imwrite('/Users/fred/desktop/lena_rect_inpaint_navier_stokes_15.png', newimg)

elif method == 'Telea':
    print('Telea')

    img = cv2.imread('/Users/fred/desktop/lena_rect.png')

    msk = cv2.imread('/Users/fred/desktop/rect.png',0)

    newimg = cv2.inpaint(img, msk, 3, cv2.INPAINT_TELEA)

    cv2.imwrite('/Users/fred/desktop/lena_rect_inpaint_telea_3.png', newimg)


双谐波:

Navier-Stokes:

Navier-Stokes:

Telea:

这篇关于如何使用“转换"撤消或删除绘制的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆