clear a rectangle
clear a rectangle
I want to clear a rectangular region from an image (ie completely remove the contents of a rectangle and replace them with transparent pixel). My solution right now is to use the composite operation with DstIn/DstOut. But this is very slow because it requires creating an overlay image which in my case has to be really big. Is there a smarter way to that, maybe something similar to what you I would do in a conventional image editor (ie select a rectangular region and the clear the selection, this can be done in O(1) additional memory)?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: clear a rectangle
you can take your transparent rectangle and use -compose copy -composite, but that still requires you to use composite with a transparent image.
convert logo: \( -size 100x100 xc:none \) -alpha set -gravity center -compose copy -composite logo_hole.gif
you can also draw a colored rectangle (of some color that does not match any colors along its border), then do a -draw matte floodfill
cannot say which is faster, but suspect the first will be.
see http://www.imagemagick.org/Usage/draw/#color and http://www.imagemagick.org/Usage/draw/#matte
convert logo: \( -size 100x100 xc:none \) -alpha set -gravity center -compose copy -composite logo_hole.gif
you can also draw a colored rectangle (of some color that does not match any colors along its border), then do a -draw matte floodfill
cannot say which is faster, but suspect the first will be.
see http://www.imagemagick.org/Usage/draw/#color and http://www.imagemagick.org/Usage/draw/#matte
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: clear a rectangle
It does not have to be.. use a smaller image and set a -geometry offset.netro78 wrote:But this is very slow because it requires creating an overlay image which in my case has to be really big
Code: Select all
convert rose: -alpha set -size 20x20 xc: -geometry +20+10 \
-compose DstOut -composite show:
I thought that maybe you could do it with a region, but regions make transparent areas see-thru as it uses a 'Over' method to overlay the modified region images. I have not looked too deeply into regions as yet.
That is this failed...
Code: Select all
convert rose: -alpha set -region 20x20+20+10 -alpha transparent +region show:
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/