This filter will set [0,0] to zero in frequency domain, effectivly removing DC components.


In [1]:
%run ../common.ipynb


Populating the interactive namespace from numpy and matplotlib

In [2]:
image = imread('../MP.tiff')

In [3]:
image.shape


Out[3]:
(2111, 2198)

In [4]:
imshow(image, figure=figure(figsize=(12,12)), cmap='gray')


Out[4]:
(<matplotlib.figure.Figure at 0x1034908d0>,
 <matplotlib.axes._subplots.AxesSubplot at 0x10798e810>,
 <matplotlib.image.AxesImage at 0x1079be310>)

In [5]:
F = fft2(image)

In [6]:
F[0,0] = 0

In [11]:
f = ifft2(F).real

In [12]:
imshow(f)


Out[12]:
(<matplotlib.figure.Figure at 0x103525590>,
 <matplotlib.axes._subplots.AxesSubplot at 0x103521dd0>,
 <matplotlib.image.AxesImage at 0x1034e8090>)

In [13]:
imshow(f, figure=figure(figsize=(12,12)), cmap='gray')


Out[13]:
(<matplotlib.figure.Figure at 0x11f33ec10>,
 <matplotlib.axes._subplots.AxesSubplot at 0x1034cefd0>,
 <matplotlib.image.AxesImage at 0x10351da90>)

In [14]:
f.real[100:110,100:110]


Out[14]:
array([[-41.0654755 , -44.0654756 , -47.06547569, -46.06547566,
        -46.06547566, -47.06547569, -48.06547572, -48.06547572,
        -48.06547572, -46.06547566],
       [-41.0654755 , -43.06547556, -44.0654756 , -44.0654756 ,
        -44.0654756 , -44.0654756 , -47.06547569, -48.06547572,
        -51.06547581, -47.06547569],
       [-43.06547556, -43.06547556, -43.06547556, -43.06547556,
        -43.06547556, -41.0654755 , -43.06547556, -47.06547569,
        -51.06547581, -49.06547575],
       [-43.06547556, -44.0654756 , -42.06547553, -43.06547556,
        -41.0654755 , -41.0654755 , -41.0654755 , -44.0654756 ,
        -48.06547572, -47.06547569],
       [-42.06547553, -44.0654756 , -43.06547556, -46.06547566,
        -43.06547556, -44.0654756 , -43.06547556, -46.06547566,
        -48.06547572, -49.06547575],
       [-44.0654756 , -48.06547572, -47.06547569, -47.06547569,
        -42.06547553, -43.06547556, -43.06547556, -45.06547563,
        -45.06547563, -48.06547572],
       [-42.06547553, -46.06547566, -46.06547566, -47.06547569,
        -43.06547556, -47.06547569, -46.06547566, -48.06547572,
        -45.06547563, -47.06547569],
       [-46.06547566, -49.06547575, -47.06547569, -45.06547563,
        -43.06547556, -45.06547563, -46.06547566, -45.06547563,
        -42.06547553, -43.06547556],
       [-45.06547563, -45.06547563, -43.06547556, -42.06547553,
        -42.06547553, -45.06547563, -47.06547569, -47.06547569,
        -45.06547563, -45.06547563],
       [-49.06547575, -47.06547569, -42.06547553, -40.06547547,
        -40.06547547, -43.06547556, -46.06547566, -45.06547563,
        -43.06547556, -43.06547556]])

In [15]:
# as figure 4.30 page 258, set negative values to zero
mask = f < 0
f[mask] = 0

In [16]:
imshow(f, figure=figure(figsize=(12,12)), cmap='gray')


Out[16]:
(<matplotlib.figure.Figure at 0x104c78310>,
 <matplotlib.axes._subplots.AxesSubplot at 0x10d1dad50>,
 <matplotlib.image.AxesImage at 0x10d142750>)

In [17]:
imsave('dc.tif', uint8(f))

In [20]:
histshow(image)
histshow(f.astype(np.uint8)[f>0])



In [21]:
image.mean?

In [ ]: