How to Extract 3d patches using unfold?

First, how can deal with the margin problem when I using unfold function for many times to extract 3d patches, because I found that some of pixels in margin will be ignored when the patch size can not be exactly divided.
Second, in the test set, how can I recover the original Image size after predict label through networks?

I’m not sure, if there is an easy way to create patches and reconstruct the input image without padding, if the shapes do not match.
Have a look at this post to see, how to use padding to reconstruct the input again.

Thank you, you really help me .