3
$\begingroup$

I want to do ImagePartition with offset whose offset size is different with x(horizontal) and y(vertical). Here I got Lena image from https://en.wikipedia.org/wiki/Lenna#/media/File:Lenna_(test_image).png

lena=Import["/Downloads/Lenna_(test_image).png"]
Dimensions[ImageData[lena]]

The dimension was 512x512.

I want to part this image into small images, as in the size of horizontal = 80 pixels, verticle = 32pixels. The overlap between images are horizontal = 44 pixels and verticle = 16 pixels.

Since 80 + (80 - 44)x(13 - 1)= 512, 32 + (32 - 16)x(31 - 1)= 512, I think the number of small images become 13 (horizontal) x 31 (verticle). However, when I try

lenap = ImagePartition[lena, {80, 32}, {80 - 44, 32 - 16}]
Dimensions[lenap]

The number of image was 12(horzontal) x 31(verticle). I can't understand why the number of only horizontal images was strange, i.e. not 13... Also, the Image of

lenap[[1,-1]]

should be same as

ImageTake[lena,{1,32},{512-80+1,512}]

However these images are not same, maybe next pictures each other.

If someone who knows how to ImagePartition with offset properly, please help me!

Also, I want to confirm whether the whole image was used for the Image-partition, I want to reconstruct them into one image. I found another question as Inverse ImagePartition with offset I wanted to do the similar thing, but I don't know which parameter I should change... below didn't work.

ImageAssemble[ArrayFlatten[{{Map[ImageTake[#, dh, dw] &, 
 Drop[part, -44, -16], {2}], 
Map[ImageTake[#, dh, {1, -1}] &, part[[;; -2, {-1}]], {2}]}, {Map[
 ImageTake[#, {1, -1}, dw] &, part[[{-1}, ;; -2]], {2}], 
part[[{-1}, {-1}]]}}]]
$\endgroup$

1 Answer 1

3
$\begingroup$

It is a bug. If we compare it with Partition used on ImageData we see that indeed it must be 13x31 partitions. It can also be seen that the right part of image is missing after reassembling.

lena = Import[
  "https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%\
29.png"]

Map[Image, 
  Partition[ImageData[lena], Reverse@{80, 32}, 
   Reverse@{80 - 44, 32 - 16}], {2}] // ImageAssemble

ImagePartition[lena, {80, 32}, {80 - 44, 32 - 16}] // ImageAssemble

enter image description here

enter image description here

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Thank you so much!!! Your answer is very useful. I just believed the Mathematica code and have never doubted the bug... Also, thanks again for telling me how to use ImageAssemble command properly. $\endgroup$
    – rani
    Commented Mar 6 at 0:50

Your Answer

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

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