Distorted Merge of two images..Please help

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Distorted Merge of two images..Please help

Post by sainib »

Important Note for Anthony - I tried sending this message via email to you, Anthony, but posting in the forum too because I dont know if email went through. I did not get a confirmation so my apologies if this is duplicate for you!.

--------

I have been learning ImageMagick for a couple of months now and just love this piece of art. It is just amazing.

I am trying to do something that I am not sure if and how it can be done with ImageMagick, so I am reaching out to you for your help.

My goal is to merge two images of same size into one and the resulting image should have pixel at any given point picked up randomly from only one of the two input images. So, by controlling the percentages of pixels contributed by two input images into final image and generating a series of images can produce a nice animation.

Any help and pointers are appreciated.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distorted Merge of two images..Please help

Post by fmw42 »

create an image of random noise same size as your two images. then make it binary (either full black or full white, no gray). Then use the binary image to composite the two images over each other using the binary image as a mask to determine which pixel comes from which image.

example mask:
convert -size 128x128 xc: +noise random -colorspace gray -threshold 50% tmp_random.png
or
convert -size 128x128 xc: +noise random -threshold 50% -channel g -separate tmp_random.png

Then

convert zelda3.jpg lena2.jpg tmp_random.png -compose over -composite zelda_lena_random.jpg

see
http://www.imagemagick.org/Usage/backgrounds/
http://www.imagemagick.org/Usage/canvas/#random

and

http://www.imagemagick.org/Usage/compose/#compose


If you change the threshold from 0 to 100% and add -seed X so that the seed stays constant, you can animate this as a random transition. Perhaps also try without the -seed, so that the random pattern changes each time.
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

Thanks a lot! I really appreciate your help and quick response.

The commands you provided worked right away and gave the results I wanted..your explanation was very clear and made perfect sense, it just took me sometime to map the explanation to the command, which I wanted to do for my own understanding, but I went back to the documentation for each option used in command and think I understand what happened 'behind the commands' better now.. At first it was a pure magick to me ;)

Best Regards
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distorted Merge of two images..Please help

Post by fmw42 »

glad it helped. post a link to your resulting animation, if you can, as I would like to see an example of what you produced.
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

Sure and thanks for your interest!

I actually created a series of images with varying degree of threshold to create the transition.

I posted the video on a blog on blogspot, where I plan to post other videos I create as I continue to learn

http://ffmagick.blogspot.com/2011/11/experiment-1.html

There are four transitions in this video - the first and last one are using the new masked composite images that I learned from you, the second one uses the "-compose dissolve" and third one uses blend..I really did not see a lot of difference between dissolve and blend. I mean at least from the standpoint of converting series of images into a movie, I understand the minor difference in how the pixel info is written to the target image from explanation in the documentation.

Also,I am using ffmpeg to convert the images into a movie.

Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distorted Merge of two images..Please help

Post by fmw42 »

Nice transitions. if you are on Linux/Mac, you might be interested in my transitions bash shell script at the link below and perhaps my shapemorph script as well. Also see pagecurl and pagepeel.
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

Fred - Thanks for the encouragement.. I am just a rookie yet but plan to learn more of imageMagick.. I have not been more impressed with a single software as much as IM has impressed me.. And on top of that, your script library is just awesome. It will be a great learning resource..but I do not plan to try and write transitions myself to learn more about IM.. Best Regards.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Distorted Merge of two images..Please help

Post by anthony »

I promised you via email that I would give an answer here. But it seems Fred (fmw42) has already given most of it :-)

The solution is as fred pointed out, to have a random image which you then use a threshold, and then use it as a image selection mask.

See three image composite masking
http://www.imagemagick.org/Usage/compose/#mask

When creating the animation however it is important to use the same initial random image (varying the threshold) to create the animatied 'transition sequence'.

Fred has already created a script (unix shell script) for this whcih he calls 'transitions'
http://www.fmwconcepts.com/imagemagick/ ... /index.php
This includes purely random pixel transitions too.

