Skip to content
Advertisement

Reconstructing an image after using extract_image_patches

I have an autoencoder that takes an image as an input and produces a new image as an output.

The input image (1x1024x1024x3) is split into patches (1024x32x32x3) before being fed to the network.

Once I have the output, also a batch of patches size 1024x32x32x3, I want to be able to reconstruct a 1024x1024x3 image. I thought I had this sussed by simply reshaping, but here’s what happened.

First, the image as read by Tensorflow: Input image

I patched the image with the following code

JavaScript

Here are a couple of patches from this image:

Patched input #168 Patched input #169

But it’s when I reshape this patch data back into an image that things go pear-shaped.

JavaScript

Reconstructed output

In this example, no processing has been done between patching and reconstructing. I have made a version of the code you can use to test this behaviour. To use it, run the following:

JavaScript

The code will make one input image, one patch image, and one output image for each of the 1024 patches in each input image, so comment out the lines that create input and output images if you’re only concerned with saving all the patches.

Somebody, please explain what happened :(

Advertisement

Answer

Use Update#2 – One small example for your task: (TF 1.0)

Considering image of size (4,4,1) converted to patches of size (4,2,2,1) and reconstructed them back to image.

JavaScript

Output:

JavaScript

#Update – for 3 channels (debugging..) working only for p = sqrt(h)

JavaScript

Output :

JavaScript

#Update 2

Reconstructing from the output of extract_image_patches seems difficult. Used other functions to extract patches and reverse the process to reconstruct which seems easier.

JavaScript

Output:

JavaScript

You could see other cool tensor transformation functions here: https://www.tensorflow.org/api_guides/python/array_ops

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement