22
$\begingroup$

I have the following images, both 480 x 270 pixels:

AquaSilk (Zangief) vs EMP EvilRahsaan (Blanka) - capture 1

AquaSilk (Zangief) vs EMP EvilRahsaan (Gen) - capture 2

I'd like to stitch them side by side in a 960 x 270 pixel image like so (scaled down):

images side-by-side

So far, I've been using GraphicsGrid to try to achieve this:

c1 = Import["https://i.stack.imgur.com/2SRcD.png"];
c2 = Import["https://i.stack.imgur.com/zL8id.png"];
(* Frame parameter set here to emphasize next point. *)
g = GraphicsGrid[{{c1, c2}}, Frame -> True]

But there's padding between the images:

GraphicsGrid call with c1 and c2

Additionally, it's scaled incorrectly, as ImageDimensions shows:

ImageDimensions@g

(* Expect {960, 540} *)
{360, 180}

I can use the ImageSize parameter to explicitly set the size of the output image, but that just reproduces the above result to scale.

How can combine the images side-by-side without scaling or padding?

$\endgroup$
3
  • $\begingroup$ My proxy/firewall won't let me Import the pictures, but isn't this a job for ImagePadding->None? $\endgroup$
    – Verbeia
    Jan 19, 2012 at 3:47
  • $\begingroup$ @Verbeia ImagePadding -> None actually masks the entire image with a thick white border all around, cropping the images in half with the parts along the vertical center being exposed. $\endgroup$
    – casperOne
    Jan 19, 2012 at 3:50
  • $\begingroup$ Try Grid instead of GraphicsGrid. I'm at work now so I can't really pursue this now, but GraphicsGrid enforces equal column widths, so this might be causing a problem. ImageAssemble is the neatest solution, but there are others. $\endgroup$
    – Verbeia
    Jan 19, 2012 at 3:55

2 Answers 2

30
$\begingroup$

What you're looking for is ImageAssemble:

c1 = Import["https://i.stack.imgur.com/2SRcD.png"];
c2 = Import["https://i.stack.imgur.com/zL8id.png"];
ImageAssemble[{c1, c2}]

Mathematica graphic

It can also assemble vertically and horizontally:

ImageAssemble[{{c1, c1}, {c2, c2}}]

Mathematica graphic

$\endgroup$
1
  • $\begingroup$ As well as fleshing out the answer, I'm actually doing the 4x4, but displaying the NxN case is the best answer overall. $\endgroup$
    – casperOne
    Jan 19, 2012 at 3:48
7
$\begingroup$

Incidentally, ImageDimensions on GraphicsGrid is behaving correctly. GraphicsGrid is generating an object with head Graphics, with a default width of 360 points, and the contents scaled down to fit. ImageDimensions then creates a bitmap version of the graphic, maintaining the size on screen, and returns the dimensions for that.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.