But their are lots of other ways of doing transitions.
See a couple of them in... IM Examples, Animation Modifications, Morphing and Distorts...
http://www.imagemagick.org/Usage/anim_mods/#morph

However I would like to see what you eventually come up with..
Post examples. You can put images on a free cloud service like "dropbox" and then post a link to it in this discussion.

If you have more trouble, ask here. We are more than glad to help.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

Thanks a lot Anthony..This is a great explanation. It may seem dramatic with my appreciations but I just have not experienced this level of details and quality of responses on other software forums.

I would be happy to share what I create. I actually created a blog on blogspot to upload the results but dropbox is also a good idea.

My original goal was to create a script something like - http://dvd-slideshow.sourceforge.net/wiki/Main_Page - but much more flexible and extensible so more and different types of transitions and effects can be added rather easily, which is not so straight forward in dvd-slideshow.

I am at a very basic stage right now..actually the first video I uploaded on the blog screams that too ;) but you could view it here, if you wish

http://ffmagick.blogspot.com/2011/11/experiment-1.html

I appreciate your response again and I look forward to learning more in future from you and Fred.

Best Regards
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Distorted Merge of two images..Please help

Post by anthony »

When you feel it is up to review by us. Return to this forum to share the link.

Me sure to mention that is it 'powered by ImageMagick' :-)


Note how fred's "transitions" script allows the same make to control not only a variable blinder like transition, but also allows on to be used to provide a variable cross fade, where some parts of an image fade to the other image, before other parts.

That is rather than use it as a 'thresholded mask', he uses it as a dissolve mask.

The two are closely related and you can even add a control to adjust how sharp that threshold/crossfade transition is. From a highly aliased 'pixel level threshold wipe' to a blurred line of cross-fading, all the way well spread out variable cross-fade.

Note that what you call 'wipe' on your page is actually more of a horizontal 'roll' to a new scene.
You can also do such rolls vertically, or even diagonally! See example (to same image) in...
http://www.imagemagick.org/Usage/anim_mods/#distort

How about a more interesting compound transition. Take the rotating image animation example in the last link above, but do a cross fade at the same time!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

Hey Anthony / Fred - I worked on another transition that I think need little bit of more fine tuning but wanted to share with you guys..

http://ffmagick.blogspot.com/2011/11/experiment-2.html

Let me know what you think. Its not really as smooth as I wanted it to be.. so will spend more time on that. Thanks guys!


BTW - Anthony - Great transition suggestions above. I will give it a shot. Thanks again
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Distorted Merge of two images..Please help

Post by fmw42 »

very nice and different transition effect.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Distorted Merge of two images..Please help

Post by anthony »

sainib wrote:Hey Anthony / Fred - I worked on another transition that I think need little bit of more fine tuning but wanted to share with you guys..
http://ffmagick.blogspot.com/2011/11/experiment-2.html
The page fails with firefox -- java errors and totally blank, though I can see the page source that was loaded
But it worked fine with chrome.

Your experiment 1 should your 'pixel' transitions. But as I mentioned that would work a lot better as either a fairly standard 'dissolve fade' (overlay new with increasing transparency). Or if you only generated one fixed random image, with different threshold levels. This is what fred's transitions script does.

Note also that with video, you should arrange so the video continues to run during the transition! Looks much better, though it does 'clip' the end and start of the video you are transitioning.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sainib
Posts: 7
Joined: 2011-11-03T20:49:59-07:00
Authentication code: 8675308

Re: Distorted Merge of two images..Please help

Post by sainib »

@Fred - Thanks!

@Anthony - Thanks! I am sorry about the problem in firefox. This is a third party's (google) blogging platform and I dont have much control over the code. I am surprise to hear that one of google's product is not compatible to firefox. In any case, I am glad that you were able to access the site using chrome.

I think, as part of my practice, I created the fade-in effect.. let me upload that to the site.

Regarding the idea of keeping the video rolling during transition sounds interesting. I will give that a shot. I also fixed the problem with the script that was causing to the video to get clipped.
Post Reply