crop - Cut out one or more rectangular regions of the image
crop - Cut out one or more rectangular regions of the image
Hi,
I have a set of (overlapping) rectangles and I want to crop a region of ONE image that is coverd by one or more of these rectangles. Example: If first rectangle would be a horizontal bar and second would be a vertical bar both overlapping then I would like to get a cross as THE result image. How do I have to call convert then?
Thank you
I have a set of (overlapping) rectangles and I want to crop a region of ONE image that is coverd by one or more of these rectangles. Example: If first rectangle would be a horizontal bar and second would be a vertical bar both overlapping then I would like to get a cross as THE result image. How do I have to call convert then?
Thank you
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: crop - Cut out one or more rectangular regions of the image
There are many ways. For example:
Arrange to have each rectangle white in an image the size of the original, with the rest of the image black.
Composite these two rectangles, "compose Lighten", so now you have an image that is white there was at least one rectangle and black elsewhere.
Use that "compose CopyOpacity" to paint out any pixels that were not covered by either rectangle.
If you had supplied images, and told us your version of IM and your platform, I could have shown you the commands.
Arrange to have each rectangle white in an image the size of the original, with the rest of the image black.
Composite these two rectangles, "compose Lighten", so now you have an image that is white there was at least one rectangle and black elsewhere.
Use that "compose CopyOpacity" to paint out any pixels that were not covered by either rectangle.
If you had supplied images, and told us your version of IM and your platform, I could have shown you the commands.
snibgo's IM pages: im.snibgo.com
Re: crop - Cut out one or more rectangular regions of the image
Version: ImageMagick 6.8.9-9 Q16 i686 2016-06-01 http://www.imagemagick.org
System: Debian testing
convert rose.png -crop 70x10+0+26 -crop 10x46+30+0 rose_cross.png
(Leads to be a dot at the moment)
Thank you for yout help!!!
System: Debian testing
convert rose.png -crop 70x10+0+26 -crop 10x46+30+0 rose_cross.png
(Leads to be a dot at the moment)
Thank you for yout help!!!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: crop - Cut out one or more rectangular regions of the image
You are making a crop, then making a crop of that, which doesn't leave much.
Perhaps this is what you want (bash script):
Perhaps this is what you want (bash script):
Code: Select all
convert \
rose: \
\( -clone 0 -fill Black -colorize 100 +write mpr:BLCK +delete \) \
\( \
\( mpr:BLCK -region 70x10+0+26 -fill White -colorize 100 \) \
\( mpr:BLCK -region 10x46+30+0 -fill White -colorize 100 \) \
-compose Lighten -composite \
\) \
-compose CopyOpacity -composite \
c.png
snibgo's IM pages: im.snibgo.com
Re: crop - Cut out one or more rectangular regions of the image
I adapted it like this especially setting mpr:block instead of mpr:BLCK which did not work. Now all fine: Thank you very much!!!
convert ~/Downloads/rose.png \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 70x10+0+26 -fill White -colorize 100 \) \( mpr:block -region 10x46+30+0 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite rose_cross.png
convert ~/Downloads/rose.png \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 70x10+0+26 -fill White -colorize 100 \) \( mpr:block -region 10x46+30+0 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite rose_cross.png
Re: crop - Cut out one or more rectangular regions of the image
The example worked but in real there are problems: I used this image: http://www.directupload.net/file/d/4408 ... n3_png.htm
Calling:
convert "/tmp/import_crop.png" \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 338x49+187+0 -fill White -colorize 100 \) \( mpr:block -region 409x156+116+49 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite /tmp/export_crop.bmp
It is exactly the same as above except different numbers. Even file types are identical:
/home/orther/Downloads/rose.png: PNG image data, 70 x 46, 8-bit/color RGB, non-interlaced
/tmp/import_crop.png: PNG image data, 525 x 700, 8-bit/color RGB, non-interlaced
But the result image looks exactly the same like import image. So no change between org and dest picture. What could be the reason? (I tried different image type like bmp, jpg, png. Always output looked like input).
Calling:
convert "/tmp/import_crop.png" \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 338x49+187+0 -fill White -colorize 100 \) \( mpr:block -region 409x156+116+49 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite /tmp/export_crop.bmp
It is exactly the same as above except different numbers. Even file types are identical:
/home/orther/Downloads/rose.png: PNG image data, 70 x 46, 8-bit/color RGB, non-interlaced
/tmp/import_crop.png: PNG image data, 525 x 700, 8-bit/color RGB, non-interlaced
But the result image looks exactly the same like import image. So no change between org and dest picture. What could be the reason? (I tried different image type like bmp, jpg, png. Always output looked like input).
Re: crop - Cut out one or more rectangular regions of the image
Solution found: Export image type must be png and not bmp. If bmp is set there is no change on image. png is cropped. Why ever ...
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: crop - Cut out one or more rectangular regions of the image
PNG supports a virtual canvas that stores the size and offset of each crop. BMP does not support this.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: crop - Cut out one or more rectangular regions of the image
But the commands shown don't rely on offsets being stored in files.
The commands do make pixels transparent, so that won't work when the output doesn't support transparency (eg JPG).
The commands do make pixels transparent, so that won't work when the output doesn't support transparency (eg JPG).
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: crop - Cut out one or more rectangular regions of the image
Sorry, I did not read the post carefully and thought it was another post where virtual canvas was I believe the issue.snibgo wrote:But the commands shown don't rely on offsets being stored in files.
Re: crop - Cut out one or more rectangular regions of the image
I am sorry asking again, I catched the example for one case but could not repeat it.
Using this (very large) image: http://www.file-upload.net/download-117 ... 9.bmp.html saved as page569.bmp
I then called:
convert -crop 525x700+516+1110 page569c.bmp /tmp/figure.png
which should have extracted the left figure. I get the error: convert: invalid chromaticities `/tmp/figure.png' @ warning/png.c/MagickPNGWarningHandler/1671.
So I used:
convert -crop 525x700+516+1110 page569c.bmp /tmp/figure.bmp
which extracted the figure perfectly. Now I want to remove the text around the figure using the frames. I call then:
convert /tmp/figure.bmp \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 338x49+187+0 -fill White -colorize 100 \) \( mpr:block -region 409x156+116+49 -fill White -colorize 100 \) \( mpr:block -region 525x280+0+205 -fill White -colorize 100 \) \( mpr:block -region 483x215+42+484 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite /tmp/figure2.bmp
which relates to the new coordinates of the cropped figure. It does not any effect. /tmp/figure2.bmp looks exactly the same like /tmp/figure.bmp.
What could be the reason?
Using this (very large) image: http://www.file-upload.net/download-117 ... 9.bmp.html saved as page569.bmp
I then called:
convert -crop 525x700+516+1110 page569c.bmp /tmp/figure.png
which should have extracted the left figure. I get the error: convert: invalid chromaticities `/tmp/figure.png' @ warning/png.c/MagickPNGWarningHandler/1671.
So I used:
convert -crop 525x700+516+1110 page569c.bmp /tmp/figure.bmp
which extracted the figure perfectly. Now I want to remove the text around the figure using the frames. I call then:
convert /tmp/figure.bmp \( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \) \( \( mpr:block -region 338x49+187+0 -fill White -colorize 100 \) \( mpr:block -region 409x156+116+49 -fill White -colorize 100 \) \( mpr:block -region 525x280+0+205 -fill White -colorize 100 \) \( mpr:block -region 483x215+42+484 -fill White -colorize 100 \) -compose Lighten -composite \) -compose CopyOpacity -composite /tmp/figure2.bmp
which relates to the new coordinates of the cropped figure. It does not any effect. /tmp/figure2.bmp looks exactly the same like /tmp/figure.bmp.
What could be the reason?
Re: crop - Cut out one or more rectangular regions of the image
As I understand I should make png of it because bmp does not support transparency. Event I get this error I get the png. When calling the frame term on png instead on bmp:
convert /tmp/figure.png \( -clone 0 -fill Bla... ompose CopyOpacity -composite /tmp/figure2.png
it is the same result: /tmp/figure.png and /tmp/figure2.png are identical.
convert /tmp/figure.png \( -clone 0 -fill Bla... ompose CopyOpacity -composite /tmp/figure2.png
it is the same result: /tmp/figure.png and /tmp/figure2.png are identical.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: crop - Cut out one or more rectangular regions of the image
Your syntax is wrong. You should read the image, then crop, then write it.mleo wrote:convert -crop 525x700+516+1110 page569c.bmp /tmp/figure.bmp
"-composite" operates on two images, or two images plus a mask. It won't operate on four images.mleo wrote:convert /tmp/figure.bmp
\( -clone 0 -fill Black -colorize 100 +write mpr:block +delete \)
\(
\( mpr:block -region 338x49+187+0 -fill White -colorize 100 \)
\( mpr:block -region 409x156+116+49 -fill White -colorize 100 \)
\( mpr:block -region 525x280+0+205 -fill White -colorize 100 \)
\( mpr:block -region 483x215+42+484 -fill White -colorize 100 \)
-compose Lighten -composite \)
-compose CopyOpacity -composite /tmp/figure2.bmp
snibgo's IM pages: im.snibgo.com
Re: crop - Cut out one or more rectangular regions of the image
Is there any way to solve this problem cropping an area consisting of two OR MORE rectangles using imagemagick? Otherwise I would calculate outstanding rectangles and draw them as white rectangles onto the picture ...
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: crop - Cut out one or more rectangular regions of the image
If you have many rectangles to include or exclude, drawing them as black or white rectangles is a more obvious method.
snibgo's IM pages: im.snibgo.com