how to include only certain areas of an image
Posted: 2018-06-09T09:08:37-07:00
Hi,
I am provided with the widths, heights , and coordinates of some rectangles and I need to convert an existing image so that the image after conversion only includes the areas specified by the rectangles. That is, I want to censor all parts of the image that do not fall within the given rectangles.'
I am currently using a command like this to achieve the above :
convert -size dimensionOfImage canvas:SomeColour \(myImage -crop dimensionAndCoordinateOfBox1 \) - geometry coordinateOfBox1 - composite \(myImage -crop dimensionAndCoordinateOfBox2 \) - geometry coordinateOfBox2 - composite myImage
using some example made up numbers, this would be :
convert -size 1000x1000 canvas:black \(myImage -crop 100x100+0+0 \) - geometry +0+0 - composite \(myImage -crop 150x150+200+200 \) - geometry +200+200 - composite myImage
The problem is that this method is slow for my means and also the time required to execute it increases with the number of boxes.
I was thinking of another way which would basically involve drawing the rectangles over the image, saving it to say temp and then comparing temp to the original image to get what is required (although I am unsure of the exact command to do this)
Would be grateful if someone could comment on my approaches and perhaps provide a better(faster) way.
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31
I am on Ubuntu 16.0.4
I am provided with the widths, heights , and coordinates of some rectangles and I need to convert an existing image so that the image after conversion only includes the areas specified by the rectangles. That is, I want to censor all parts of the image that do not fall within the given rectangles.'
I am currently using a command like this to achieve the above :
convert -size dimensionOfImage canvas:SomeColour \(myImage -crop dimensionAndCoordinateOfBox1 \) - geometry coordinateOfBox1 - composite \(myImage -crop dimensionAndCoordinateOfBox2 \) - geometry coordinateOfBox2 - composite myImage
using some example made up numbers, this would be :
convert -size 1000x1000 canvas:black \(myImage -crop 100x100+0+0 \) - geometry +0+0 - composite \(myImage -crop 150x150+200+200 \) - geometry +200+200 - composite myImage
The problem is that this method is slow for my means and also the time required to execute it increases with the number of boxes.
I was thinking of another way which would basically involve drawing the rectangles over the image, saving it to say temp and then comparing temp to the original image to get what is required (although I am unsure of the exact command to do this)
Would be grateful if someone could comment on my approaches and perhaps provide a better(faster) way.
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31
I am on Ubuntu 16.0.4