composite images
composite images
Hi everyone
I have a set of images which all have a common background. Each one has a unique colored block placed on top of the background, somewhere within the image. What I want to do is combine these images into one. The background should be kept unchanged, and ALL blocks should appear in the final combined image. I have some example images to illustrate what I'm trying to do, but I can't seem to find a way to upload them here...
Can anyone point me in the right direction?
Thanks!
Emma
I have a set of images which all have a common background. Each one has a unique colored block placed on top of the background, somewhere within the image. What I want to do is combine these images into one. The background should be kept unchanged, and ALL blocks should appear in the final combined image. I have some example images to illustrate what I'm trying to do, but I can't seem to find a way to upload them here...
Can anyone point me in the right direction?
Thanks!
Emma
Re: composite images
You can not save the images on the forum; you will need to upload then to either a website or free image hosting site.
How are you using Imagemagick comand line, php, API ?
I would decide on a an image to use as the base image and not modify that; all the other images - change the background to transparent and overlay them onto the first image.
Something along the lines of this: http://www.rubblewebs.co.uk/imagemagick ... _f_75.html
How are you using Imagemagick comand line, php, API ?
I would decide on a an image to use as the base image and not modify that; all the other images - change the background to transparent and overlay them onto the first image.
Something along the lines of this: http://www.rubblewebs.co.uk/imagemagick ... _f_75.html
Re: composite images
I am using Imagemagick from the command line in Cygwin.
The tricky part is that my background is not just a solid. It has a complicated pattern. So I'm not sure how to make that transparent in all my images?
I do have one image which contains ONLY the background. "Mathematically", what I want to do is the following:
BackgroundImage + (Image01 - BackgroundImage) + (Image02 - BackgroundImage) + ...
where "Image01 - BackgroundImage" means Image01 with the background being transparent. So, the pixels in the BackgroundImage which are identical to the pixels in Image01 should be removed (made transparent). How do I do this? I haven't used php, and I would prefer doing this from a command line if possible.
Thanks for your help.
Emma
The tricky part is that my background is not just a solid. It has a complicated pattern. So I'm not sure how to make that transparent in all my images?
I do have one image which contains ONLY the background. "Mathematically", what I want to do is the following:
BackgroundImage + (Image01 - BackgroundImage) + (Image02 - BackgroundImage) + ...
where "Image01 - BackgroundImage" means Image01 with the background being transparent. So, the pixels in the BackgroundImage which are identical to the pixels in Image01 should be removed (made transparent). How do I do this? I haven't used php, and I would prefer doing this from a command line if possible.
Thanks for your help.
Emma
Re: composite images
You should still be able to do all you need is lateral thinking - try and upload some images somewhere.
Anthony has an example with a known background near the bottom of this page: http://www.imagemagick.org/Usage/channels/
Anthony has an example with a known background near the bottom of this page: http://www.imagemagick.org/Usage/channels/
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: composite images
see changemask and/or difference under -compose
http://www.imagemagick.org/Usage/channels/#mask_bgnd
Basically you create a mask from the changed area and use that to make the image transparent where there is background.
http://www.imagemagick.org/Usage/channels/#mask_bgnd
Basically you create a mask from the changed area and use that to make the image transparent where there is background.
Re: composite images
hi everyone
It seems that my ImageMagick doesn't recognize "ChangeMask":
$ convert 01.bmp bg.bmp -compose ChangeMask -composite bg_removed.bmp
convert: unrecognized compose operator `ChangeMask'.
Any ideas why?
Thanks
Emma
It seems that my ImageMagick doesn't recognize "ChangeMask":
$ convert 01.bmp bg.bmp -compose ChangeMask -composite bg_removed.bmp
convert: unrecognized compose operator `ChangeMask'.
Any ideas why?
Thanks
Emma
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: composite images
changemask was added in 6.3.3-4.
For your version of IM type:
and for a list of the compose operators in your current version type:
Pete
For your version of IM type:
Code: Select all
convert -version
Code: Select all
convert -list compose
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: composite images
ChangeMask is a new addition that was added to make the addition of GIF Animation Transparent Optimization work correctly.
It is actually equivalent to masking the image using a thresholded difference image, to find what parts of the image changed (or didn't).
Questions....
It is actually equivalent to masking the image using a thresholded difference image, to find what parts of the image changed (or didn't).
Questions....
- Could the changes to the background in each image overlap when they are merged together? And if so do they have 'anti-aliased' edges (that is semi-transparent changes to the background)?
If this is the case you will have to use the more complex, background removal to try and extract the overlays while preserving the semi-transparent pixels, so that when the extracted overlay overlays a different overlay, the semi-transparent pixels change reasonably correctly.
See Masking with Anti-Aliased Edges. - Do you have a copy of the background without any overlay at all?
Such an image makes the processing a lot simpler. If you don't you may be able to generate one using a technique of merging two images which do not have overlapping changes,m such as described in... Double Exposure.
That same section also describes the automatic generation of change masks so you can merge the images, but only if the changes DO NOT OVERLAP themselves. It is a good guide for basic 'common background' image merging.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: composite images
Hi all
Thanks for your help.
Looks like cygwin does not yet have the most recent version of ImageMagick.
I'm afraid I don't understand anthony's first question... The answer to the second question is, Yes, I do have an image which contains only the background.
Here is a link showing what I'm trying to do. I have access to the first 4 of the images, and I would like to be able to produce the last ("Combined") version, which includes the background as well as all the additions that are present in the other images.
http://www.boulder.swri.edu/~emma/work/misc/index.html
Thanks
Emma
Thanks for your help.
Looks like cygwin does not yet have the most recent version of ImageMagick.
I'm afraid I don't understand anthony's first question... The answer to the second question is, Yes, I do have an image which contains only the background.
Here is a link showing what I'm trying to do. I have access to the first 4 of the images, and I would like to be able to produce the last ("Combined") version, which includes the background as well as all the additions that are present in the other images.
http://www.boulder.swri.edu/~emma/work/misc/index.html
Thanks
Emma
Re: composite images
Btw, the real images that I'm working with are much more complex... background is not as simple as two turcoise lines... Just thought I'd point this out.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: composite images
create an image which is the difference of each image from the clean background image using -compose change_mask -composite. then overlay each of those difference images onto the clean background image.
see http://www.imagemagick.org/Usage/compose/#changemask
Note changemask requires IM 6.3.4. So you may need to upgrade your version of IM
To see what you are running:
identify -version
Here are the command lines that seem to work to do what you want:
convert 01.JPG bg.JPG -compose change_mask -composite 01a.png
convert 02.JPG bg.JPG -compose change_mask -composite 02a.png
convert 03.JPG bg.JPG -compose change_mask -composite 03a.png
convert bg.JPG 01a.png 02a.png 03a.png -flatten 123bg.png
Here are the images:
http://www.fmwconcepts.com/misc_tests/f ... ts/01a.png
http://www.fmwconcepts.com/misc_tests/f ... ts/02a.png
http://www.fmwconcepts.com/misc_tests/f ... ts/03a.png
http://www.fmwconcepts.com/misc_tests/f ... /123bg.png
However, part of your problem is that your images are JPG and thus have corrupted the colors due to compression around the extra color areas. Thus the difference image has some white and other colors around it that are not just the added blocks of color. You really need to have each of these images created from scratch as PNG to get a cleaner result.
The following works (and needs the -compose over, as I am not sure what the default is, but it does not work without it)
convert bg.JPG \
\( 01.JPG bg.JPG -compose change_mask -composite \) \
\( 02.JPG bg.JPG -compose change_mask -composite \) \
\( 03.JPG bg.JPG -compose change_mask -composite \) \
-compose over -flatten 123bg.png
On the other hand, this works also but is slightly more complicated:
convert bg.JPG \
\( 01.JPG bg.JPG -compose change_mask -composite \) -composite \
\( 02.JPG bg.JPG -compose change_mask -composite \) -composite \
\( 03.JPG bg.JPG -compose change_mask -composite \) -composite \
123bg.png
see http://www.imagemagick.org/Usage/compose/#changemask
Note changemask requires IM 6.3.4. So you may need to upgrade your version of IM
To see what you are running:
identify -version
Here are the command lines that seem to work to do what you want:
convert 01.JPG bg.JPG -compose change_mask -composite 01a.png
convert 02.JPG bg.JPG -compose change_mask -composite 02a.png
convert 03.JPG bg.JPG -compose change_mask -composite 03a.png
convert bg.JPG 01a.png 02a.png 03a.png -flatten 123bg.png
Here are the images:
http://www.fmwconcepts.com/misc_tests/f ... ts/01a.png
http://www.fmwconcepts.com/misc_tests/f ... ts/02a.png
http://www.fmwconcepts.com/misc_tests/f ... ts/03a.png
http://www.fmwconcepts.com/misc_tests/f ... /123bg.png
However, part of your problem is that your images are JPG and thus have corrupted the colors due to compression around the extra color areas. Thus the difference image has some white and other colors around it that are not just the added blocks of color. You really need to have each of these images created from scratch as PNG to get a cleaner result.
The following works (and needs the -compose over, as I am not sure what the default is, but it does not work without it)
convert bg.JPG \
\( 01.JPG bg.JPG -compose change_mask -composite \) \
\( 02.JPG bg.JPG -compose change_mask -composite \) \
\( 03.JPG bg.JPG -compose change_mask -composite \) \
-compose over -flatten 123bg.png
On the other hand, this works also but is slightly more complicated:
convert bg.JPG \
\( 01.JPG bg.JPG -compose change_mask -composite \) -composite \
\( 02.JPG bg.JPG -compose change_mask -composite \) -composite \
\( 03.JPG bg.JPG -compose change_mask -composite \) -composite \
123bg.png
Last edited by fmw42 on 2008-08-14T12:17:31-07:00, edited 3 times in total.
Re: composite images
Another method:
A bit messy but could be cleaned up a lot especialy if you use php
Code: Select all
<?php
// Make a mask
$cmd = "01.jpg -fuzz 20% -transparent #fe0000 ";
exec(" convert $cmd temp1.png");
// Put the mask over the original and remove everything apart from the colour
exec("composite -compose Dst_Out temp1.png -gravity center 01.jpg -matte result1.png");
$cmd = "02.jpg -fuzz 20% -transparent #fe0000 ";
exec(" convert $cmd temp2.png");
exec("composite -compose Dst_Out temp2.png -gravity center 02.jpg -matte result2.png");
$cmd = "03.jpg -fuzz 20% -transparent #00fe81 ";
exec(" convert $cmd temp3.png");
exec("composite -compose Dst_Out temp3.png -gravity center 03.jpg -matte result3.png");
// Put all the images together
exec("convert bg.jpg result1.png -gravity center -composite result2.png -gravity center -composite result3.png -gravity center -composite final.jpg");
?>
Re: composite images
Hi again
Response to fmw42: I can not upgrade to a version which has Change_Mask, because I'm using Cygwin. I checked earlier, and Cygwin doesn't have this updated version.
Response to Bonzo: I don't fully understand your code, but it looks like you are manually selecting colors to cut them out. The actual images I'm working with are much more complicated than these example images that I provided. So there is no way I can manually pick out all the colors individually. The real background is actually a picture of Pluto and its moons, and stars in the background. But the backgrounds ARE identical in all the images.
Anyway.. I think I'm still stuck. Any other ideas? I appreciate all your time on this.
Thanks
Emma
Response to fmw42: I can not upgrade to a version which has Change_Mask, because I'm using Cygwin. I checked earlier, and Cygwin doesn't have this updated version.
Response to Bonzo: I don't fully understand your code, but it looks like you are manually selecting colors to cut them out. The actual images I'm working with are much more complicated than these example images that I provided. So there is no way I can manually pick out all the colors individually. The real background is actually a picture of Pluto and its moons, and stars in the background. But the backgrounds ARE identical in all the images.
Anyway.. I think I'm still stuck. Any other ideas? I appreciate all your time on this.
Thanks
Emma
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: composite images
In the given images, none of the added overlays, will overlay each other in the final result, which answers the first question.embirath wrote:Here is a link showing what I'm trying to do. I have access to the first 4 of the images, and I would like to be able to produce the last ("Combined") version, which includes the background as well as all the additions that are present in the other images.
http://www.boulder.swri.edu/~emma/work/misc/index.html
As such you can generate a simple mask for each overlay by comparing the overlay image with the original background. You can then compose using that mask.
Alturnativally use the ChangeMask composition operator, when comparing the image with the background, to make 'common areas' transparent, then merge them all together.
Example...
Code: Select all
convert bg.JPG \
\( 01.JPG -clone 0 -compose ChangeMask -fuzz 2% -composite \) \
\( 02.JPG -clone 0 -compose ChangeMask -fuzz 2% -composite \) \
\( 03.JPG -clone 0 -compose ChangeMask -fuzz 2% -composite \) \
+compose -flatten combined.jpg
However. if the overlaps can overlap themselves. then you will have problems with the above, and that requires much more complex extraction of the overlay image from the original background as given by my Question 1.
See Masking with Anti-Aliased Edges.
I would really like to be able to do, is convert the technique described in the above link to a new special type of 'ChangeMask' type operator that takes two percentages, instead of a simple threshold 'fuzz' factor. That is a 'low threshold' for transparency, and a 'high threshold' for the opaque parts. So that the pixels that fall in between are made semi-transparent to extract the 'anti-aliasing' properties of the overlay.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: composite images
I completely understand. The ChangeMask is actually a complex composition that internally uses a Difference composition image.embirath wrote:I can not upgrade to a version which has Change_Mask, because I'm using Cygwin. I checked earlier, and Cygwin doesn't have this updated version.
You can see the equivalent at...
Removing a Known Background.
Perhaps you can compile your own version of IM or ask on the Cygwin forums (or here in another topic) if anyone has a later version of IM.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/