コード例 #1
0
ファイル: circhough.py プロジェクト: thanasi/ImagingHW
def hough(im, R):
    '''
     return Hough transform of a binary image containing circles of radius R
     the axes in the Hough transform represent the a and b center coords
     of a circle given by the equation:
        
        (x - a)**2 + (y - b)**2 = R**2
        
     for each 'on' point, p0, in the binary image, the set of centers of 
     circles that could pass through p0 is represented by a circle of 
     radius R about p0.  Therefore, for each 'on' point in the image, p0, 
     I will add a circle of radius R centered at p0 to the accumulator

    '''
    circ = make_ball(R,shell=1,bgsize=(2*R+1,2*R+1)).astype(int)
    # create accumulator with shape of image since we can only vary the centers
    L,W = im.shape
    acc = np.zeros(im.shape)
    for i in range(L):
        for j in range(W):
            if im[i,j]==1:
                # if near the edges, appropriately crop the circle
                if i<R:
                    i_min = 0
                    crop_top = R - i
                    i_max = i + R
                    crop_bottom = 2 * R
                elif i>L-R:
                    i_min = i - R
                    crop_top = 0
                    i_max = L
                    crop_bottom = L - 1 - i - R
                else:
                    i_min = i - R
                    crop_top = 0
                    i_max = i + R
                    crop_bottom = 2 * R
                
                if j<R:
                    j_min = 0
                    crop_left = R - j
                    j_max = j + R
                    crop_right = 2 * R
                elif j>W-R:
                    j_min = j - R
                    crop_left = 0
                    j_max = W
                    crop_right = W - 1 - j - R
                else:
                    j_min = j - R
                    crop_left = 0
                    j_max = j + R
                    crop_right = 2 * R
                
                # add circle centered at i,j to accumulator
                acc[i_min:i_max,j_min:j_max] += circ[crop_top:crop_bottom,
                                                     crop_left:crop_right]
                                                     
    return acc
コード例 #2
0
ファイル: problem2.py プロジェクト: thanasi/ImagingHW
# Athanasios Athanassiadis Jan 2012
from segmentation import *
from ball import make_ball

fig1 = np.fromfile("figure1_problem_set_3", dtype=">i2").reshape((192, 161))
fig1 /= 1.0 * fig1.max()

# set a new starting point that is on the edge on the other side of the figure
i0, j0 = 71, 80
startpoint = np.zeros(fig1.shape)
startpoint[i0, j0] = 1
edge, chain = track_edge(fig1, (i0, j0))
ball = make_ball(5, shell=1, center=(i0, j0), bgsize=(192, 161))

# set up colors
r = fig1 * (1 - edge) * (1 - ball) * (1 - startpoint) + ball + startpoint
g = fig1 * (1 - edge) * (1 - ball) * (1 - startpoint) + startpoint
b = fig1 * (1 - ball) * (1 - startpoint)
imsave("3-2a.png", (r, g, b))