when I call the function ImagePartition I get an image list from which I can reconstruct the image by calling ImageAssemble onto the list.

I would like to be able to reconstruct the image after I call ImagePartition with a given offset. For example:


Is there a quick solution to this or do I have to revert the images back into normal lists?

Best, Max


1 Answer 1


Assuming the offsets are less or equal to to the subimage sizes:

FromImagePartition[part_, {_, _}, {dw_, dh_}] := ImageAssemble[ArrayFlatten[{
      {Map[ImageTake[#, dh, dw] &, Drop[part, -1, -1], {2}],
       Map[ImageTake[#, dh, {1, -1}] &, part[[;; -2, {-1}]], {2}]},
      {Map[ImageTake[#, {1, -1}, dw] &, part[[{-1}, ;; -2]], {2}],
       part[[{-1}, {-1}]]}}]]

though I'm not sure if it's quick. Example:

im = Import["ExampleData/spikey.tiff"]
part = ImagePartition[im, {50, 25}, {7, 4}];
inv = FromImagePartition[part, {50, 25},{7, 4}]

ImageData[inv, "Byte"] ===
  ImageData[ImageTake[im, Sequence @@ ImageDimensions[inv][[{-1, 1}]]], "Byte"]
(* True *)

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.