Exemple #1
0
def _octagon_kernel(mo, no, mi, ni):
    outer = (mo + 2 * no) ** 2 - 2 * no * (no + 1)
    inner = (mi + 2 * ni) ** 2 - 2 * ni * (ni + 1)
    outer_weight = 1.0 / (outer - inner)
    inner_weight = 1.0 / inner
    c = ((mo + 2 * no) - (mi + 2 * ni)) // 2
    outer_oct = octagon(mo, no)
    inner_oct = np.zeros((mo + 2 * no, mo + 2 * no))
    inner_oct[c: -c, c: -c] = octagon(mi, ni)
    bfilter = (outer_weight * outer_oct -
               (outer_weight + inner_weight) * inner_oct)
    return bfilter
Exemple #2
0
def _octagon_kernel(mo, no, mi, ni):
    outer = (mo + 2 * no)**2 - 2 * no * (no + 1)
    inner = (mi + 2 * ni)**2 - 2 * ni * (ni + 1)
    outer_weight = 1.0 / (outer - inner)
    inner_weight = 1.0 / inner
    c = ((mo + 2 * no) - (mi + 2 * ni)) // 2
    outer_oct = octagon(mo, no)
    inner_oct = np.zeros((mo + 2 * no, mo + 2 * no))
    inner_oct[c:-c, c:-c] = octagon(mi, ni)
    bfilter = (outer_weight * outer_oct -
               (outer_weight + inner_weight) * inner_oct)
    return bfilter
Exemple #3
0
def test_corner_orientations_lena():
    img = rgb2gray(data.lena())
    corners = corner_peaks(corner_fast(img, 11, 0.35))
    expected = np.array([-1.9195897 , -3.03159624, -1.05991162, -2.89573739,
                         -2.61607644, 2.98660159])
    actual = corner_orientations(img, corners, octagon(3, 2))
    assert_almost_equal(actual, expected)
def cornerDemo(fileName):
    img = cv2.imread(fileName, cv2.CV_LOAD_IMAGE_COLOR)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #C = skimage.feature.corner_peaks(skimage.feature.corner_fast(gray, 14), min_distance=1)
    #C = skimage.feature.corner_peaks(skimage.feature.corner_harris(gray), min_distance=1)
    w, q = skimage.feature.corner_foerstner(gray)
    accuracy_thresh = 0.4
    roundness_thresh = 0.2
    foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w
    C = skimage.feature.corner_peaks(foerstner, min_distance=1)
    orientations = skimage.feature.corner_orientations(gray, C, octagon(3, 2))

    corners = np.rad2deg(orientations)
    AngleBins = np.arange(0, 360, 45)
    AngleBinsOrientation = np.array([0, 1, 2, 1, 0, 1, 2, 1])
    OrientationHist = np.zeros((3, 1))
    for a in corners:
        OrientationHist[AngleBinsOrientation[np.argmin(
            np.abs(a - AngleBins))]] += 1

    if OrientationHist.sum() > 0:
        OrientationHist = OrientationHist / OrientationHist.sum()
    else:
        OrientationHist = -0.01 * np.ones((3, 1))

#	plt.subplot(2,1,1)
    plt.imshow(img)
    plt.plot(C[:, 1], C[:, 0], '*')
    for i in range(len(orientations)):
        plt.text(C[i, 1], C[i, 0], "{0:.2f}".format(corners[i]), fontsize=8)
#	plt.subplot(2,1,2)
#	plt.hist(corners, 20)
    plt.show()

    print OrientationHist
def getCornerFeatures(img):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    corners = skimage.feature.corner_peaks(skimage.feature.corner_fast(
        gray, 14),
                                           min_distance=1)
    orientations = skimage.feature.corner_orientations(gray, corners,
                                                       octagon(3, 2))
    corners = np.rad2deg(orientations)

    corners = np.array(corners)
    AngleBins = np.arange(0, 360, 45)
    AngleBinsOrientation = np.array([0, 1, 2, 1, 0, 1, 2, 1])
    OrientationHist = np.zeros((3, 1))
    for a in corners:
        OrientationHist[AngleBinsOrientation[np.argmin(
            np.abs(a - AngleBins))]] += 1

    if OrientationHist.sum() > 0:
        OrientationHist = OrientationHist / OrientationHist.sum()
    else:
        OrientationHist = -0.01 * np.ones((3, 1))

    F = []
    F.extend(OrientationHist[:, 0].tolist())
    F.append(100.0 * float(len(corners)) / (gray.shape[0] * gray.shape[1]))
    Fnames = ["Corners-Hor", "Corners-Diag", "Corners-Ver", "Corners-Percent"]
    return (F, Fnames)
