Page 1 of 1

How to interlace two different images?

Posted: 2009-07-06T14:39:52-07:00
by gibbon
Hello,

I'm a noob and I'm looking for a command line to interlace two different pictures for almost two days. I've searched on IM's website but I didn't find something like that, maybe I didn't searched well but my english is quite poor .

The thing to do:

line1 from image1 ---> line 1 of new image
line1 from image2 ---> line 2 of new image
line2 from image1 ---> line 3 of new image
line2 from image2 ---> line 4 of new image
and so on...

image1 and image2 are in the same resolution and the new image has 2 times more lines.

I would be very gratefull if someone could explain me how to achieve this.

Re: How to interlace two different images?

Posted: 2009-07-06T22:04:56-07:00
by anthony
Now that is a tricky problem... very very tricky.
The problem is there is no 'shuffle' option to shuffle two image lists together!
Though I proposed one many many years ago!

You can use tile cropping to convert each set of images into a sequence of individual rows,
http://www.imagemagick.org/Usage/crop/#crop_tile
but then you still need to shuffle the two rows together!

However by some imagination I have a solution....
1/ append the two images side by side
2/ tile crop the images into the shuffled rows.
3/ append the separated (and now shuffled) rows vertically!

For example, first two images (both the same size)...

Code: Select all

   convert rose:  image1.png
   convert rose: -negate image2.png
Note: the two rose images Images are 70x46 pixels.

now do the three steps...

Code: Select all

   convert image1.png image2.png  +append \
           -crop 70x1 +repage -append \
           row_shuffeled_image.png
If you don't know the size of the image, replace the -crop 70x1 +repage with -crop 0x1 +repage -crop 50%x100% +repage

The other method I thought of was to scale each image by 2, and generate a thrid mask to extract a row from each image alternativally. This used a three image masked composition
http://www.imagemagick.org/Usage/compose/#mask

The mask can be generated using a gray50 pattern image!

Code: Select all

  convert image1.png image2.png  -scale 100x200%\! \
               \( -size 1x92 pattern:gray50 -scale 70x92\! \) \
               -composite   row_shuffeled_image.png
So their are two methods you can use. The second is a lot faster as fewer images are involved.

If you want to separate the images again see...
De-Interlacing a video frame
http://www.imagemagick.org/Usage/video/#deinterlace

Re: How to interlace two different images?

Posted: 2009-07-22T03:26:13-07:00
by aberkl
gibbon wrote:Hello,

line1 from image1 ---> line 1 of new image
line1 from image2 ---> line 2 of new image
line2 from image1 ---> line 3 of new image
line2 from image2 ---> line 4 of new image
and so on...

image1 and image2 are in the same resolution and the new image has 2 times more lines.
Hi gibbon,

did you find a solution for your problem? If yes, I would be very interested in it. Seems I am looking for the exact same thing...
And just out of curiosity: Why are you trying to combine two different images? Is it possibly two images 1920x1080 with 720 lines of active image each? If yes, give me a ping!

Best, Andreas

Re: How to interlace two different images?

Posted: 2009-07-22T09:49:32-07:00
by fmw42
This post might be of interest. viewtopic.php?f=1&t=13483

Re: How to interlace two different images?

Posted: 2009-07-23T08:10:41-07:00
by glennrp
I haven't tested this but it might be pretty fast:

1) Append the two images as in anthony's suggestion above

2) write the resulting image as a raw RGB image, which will be same height
and twice as wide as the original

3) read it back as a raw RGB image but with the dimension changed
to the original width and twice the height. (using -size OriginalWidthxTwiceOriginalHeight)

Glenn

Re: How to interlace two different images?

Posted: 2009-07-23T18:30:17-07:00
by anthony
That would be pretty fast, especially in a pipeline, though any meta-data would be lost, and would be slowed from the IO. On the other had with multiple processes it may be faster!

Much of the slowness of my method is all the work IM does to generate all the row images.
The append part is basically just to get the row image order right.

The use of a striped masking image for a compose operation should be quite fast.

Perhaps some speed tests are needed for all three methods is needed. Say at a couple of different sizes. That actual images themselves do not matter for the test.