Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performing a reflective center pad on an image

This forum thread from an active Kaggle competition mentions something the author calls a "reflective center pad". Basically this is a transformation that takes the edges of the image and reflects them outwards, causing mirroring on the edges of the image, which the author shows slightly but noticeably improves model performance.

For reference, here is the image they post demonstrating this technique:

My question is twofold:

  1. Does this transformation have a canonical name? "Reflective center pad" sounds unofficial.
  2. What's a simple way of expressing this transformation in code, perhaps using numpy and something like skimage?
like image 453
Aleksey Bilogur Avatar asked Oct 22 '25 10:10

Aleksey Bilogur


1 Answers

Does this transformation have a canonical name? "Reflective center pad" sounds unofficial.

"Symmetric padding" is a commonly used expression to refer to this transformation.

What's a simple way of expressing this transformation in code

I think the simplest way to achieve that would be using Numpy's pad with mode='symmetric'.

Demo

import numpy as np
from skimage import data
import matplotlib.pyplot as plt

img = data.astronaut()
padded = np.pad(img, pad_width=((100, 200), (100, 500), (0, 0)), mode='symmetric')

fig, (ax1, ax2) = plt.subplots(2, 1)
ax1.imshow(img)
ax2.imshow(padded)
fig.show()

Padding results

like image 79
Tonechas Avatar answered Oct 24 '25 22:10

Tonechas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!