Exemple #6
0
def test_corner_orientations_lena():
    img = rgb2gray(data.lena())
    corners = corner_peaks(corner_fast(img, 11, 0.35))
    expected = np.array([-1.9195897 , -3.03159624, -1.05991162, -2.89573739,
                         -2.61607644, 2.98660159])
    actual = corner_orientations(img, corners, octagon(3, 2))
    assert_almost_equal(actual, expected)
def detectOpticDisc(image):
    kernel = octagon(10, 10)
    thresh = threshold_otsu(image[:,:,1])
    binary = image > thresh
    print binary.dtype
    luminance = convertToHLS(image)[:,:,2]
    t = threshold_otsu(luminance)
    t = erosion(luminance, kernel)
    
    
    labels = segmentation.slic(image[:,:,1], n_segments = 3)
    out = color.label2rgb(labels, image[:,:,1], kind='avg')
    skio.imshow(out)
    
    x, y = computeCentroid(t)
    print x, y
    rows, cols, _ = image.shape
    p1 = closing(image[:,:,1],kernel)
    p2 = opening(p1, kernel)
    p3 = reconstruction(p2, p1, 'dilation')
    p3 = p3.astype(np.uint8)
    #g = dilation(p3, kernel)-erosion(p3, kernel)
    #g = rank.gradient(p3, disk(5))
    g = cv2.morphologyEx(p3, cv2.MORPH_GRADIENT, kernel)
    #markers = rank.gradient(p3, disk(5)) < 10
    markers = drawCircle(rows, cols, x, y, 85)
    #markers = ndimage.label(markers)[0]
    #skio.imshow(markers)
    g = g.astype(np.uint8)
    #g = cv2.cvtColor(g, cv2.COLOR_GRAY2RGB)
    w = watershed(g, markers)
    print np.max(w), np.min(w)
    w = w.astype(np.uint8)
    #skio.imshow(w)
    return w
def octMask(maskImg, octagon_m, octagon_n):
    boxsize = maskImg.get_xsize()
    maskArray = EMNumPy.em2numpy(maskImg)
    
    if (boxsize <= octagon_n * 2 or boxsize <= octagon_m):
        print "ERROR: (2 * the slanted sides) or (the horizontal and vertical sides) is larger than the boxsize of particles."
        sys.exit()
    
    #from skimage.morphology import octagon
    #Generates an octagon shaped structuring element with a given size of horizontal and vertical sides and a given height or width of slanted sides.
    #The slanted sides are 45 or 135 degrees to the horizontal axis and hence the widths and heights are equal.
    octArray = octagon(octagon_m, octagon_n, dtype=np.uint8)
    m, n = octArray.shape
    assert m==n
    
    if (m%2 == 0):
        pad_before = (boxsize - m)/2
        pad_after = (boxsize - m)/2
    else:
        pad_before = (boxsize - m)/2
        pad_after = (boxsize - m)/2+1
    
    octArrayPad = np.pad(octArray, (pad_before, pad_after), mode='constant')
    octImg = EMNumPy.numpy2em(octArrayPad)
    return octImg
Exemple #9
0
def test_corner_orientations_square():
    square = np.zeros((12, 12))
    square[3:9, 3:9] = 1
    corners = corner_peaks(corner_fast(square, 9), min_distance=1)
    actual_orientations = corner_orientations(square, corners, octagon(3, 2))
    actual_orientations_degrees = np.rad2deg(actual_orientations)
    expected_orientations_degree = np.array([45.0, 135.0, -45.0, -135.0])
    assert_array_equal(actual_orientations_degrees, expected_orientations_degree)
