In [2]:
import cv2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

In [3]:
afmdata = np.genfromtxt('../NaRWHAL/Data/BackgroundedTXTFiles/5umNetwork-SparseToDense')
afmdata= afmdata*(10**9)
height, width = afmdata.shape
afmimg=np.zeros((height, width, 3))

In [ ]:
factor=(255)/(afmdata.max()-afmdata.min())
for i in range(height):
    for j in range(width):
        intensity=np.int((afmdata[i][j]-afmdata.min())*factor)
        #afmimg[i][j]=np.array([np.int((afmdata[i][j]-afmdata.min())*factor),0,0])
        afmimg[i][j]=np.array([intensity, intensity, intensity])

In [4]:
afmimg = np.uint8(afmimg)
grayscaled = cv2.cvtColor(afmimg,cv2.COLOR_BGR2GRAY)
plt.matshow(grayscaled, origin = 'lower', cmap = 'viridis')


Out[4]:
<matplotlib.image.AxesImage at 0x10bebe898>

In [5]:
background = cv2.adaptiveThreshold(grayscaled, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 71, 3)
plt.matshow(background, origin = 'lower', cmap = 'viridis')


Out[5]:
<matplotlib.image.AxesImage at 0x10be3c390>

In [11]:
backgrounded = grayscaled - background
plt.matshow(backgrounded, origin = 'lower', cmap = 'viridis')


Out[11]:
<matplotlib.image.AxesImage at 0x11079cd30>

In [13]:
retval2,threshold2 = cv2.threshold(backgrounded, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
plt.matshow(threshold2, origin = 'lower', cmap = "viridis")


Out[13]:
<matplotlib.image.AxesImage at 0x110b085c0>

In [1]:
img = backgrounded
equ = cv2.equalizeHist(img)
res = np.hstack((img,equ)) #stacking images side-by-side
plt.matshow(res, cmap = 'viridis')
plt.title('Backgrounded Image with and without Histogram Equalization')


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-0e022987e9a9> in <module>()
----> 1 img = backgrounded
      2 equ = cv2.equalizeHist(img)
      3 res = np.hstack((img,equ)) #stacking images side-by-side
      4 plt.matshow(res, cmap = 'viridis')
      5 plt.title('Backgrounded Image with and without Histogram Equalization')

NameError: name 'backgrounded' is not defined

In [26]:
def histogram_equalization(source):
    """
    Takes in a uint8 image and equalizes the histogram
    """
    img = source
    equ = cv2.equalizeHist(img)
    
    return equ

In [27]:
test1 = histogram_equalization(backgrounded)

In [28]:
plt.matshow(test1)


Out[28]:
<matplotlib.image.AxesImage at 0x1121215f8>

In [ ]: