Example #1
0
def high_pass(gray, fn, dim=3, save=True, show=True):
    # kernal high pass
    if dim == 3:
        ker = [ [-1.0/16.0, 3.0/16.0,-1.0/16.0],
                [-1.0/16.0,16.0/16.0,-1.0/16.0],
                [-1.0/16.0,3.0/16.0,-1.0/16.0]]
    else:
        return None
                
    height, width = gray.shape
    ret = np.copy(gray)
    for i in range (0, width):
        for j in range( 0, height):
            if i != 0 and j != 0 and i < width -1 and j < height-1:
                val =  ker[0][0] * gray[j-1][i-1] + ker[0][1] * gray[j-1][i] + ker[0][2] * gray[j-1][i+1]
                val += ker[1][0] * gray[j][i-1] + ker[1][1] * gray[j][i] + ker[1][2] * gray[j][i+1]
                val += ker[2][0] * gray[j+1][i-1] + ker[2][1] * gray[j+1][i] + ker[2][2] * gray[j+1][i+1]
                if (val < 0):
                    val = 0
                if (val > 1):
                    val = 1
                ret[j][i]  = val
    if save:
        if show:
            saveimage(ret, fn, 'high pass', is_gray=True, show=True)
        else:
            saveimage(ret, fn, 'high pass', is_gray=True, show=False)
        
    return ret
Example #2
0
def my_canny(img, fn, sigma=6, with_mask=True, save=True, show=True):
    height = img.shape[0]
    width = img.shape[1]
    if with_mask:
        import numpy as np
        mask = np.ones((height, width),'uint8')
        y1, x1 = 250, 186
        y2, x2 = 610, 310
        mask[y1: y2, x1: x2] = 0
        ret = canny(img, sigma, mask)
    else:
        ret = canny(img, sigma)
        
    if save:
        from src.util import saveimage
        if with_mask:
            feature = '_sigma' + str(sigma) + '_mask'
        else:
            feature = '_sigma' + str(sigma)
        if show == False:
            saveimage(ret, fn+feature, title='canny'+feature, isGray=True, show=False)
        else:
            saveimage(ret, fn+feature, title='canny'+feature, isGray=True, show=True)
    return ret
Example #3
0
height = img.size[1]
arr = np.array(img.getdata(), dtype=np.uint8).reshape(height, width, 3)

# get the gray image
from skimage.color import rgb2gray
gray = rgb2gray(arr)

#subtracting the low pass from original
from scipy import ndimage
from src.util import saveimage

npix = 16
npiy = 2
gaussed = ndimage.gaussian_filter(gray, sigma=[npix, npiy])
fn = result_dir + 'gaussian_filter_' + str(npix) + str('_') + str(npiy)
saveimage(gaussed, fn, 'gaussian_filter', is_gray=True, show=False)

high_pass = gray - gaussed
idx = 0 > high_pass 
high_pass[idx] = 0
fn = result_dir + 'high_pass_gaussian' + str(npix) + str('_') + str(npiy)
saveimage(high_pass, fn, 'high_pass_gaussian', is_gray=True, show=False)

# binarize the result
idx = high_pass >= 0.05
high_pass[idx] = 1.0
idx = high_pass < 0.05
high_pass[idx] = 0.0
#binary_image = np.array(high_pass, dtype='b')
#high_pass=None
fn = result_dir + 'high_pass_binarize' + str(npix) + str('_') + str(npiy)
Example #4
0
height = img.size[1]
arr = np.array(img.getdata(), dtype=np.uint8).reshape(height, width, 3)

# get the gray image
from skimage.color import rgb2gray
gray = rgb2gray(arr)
arr = None
#from src.hist import my_hist
#fn = result_dir + 'gray_hist'
#my_hist(gray, fn)

#from histogram, determine the threshold value min = 0.3, max=0.6 for gray
gray_tmp= np.array(gray)
gray = None
low, high = 0.3, 0.6
idx = low > gray_tmp
gray_tmp[idx] = 0
idx = gray_tmp > high
gray_tmp[idx] = 0
from src.util import saveimage
fn = result_dir + 'thresh_' + str(int(low*10)) + '_' + str(int(high*10))
saveimage(gray_tmp, fn, is_gray=True)

from src.morphology import my_opening
fn = result_dir + 'threshed_opening'
opened = my_opening(gray_tmp, fn, 1, 40)

#diff = gray - opened
#fn = result_dir + 'threshed gray-opening'
#saveimage(diff, fn, is_gray=True)
Example #5
0
from src.gabor import gabor_feature
print "begin 1"
tao = 4
elongation = 8
sigmax = tao/2.35
sigmay = sigmax * elongation

max_orientation, max_magnitude, max_frequency = gabor_feature(gray, sigmax=sigmax, sigmay=sigmay)
print "end1"
from src.gabor import normalize
normal_gabor = normalize(max_magnitude)

from src.util import saveimage
fn = result_dir + 'complex_gabor_magnitude_sigma' + str(int(sigmax)) + '_' + str(int(sigmay)) +'_180'
saveimage(normal_gabor, fn, title='gabor magnitude', is_gray=True, show=True)
#==================================================================
from src.gabor import gabor_feature_real
print "begin2"
tao = 4
elongation = 8
sigmax = tao/2.35
sigmay = sigmax * elongation

max_orientation, max_magnitude, max_frequency = gabor_feature_real(gray, sigmax=sigmax, sigmay=sigmay)
print "end2"
normal_gabor = normalize(max_magnitude)

fn = result_dir + 'real_gabor_magnitude_sigma' + str(int(sigmax)) + '_' + str(int(sigmay)) +'_180'
saveimage(normal_gabor, fn, title='gabor magnitude', is_gray=True, show=True)