5
$\begingroup$

I would like to do an ArrayPlot where, instead of using colors, I can place my own custom images.

I tried something like ArrayPlot[{0,1,0,1}, ColorRules->{0->img1, 1->img2}], but it looks like some sort of average of the image is taken, which is then used as the color.

Is it possible to do this?

$\endgroup$
3
$\begingroup$

You can use GraphicsGrid:

{img1, img2} = ExampleData[{"TestImage", #}] & /@ {"Lena", "Mandrill"};
GraphicsGrid[RandomInteger[1, {5, 5}] /. {0 -> img1, 1 -> img2},  Spacings -> 0]

enter image description here

Or replace array entries with ImageData of input images, ArrayFlatten the resulting nested array and use Image on the result:

SeedRandom[1]
mat = RandomInteger[1, {5, 5}];
Image[ArrayFlatten[mat /. {0 -> ImageData[img1], 1 -> ImageData[img2]}]] // 
 ImageResize[#, 300] &

enter image description here

$\endgroup$
2
$\begingroup$

You can also use Multicolumn

{img1, img2} = ExampleData[{"TestImage", #}] & /@ {"Lena", "Mandrill"};
Multicolumn[RandomInteger[1, 16] /. {0 -> img1, 1 -> img2}, 
 Spacings -> {0, 0}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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