I think this could be what you're looking for. First let's create a list of patches:
img = ExampleData[{"TestImage", "Lena"}];
patches = ImagePartition[img, 256, {128, 128}]
I'm not going to use ImageAssemble
to put these back together. The trick is to create black and white masks, one for each patch. This is one example:
And then to use ImageMultiply
to create the following intermediate step:
Now since black is {0,0,0}
and each image has a the right dimensions we can add them all together using ImageAdd
. The implementation looks like this:
img = ExampleData[{"TestImage", "Lena"}];
{w, h} = ImageDimensions[img];
masks[{w_, h_}, {partW_, partH_}, {offsetX_, offsetY_}] :=
Flatten@Table[
Graphics[{
Black, Rectangle[{0, 0}, {w, h}],
White, Rectangle[{offx, offy}, {offx + partW, offy + partH}]
}, ImageSize -> {w, h},
Method -> {"ShrinkWrap" -> True}], {offx, 0,
offsetX Floor[(w - partW)/offsetX], offsetX}, {offy, 0,
offsetY Floor[(h - partH)/offsetY], offsetY}
];
patchesCombine[patches_, masks_] := Module[{masked},
masked = ImageMultiply[img, #] & /@ masks;
Fold[ImageAdd, First@masked, Rest@masked]
]
And can be used like this:
patchesCombine[
patches,
masks[ImageDimensions[img], {256, 256}, {128, 128}]
]
The arguments supplied to masks
are the same arguments that you would supply to ImagePartition
.