def open_close(im, val):

    val = int(val)

    if 4 > val > 0:

        k = morphology.octagon(val, val)

        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)

    if 8 > val >= 4:
        k = morphology.octagon(val // 2 + 1, val // 2 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)

    if val >= 8:
        k = morphology.octagon(val // 4 + 1, val // 4 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)

    return im
Exemple #11
0
def test_corner_orientations_square():
    square = np.zeros((12, 12))
    square[3:9, 3:9] = 1
    corners = corner_peaks(corner_fast(square, 9), min_distance=1)
    actual_orientations = corner_orientations(square, corners, octagon(3, 2))
    actual_orientations_degrees = np.rad2deg(actual_orientations)
    expected_orientations_degree = np.array([  45.,  135.,  -45., -135.])
    assert_array_equal(actual_orientations_degrees,
                       expected_orientations_degree)
Exemple #12
0
def test_corner_orientations_square(dtype):
    square = np.zeros((12, 12), dtype=dtype)
    square[3:9, 3:9] = 1
    corners = corner_peaks(corner_fast(square, 9),
                           min_distance=1,
                           threshold_rel=0)
    actual_orientations = corner_orientations(square, corners, octagon(3, 2))
    assert actual_orientations.dtype == _supported_float_type(dtype)
    actual_orientations_degrees = np.rad2deg(actual_orientations)
    expected_orientations_degree = np.array([45, 135, -45, -135])
    assert_array_equal(actual_orientations_degrees,
                       expected_orientations_degree)
def fg_markers(im_cent, im_bin, val, edges):

    local_maxi = peak_local_max(im_cent,
                                indices=False,
                                min_distance=int(val),
                                labels=im_bin,
                                exclude_border=int(edges))
    k = morphology.octagon(2, 2)

    local_maxi = morphology.dilation(local_maxi, selem=k)
    markers = ndimage.label(local_maxi)[0]
    markers[local_maxi] += 1

    return markers
Exemple #14
0
def test_corner_orientations_astronaut():
    img = rgb2gray(data.astronaut())
    corners = corner_peaks(corner_fast(img, 11, 0.35))
    expected = np.array([
        -1.75220190e+00, 2.01197383e+00, -2.01162417e+00, -1.88247204e-01,
        1.19134149e+00, -6.61151410e-01, -2.99143370e+00, 2.17103132e+00,
        -7.52950306e-04, 1.25854853e+00, 2.43573659e+00, -1.69230287e+00,
        -9.88548213e-01, 1.47154532e+00, -1.65449964e+00, 1.09650167e+00,
        1.07812134e+00, -1.68885773e+00, -1.64397304e+00, 3.09780364e+00,
        -3.49561988e-01, -1.46554357e+00, -2.81524886e+00, 8.12701702e-01,
        2.47305654e+00, -1.63869275e+00, 5.46905279e-02, -4.40598471e-01,
        3.14918803e-01, -1.76069982e+00, 3.05330950e+00, 2.39291733e+00,
        -1.22091334e-01, -3.09279990e-01, 1.45931342e+00
    ])

    actual = corner_orientations(img, corners, octagon(3, 2))
    assert_almost_equal(actual, expected)
Exemple #15
0
def test_corner_orientations_astronaut():
    img = rgb2gray(data.astronaut())
    corners = corner_peaks(corner_fast(img, 11, 0.35),
                           min_distance=10, threshold_abs=0, threshold_rel=0.1)
    expected = np.array([-1.75220190e+00,  2.01197383e+00, -2.01162417e+00,
                         -1.88247204e-01,  1.19134149e+00, -6.61151410e-01,
                         -2.99143370e+00,  2.17103132e+00, -7.52950306e-04,
                          1.25854853e+00,  2.43573659e+00, -1.69230287e+00,
                         -9.88548213e-01,  1.47154532e+00, -1.65449964e+00,
                          1.09650167e+00,  1.07812134e+00, -1.68885773e+00,
                         -1.64397304e+00,  3.09780364e+00, -3.49561988e-01,
                         -1.46554357e+00, -2.81524886e+00,  8.12701702e-01,
                          2.47305654e+00, -1.63869275e+00,  5.46905279e-02,
                         -4.40598471e-01,  3.14918803e-01, -1.76069982e+00,
                          3.05330950e+00,  2.39291733e+00, -1.22091334e-01,
                         -3.09279990e-01,  1.45931342e+00])
    actual = corner_orientations(img, corners, octagon(3, 2))
    assert_almost_equal(actual, expected)
Exemple #16
0
def objects():
    from skimage.morphology import (square, rectangle, diamond, disk, cube,
                                    octahedron, ball, octagon, star)
    from mpl_toolkits.mplot3d import Axes3D
    # Generate 2D and 3D structuring elements.
    struc_2d = {
        "square(15)": square(15),
        "rectangle(15, 10)": rectangle(15, 10),
        "diamond(7)": diamond(7),
        "disk(7)": disk(7),
        "octagon(7, 4)": octagon(7, 4),
        "star(5)": star(5)
    }

    struc_3d = {
        "cube(11)": cube(11),
        "octahedron(5)": octahedron(5),
        "ball(5)": ball(5)
    }

    # Visualize the elements.
    fig = plt.figure(figsize=(8, 8))

    idx = 1
    for title, struc in struc_2d.items():
        ax = fig.add_subplot(3, 3, idx)
        ax.imshow(struc, cmap="Paired", vmin=0, vmax=12)
        for i in range(struc.shape[0]):
            for j in range(struc.shape[1]):
                ax.text(j, i, struc[i, j], ha="center", va="center", color="w")
        ax.set_axis_off()
        ax.set_title(title)
        idx += 1

    for title, struc in struc_3d.items():
        ax = fig.add_subplot(3, 3, idx, projection=Axes3D.name)
        ax.voxels(struc)
        ax.set_title(title)
        idx += 1

    fig.tight_layout()
    plt.show()
def task1():
    img = mimg.imread("bw1.bmp")

    new_img1 = binary_erosion(img, selem=square(width=30))
    new_img2 = binary_erosion(img, selem=rectangle(width=30, height=20))
    new_img3 = binary_erosion(img, selem=diamond(radius=5))
    new_img4 = binary_erosion(img, selem=disk(radius=15))
    new_img5 = binary_erosion(img, selem=star(a=10))
    new_img6 = binary_erosion(img, selem=octagon(m=10, n=20))
    new_img7 = binary_dilation(img, )

    fig, ax = plt.subplots(1, 8)
    show(ax[0], img, "original")
    show(ax[1], new_img1, "BE square")
    show(ax[2], new_img2, "BE rectangle")
    show(ax[3], new_img3, "BE diamond")
    show(ax[4], new_img4, "BE disk")
    show(ax[5], new_img5, "BE star")
    show(ax[6], new_img6, "BE octagon")
    show(ax[7], new_img2, "binary_dilation")
    plt.show()
def getCornerFeatures(img):
	gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
	corners = skimage.feature.corner_peaks(skimage.feature.corner_fast(gray, 14), min_distance=1)
	orientations = skimage.feature.corner_orientations(gray, corners, octagon(3, 2))
	corners = np.rad2deg(orientations)

	corners = np.array(corners)
	AngleBins = np.arange(0,360,45);
	AngleBinsOrientation = np.array([0, 1, 2, 1, 0, 1, 2, 1])
	OrientationHist = np.zeros((3,1))
	for a in corners:
		OrientationHist[AngleBinsOrientation[np.argmin(np.abs(a-AngleBins))]] += 1	

	if OrientationHist.sum()>0:
		OrientationHist = OrientationHist / OrientationHist.sum()
	else:
		OrientationHist = - 0.01*np.ones((3,1))

	F = []
	F.extend(OrientationHist[:,0].tolist())
	F.append(100.0*float(len(corners)) / ( gray.shape[0] * gray.shape[1] ) )
	Fnames = ["Corners-Hor", "Corners-Diag", "Corners-Ver", "Corners-Percent"]
	return (F, Fnames)
def watershed(markers, im_bin, im_edge, d_mat, val, edges):

    k = morphology.octagon(2, 2)

    im_bin = morphology.binary_dilation(im_bin, selem=k)
    im_bin = morphology.binary_dilation(im_bin, selem=k)
    im_bin = morphology.binary_dilation(im_bin, selem=k)

    markers_temp = markers + np.logical_not(im_bin)
    shed_im = (1 - val) * im_edge - val * d_mat

    labels = morphology.watershed(image=shed_im, markers=markers_temp)
    labels -= 1

    if edges == 1:
        edge_vec = np.hstack((labels[:, 0].flatten(), labels[:, -1].flatten(),
                              labels[0, :].flatten(), labels[-1, :].flatten()))
        edge_val = np.unique(edge_vec)
        for val in edge_val:
            if not val == 0:
                labels[labels == val] = 0

    return labels
def cornerDemo(fileName):
	img = cv2.imread(fileName, cv2.CV_LOAD_IMAGE_COLOR)
	gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
	#C = skimage.feature.corner_peaks(skimage.feature.corner_fast(gray, 14), min_distance=1)
	#C = skimage.feature.corner_peaks(skimage.feature.corner_harris(gray), min_distance=1)
	w, q = skimage.feature.corner_foerstner(gray)
	accuracy_thresh = 0.4
	roundness_thresh = 0.2
	foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w	
	C = skimage.feature.corner_peaks(foerstner, min_distance=1)
	orientations = skimage.feature.corner_orientations(gray, C, octagon(3, 2))

	corners = np.rad2deg(orientations)
	AngleBins = np.arange(0,360,45);
	AngleBinsOrientation = np.array([0, 1, 2, 1, 0, 1, 2, 1])
	OrientationHist = np.zeros((3,1))
	for a in corners:
		OrientationHist[AngleBinsOrientation[np.argmin(np.abs(a-AngleBins))]] += 1	

	if OrientationHist.sum()>0:
		OrientationHist = OrientationHist / OrientationHist.sum()
	else:
		OrientationHist = - 0.01*np.ones((3,1))


#	plt.subplot(2,1,1)
	plt.imshow(img)	
	plt.plot(C[:,1], C[:,0], '*')
	for i in range(len(orientations)):
		plt.text(C[i,1], C[i,0], "{0:.2f}".format(corners[i]), fontsize=8);
#	plt.subplot(2,1,2)
#	plt.hist(corners, 20)
	plt.show()


	print OrientationHist
"""

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from skimage.morphology import (square, rectangle, diamond, disk, cube,
                                octahedron, ball, octagon, star)

# Generate 2D and 3D structuring elements.
struc_2d = {
    "square(15)": square(15),
    "rectangle(15, 10)": rectangle(15, 10),
    "diamond(7)": diamond(7),
    "disk(7)": disk(7),
    "octagon(7, 4)": octagon(7, 4),
    "star(5)": star(5)
}

struc_3d = {
    "cube(11)": cube(11),
    "octahedron(5)": octahedron(5),
    "ball(5)": ball(5)
}

# Visualize the elements.
fig = plt.figure(figsize=(8, 8))

idx = 1
for title, struc in struc_2d.items():
    ax = fig.add_subplot(3, 3, idx)
img = sk.io.imread('teeth.jpg', True)
grey = img.copy()
img_t = cv2.threshold(255*grey, 160, 170, cv2.THRESH_BINARY_INV)[1]
img_tmp  = 255 -img_t
plt.axis('off')
plt.imshow(img_tmp, cmap='gray')
plt.show()
img_e = binary_dilation(img_t, rectangle(2,3))
img_tmp  = 255- 255*img_e 
plt.imshow(img_tmp, cmap='gray')
plt.show()
img_e = binary_closing(img_e, rectangle(8,2))
img_tmp  = 255- 255*img_e 
plt.imshow(img_tmp, cmap='gray')
plt.show()
img_e = binary_dilation(img_e, octagon(10,2))
img_tmp  = 255- 255*img_e 
plt.imshow(img_tmp, cmap='gray')
plt.show()

img_e = binary_dilation(img_e, star(8))
img_tmp  = 255- 255*img_e 
plt.imshow(img_tmp, cmap='gray')
plt.show()
for i in range(3):
    img_e = binary_erosion(img_e, star(3 + i))
img_e  = 255- 255*img_e 
plt.imshow(img_e, cmap='gray')
plt.axis('off')
plt.show()
Exemple #23
0
 def element(self) -> np.array:
     return morphology.octagon(self.m, self.n)
Exemple #24
0
from skimage.morphology import disk, octagon, square, star, erosion, dilation

#Variables basicas
opcion = 3
tamaño = 10
img = imread('circunferencias.png')
noisy_image = rgb2gray(img)
binaria = 0.25 <= noisy_image
binaria = ~binaria

# Erosion y dilatación
if opcion == 0:
    erosionada = erosion(binaria, disk(tamaño))
    imagen_final = dilation(erosionada, disk(tamaño))
if opcion == 1:
    erosionada = erosion(binaria, octagon(tamaño, int(tamaño / 2)))
    imagen_final = dilation(erosionada, octagon(tamaño, int(tamaño / 2)))
if opcion == 2:
    erosionada = erosion(binaria, square(tamaño))
    imagen_final = dilation(erosionada, square(tamaño))
if opcion == 3:
    erosionada = erosion(binaria, star(tamaño))
    imagen_final = dilation(erosionada, star(tamaño))

#Gaurdado de imagenes
plt.imshow(binaria, cmap='gray', vmin=0, vmax=1)
plt.title('Binaria')
plt.show()
plt.imshow(erosionada, cmap='gray', vmin=0, vmax=1)
plt.title('Tratada')
plt.show()
Exemple #25
0
#                                   cval=0, order=None)#6个三通道的原图大小矩阵
        hmd=feature.hessian_matrix_det(imgrey, sigma=1)#原图大小矩阵
#        hme=feature.hessian_matrix_eigvals(hmf, Hxy=None, Hyy=None)
        si=feature.shape_index(imgrey, sigma=1, mode='constant', cval=0)#原图大小矩阵
#        ckr=feature.corner_kitchen_rosenfeld(image, mode='constant', cval=0) ##原图大小矩阵 三通道               
#        ch=feature.corner_harris(imgrey, method='k', k=0.05, eps=1e-06, sigma=1)#原图大小矩阵
#        cht=feature.corner_shi_tomasi(imgrey, sigma=1)#原图大小矩阵
#        cfs=feature.corner_foerstner(imgrey, sigma=1)#2个 #原图大小矩阵
#        csb=feature.corner_subpix(image, ch, window_size=11, alpha=0.99)
        cps=feature.corner_peaks(imgrey, min_distance=1, threshold_abs=None, 
                                 threshold_rel=0.1, exclude_border=True, indices=True, 
                                 footprint=None, labels=None)#一堆坐标值
#        cmr=feature.corner_moravec(imgrey, window_size=1)#原图大小矩阵
#        cft=feature.corner_fast(imgrey, n=12, threshold=0.15)#原图大小矩阵
        corners = feature.corner_peaks(feature.corner_fast(imgrey, 9), min_distance=1)#一堆坐标
        corts=feature.corner_orientations(imgrey, corners, octagon(3, 2))#一维矩阵长度不定
#        mtem=feature.match_template(image, template, pad_input=False,
#                                    mode='constant', constant_values=0)
#        bldg=feature.blob_dog(imgrey, min_sigma=1, max_sigma=50, 
#                              sigma_ratio=1.6, threshold=2.0, overlap=0.5)#不懂
#        bldoh=feature.blob_doh(imgrey, min_sigma=1, max_sigma=30, num_sigma=10, 
#                               threshold=0.01, overlap=0.5, log_scale=False)#不懂
#        bllog=feature.blob_log(imgrey, min_sigma=1, max_sigma=50, num_sigma=10, 
#                               threshold=0.2, overlap=0.5, log_scale=False)#不懂
        zong.append([imname,
                     greycghg[0,0],greycghg[0,1],greycghg[0,2],greycghg[0,3],greycghg[0,4],
                     greycgcl[0,0],greycgcl[0,1],greycgcl[0,2],greycgcl[0,3],greycgcl[0,4],
                     greycgeg[0,0],greycgeg[0,1],greycgeg[0,2],greycgeg[0,3],greycgeg[0,4],
                     greycgasm[0,0],greycgasm[0,1],greycgasm[0,2],greycgasm[0,3],greycgasm[0,4],
                     greycgctt[0,0],greycgctt[0,1],greycgctt[0,2],greycgctt[0,3],greycgctt[0,4],
                     np.mean(lbp),np.std(lbp),len(plm)/(len(image[:,0,0])*len(image[0,:,0])),
Exemple #26
0
import matplotlib.pyplot as plt
import cv2
from skimage.morphology import disk, star, opening, closing, diamond, octagon, rectangle, square, ball, erosion, dilation, binary_opening, binary_closing

img = 255 - sk.io.imread("bw2.bmp", True)

##img_e = erosion(img.copy(), rectangle(7,4))
##img_d = dilation(img_e.copy(), octagon(10,2))
##img_d = erosion(img_d.copy(), disk(3))
##sk.io.imshow(255-img, cmap = "gray")
##sk.io.show()
##img_d = 255 - np.array([[255 if img_d[i][j] > 140 else 0 for j in range(img.shape[1])] for i in range(img.shape[0])])
##sk.io.imshow(img_d, cmap = "gray")
##sk.io.show()
img_e = erosion(img.copy(), rectangle(7, 4))
img_d = dilation(img_e.copy(), octagon(10, 2))
img_d = erosion(img_d.copy(), disk(3))
img_d = 255 - np.array(
    [[255 if img_d[i][j] > 140 else 0 for j in range(img.shape[1])]
     for i in range(img.shape[0])])
out = np.hstack([255 - img, img_d])

plt.imshow(out, cmap="gray")
plt.title(
    "Negacja->Erozja(prostokąt(7x4))->dylacja(ośmiokąt(10x2))->\nerozja(koło(3))->progowanie->Negacja",
    {
        'fontsize': 18,
        'fontweight': 'bold',
        'verticalalignment': 'baseline',
        'horizontalalignment': 'center'
    })
areas = [rp.area for rp in rps]
region_with_largest_area = np.argmax(areas)

binary = binary_label == rps[region_with_largest_area].label
#binary = convex_hull_image(binary)
#binary = binary_dilation(binary, disk(15)) != 0
distance = distance_transform_edt(binary)
local_maxi = peak_local_max(distance) # internal marker / center of [circle] <- (external marker)

####################################

#################################### Gradient Image
red_chan = gray_image
io.imshow(red_chan)

close = closing(red_chan, octagon(4,4))
io.imshow(close)

opening = opening(close, octagon(6,6))
io.imshow(opening)

rec = reconstruction(opening, close)

rec = exposure.rescale_intensity(rec, out_range=(0,1))

gradient = gradient(rec, disk(5))
######################################################## Apply watershed to gradient using imposed markers
### This is where I am having trouble. I have the gradient image and the internal marker location. I want
### to create a marker image with the internal marker (located at the center of the optic disk) and
### the external marker drawn as a circle around the optic disk so that the watershed algorithm can
### evaluate the specific contour of the disk when feeding in the gradient image and the marker image.
# Generate 2D and 3D structuring elements.
footprint_dict = {
    "square(11) (separable)":
    (square(11, decomposition=None), square(11, decomposition="separable")),
    "square(11) (sequence)":
    (square(11, decomposition=None), square(11, decomposition="sequence")),
    "rectangle(7, 11) (separable)": (rectangle(7, 11, decomposition=None),
                                     rectangle(7,
                                               11,
                                               decomposition="separable")),
    "rectangle(7, 11) (sequence)": (rectangle(7, 11, decomposition=None),
                                    rectangle(7, 11,
                                              decomposition="sequence")),
    "diamond(5) (sequence)": (diamond(5, decomposition=None),
                              diamond(5, decomposition="sequence")),
    "octagon(7, 4) (sequence)": (octagon(7, 4, decomposition=None),
                                 octagon(7, 4, decomposition="sequence")),
    "cube(11) (separable)": (cube(11, decomposition=None),
                             cube(11, decomposition="separable")),
    "cube(11) (sequence)": (cube(11, decomposition=None),
                            cube(11, decomposition="sequence")),
    "octahedron(7) (sequence)": (octahedron(7, decomposition=None),
                                 octahedron(7, decomposition="sequence")),
}

# Visualize the elements

# use a similar dark blue for the 2d plots as for the 3d voxel plots
cmap = colors.ListedColormap(['white', (0.1216, 0.4706, 0.70588)])
fontdict = dict(fontsize=16, fontweight='bold')
for title, (footprint, footprint_sequence) in footprint_dict.items():
Exemple #29
0
    img_e = erosion(img_e.copy(), diamond(5))
    img_d = dilation(img_d.copy(), diamond(5))
    plt.imshow(np.hstack([255 - img, 255 - img_e, 255 - img_d]), cmap='gray')
    plt.title(
        "diamond(5), iteration: " + str(i + 1), {
            'fontsize': 28,
            'fontweight': 'bold',
            'verticalalignment': 'baseline',
            'horizontalalignment': 'center'
        })
    plt.axis('off')
    plt.show()
img_e = img.copy()
img_d = img.copy()
for i in range(0, 3):
    img_e = erosion(img_e.copy(), octagon(5, 2))
    img_d = dilation(img_d.copy(), octagon(5, 2))
    plt.imshow(np.hstack([255 - img, 255 - img_e, 255 - img_d]), cmap='gray')
    plt.title(
        "octagon(5,2), iteration: " + str(i + 1), {
            'fontsize': 28,
            'fontweight': 'bold',
            'verticalalignment': 'baseline',
            'horizontalalignment': 'center'
        })
    plt.axis('off')
    plt.show()
img_e = img.copy()
img_d = img.copy()
for i in range(0, 3):
    img_e = erosion(img_e.copy(), rectangle(5, 2))