本文整理汇总了Python中skimage.morphology.erosion函数的典型用法代码示例。如果您正苦于以下问题:Python erosion函数的具体用法?Python erosion怎么用?Python erosion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了erosion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: removeNoise
def removeNoise(img, r=7):
# Creating a circle inside an array
c = r # Center
d = 2 * r + 1 # Diameter
y, x = np.ogrid[-c:d-c, -c:d-c] # Create a True/False grid in numpy
mask = x * x + y * y <= r * r # Circular shape
structuringElement = np.zeros((d, d))
structuringElement[mask] = 1 # Fill ones at the places with True
# Applying erosion at the binary image
eroded = erosion(img, structuringElement)
# Dilate the remaining pixels from the eroded image
dilated = dilation(eroded, structuringElement)
# We have now opened the image. Now we need to close it:
# We could have done this in the same step as the last, but we want to show all steps
dilated2 = dilation(dilated, structuringElement)
# Then we close by eroding back to normal
eroded2 = erosion(dilated2, structuringElement)
return eroded, dilated, dilated2, eroded2
示例2: returnProcessedImage
def returnProcessedImage(que,folder,img_flist):
X = []
for fname in img_flist:
cur_img = imread(folder+'/'+fname , as_grey=True)
cur_img = 1 - cur_img
######## randomly add samples
# random add contrast
r_for_eq = random()
cur_img = equalize_adapthist(cur_img,ntiles_x=8,ntiles_y=8,clip_limit=(r_for_eq+0.5)/3)
#random morphological operation
r_for_mf_1 = random()
if 0.05 < r_for_mf_1 < 0.25: # small vessel
selem1 = disk(0.5+r_for_mf_1)
cur_img = dilation(cur_img,selem1)
cur_img = erosion(cur_img,selem1)
elif 0.25 < r_for_mf_1 < 0.5: # large vessel
selem2 = disk(2.5+r_for_mf_1*3)
cur_img = dilation(cur_img,selem2)
cur_img = erosion(cur_img,selem2)
elif 0.5 < r_for_mf_1 < 0.75: # exudate
selem1 = disk(9.21)
selem2 = disk(7.21)
dilated1 = dilation(cur_img, selem1)
dilated2 = dilation(cur_img, selem2)
cur_img = np.subtract(dilated1, dilated2)
cur_img = img_as_float(cur_img)
X.append([cur_img.tolist()])
# X = np.array(X , dtype = theano.config.floatX)
que.put(X)
return X
示例3: extract_region_opening
def extract_region_opening(img, is_demo=False):
"""
Extracts fingerprint region of image via mophological opening
"""
after_median = skimage.filter.rank.median(img, skmorph.disk(9))
after_erode = skmorph.erosion(after_median, skmorph.disk(11))
after_dil = skmorph.dilation(after_erode, skmorph.disk(5))
_, t_dil_img = cv2.threshold(after_dil, 240, 40, cv2.THRESH_BINARY)
if is_demo:
_, t_med_img = cv2.threshold(after_median, 240, 255, cv2.THRESH_BINARY)
_, t_erd_img = cv2.threshold(after_erode, 240, 40, cv2.THRESH_BINARY)
erd_gry = t_erd_img.astype(np.uint8) * 255
rgb_erd = np.dstack((erd_gry, img, img))
dil_gry = t_dil_img.astype(np.uint8) * 255
rgb_dil = np.dstack((dil_gry, img, img))
plt.subplot(2,2,1)
plt.imshow(after_erode, cmap="gray", interpolation="nearest")
plt.subplot(2,2,2)
plt.imshow(rgb_erd, interpolation="nearest")
plt.subplot(2,2,3)
plt.imshow(after_dil, cmap="gray", interpolation="nearest")
plt.subplot(2,2,4)
plt.imshow(rgb_dil, interpolation="nearest")
plt.show()
return t_dil_img
示例4: get_symbols
def get_symbols(image):
dil_eros = bin_search(dilatation_cross_numb, [image], (1, 16), 1.0, "dec")
block_size = 50
binary_adaptive_image = erosion(dilation(threshold_adaptive(
array(image.convert("L")), block_size, offset=10),
square(dil_eros)), square(dil_eros))
all_labels = label(binary_adaptive_image, background = True)
objects = find_objects(all_labels)
av_width = av_height = 0
symbols = []
for obj in objects:
symb = (binary_adaptive_image[obj], (obj[0].start, obj[1].start))
symbols.append(symb)
av_height += symb[0].shape[0]
av_width += symb[0].shape[1]
av_width /= float(len(objects))
av_height /= float(len(objects))
symbols = [symb for symb in symbols
if symb[0].shape[0] >= av_height and symb[0].shape[1] >= av_width]
return symbols
示例5: compute_mask
def compute_mask(self, params):
"""Creates the mask for the base image.
Needs the base image, an instance of imageloaderparams
and the clip area, which should be already defined
by the load_base_image method.
Creates the mask by improving the base mask created by the
compute_base_mask method. Applies the mask closing, dilation and
fill holes parameters.
"""
self.compute_base_mask(params)
mask = np.copy(self.base_mask)
closing_matrix = np.ones((params.mask_closing, params.mask_closing))
if params.mask_closing > 0:
# removes small dark spots and then small white spots
mask = img_as_float(morphology.closing(
mask, closing_matrix))
mask = 1 - \
img_as_float(morphology.closing(
1 - mask, closing_matrix))
for f in range(params.mask_dilation):
mask = morphology.erosion(mask, np.ones((3, 3)))
if params.mask_fill_holes:
# mask is inverted
mask = 1 - img_as_float(ndimage.binary_fill_holes(1.0 - mask))
self.mask = mask
self.overlay_mask_base_image()
示例6: get_rough_detection
def get_rough_detection(self, img, bigsize=40.0, smallsize=4.0, thresh = 0):
diff = self.difference_of_gaussian(-img, bigsize, smallsize)
diff[diff>thresh] = 1
se = morphology.square(4)
ero = morphology.erosion(diff, se)
labimage = label(ero)
#rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
# connectivity=1 corresponds to 4-connectivity.
morphology.remove_small_objects(labimage, min_size=600, connectivity=1, in_place=True)
#res = np.zeros(img.shape)
ero[labimage==0] = 0
ero = 1 - ero
labimage = label(ero)
morphology.remove_small_objects(labimage, min_size=400, connectivity=1, in_place=True)
ero[labimage==0] = 0
res = 1 - ero
res[res>0] = 255
#temp = 255 - temp
#temp = morphology.remove_small_objects(temp, min_size=400, connectivity=1, in_place=True)
#res = 255 - temp
return res
示例7: test_morpho2
def test_morpho2(self, bigsize=20.0, smallsize=3.0, threshold=5.0):
img = self.read_H_image()
pref = self.morpho_rec(img, 10)
filename = os.path.join(test_out_folder, 'morpho_00_rec_%s.png' % self.image_name)
skimage.io.imsave(filename, pref)
res = self.difference_of_gaussian(pref, bigsize, smallsize)
filename = os.path.join(test_out_folder, 'morpho_01_diff_%s_%i_%i.png' % (self.image_name, int(bigsize), int(smallsize)))
skimage.io.imsave(filename, res)
#res = self.morpho_rec2(diff, 15)
#filename = os.path.join(test_out_folder, 'morpho_02_rec_%s.png' % self.image_name)
#skimage.io.imsave(filename, res)
res[res>threshold] = 255
filename = os.path.join(test_out_folder, 'morpho_03_res_%s_%i.png' % (self.image_name, threshold))
skimage.io.imsave(filename, res)
se = morphology.diamond(3)
ero = morphology.erosion(res, se)
filename = os.path.join(test_out_folder, 'morpho_03_ero_%s_%i.png' % (self.image_name, threshold))
skimage.io.imsave(filename, ero)
res[ero>0] = 0
overlay_img = self.overlay(img, res)
filename = os.path.join(test_out_folder, 'morpho_04_overlay_%s_%i.png' % (self.image_name, int(threshold)))
skimage.io.imsave(filename, overlay_img)
return
示例8: erode
def erode(data, erodrN = 2):
eroded = data.copy()
for i in range(erodrN):
eroded = erosion(eroded)
return eroded
示例9: detectOpticDisc
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
示例10: focus_score
def focus_score(self):
f_score = (color.rgb2grey(self.img) - erosion(color.rgb2grey(self.img), square(4)))
non_zero_pixel_area = self.get_nonzero_pixel_area(f_score)
#print("focus score: " + str(np.sum(f_score) / non_zero_pixel_area))
#plt.imshow(f_score)
#plt.show()
return np.sum(f_score) / non_zero_pixel_area
示例11: get_distorted
def get_distorted(image, params, orient = "horizont"):
shifts = []
np_image = array(image.convert("L"))
for el in params:
if el[0] == "sin":
shifts.append(lambda x: np_image.shape[0] / el[1] * \
np.sin(x * el[2] / np_image.shape[1]))
if el[0] == "cos":
shifts.append(lambda x: np_image.shape[0] / el[1] * \
np.cos(x * el[2] / np_image.shape[1]))
if el[0] == "triang":
lambda x: np_image.shape[0] / el[1] * \
(x / el[2] / np_image.shape[1] - math.floor(x / (el[2] / np_image.shape[1])))
if el[0] == "erosion":
np_image = erosion(np_image, square(el[1]))
if el[0] == "dilation":
np_image = dilation(np_image, square(el[1]))
if orient == "horizont":
for idx in xrange(np_image.shape[0]):
for shift in shifts:
np_image[idx,:] = np.roll(np_image[idx,:], int(shift(idx)))
if orient == "vert":
for idx in xrange(np_image.shape[1]):
for shift in shifts:
np_image[:, idx] = np.roll(np_image[:, idx], int(shift(idx)))
return Image.fromarray(np_image)
示例12: morpho_rec
def morpho_rec(self, img, size=10):
# internal gradient of the cells:
se = morphology.diamond(size)
ero = morphology.erosion(img, se)
rec = morphology.reconstruction(ero, img, method='dilation').astype(np.dtype('uint8'))
return rec
示例13: removeChessboard
def removeChessboard(img):
# Get the major lines in the image
edges, dilatedEdges, (h, theta, d) = findLines(img)
# Create image with ones to fill inn lines
lines = np.ones(img.shape[:2])
# Add lines to image as zeroes
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
y1 = (dist - img.shape[1] * np.cos(angle)) / np.sin(angle)
x, y = line(int(y1), 0, int(y0), img.shape[1] - 1)
x = np.clip(x, 0, img.shape[0] - 1)
y = np.clip(y, 0, img.shape[1] - 1)
lines[x, y] = 0
# Remove border edges from image with all edges
w = 4
edges = np.pad(edges[w:img.shape[0] - w, w:img.shape[1] - w], w, mode='constant')
# Erode the lines bigger, such that they cover the original lines
lines = erosion(lines, square(13))
# Remove major lines and close shape paths
removedChessboard = closing(edges * lines, square(8))
return removedChessboard
示例14: get_internal_wsl
def get_internal_wsl(self, labelimage):
se = morphology.diamond(1)
ero = morphology.erosion(labelimage, se)
grad = labelimage - ero
res = np.zeros(labelimage.shape)
res[grad>0] = 255
return res
示例15: get_large_wsl
def get_large_wsl(self, labelimage):
se = morphology.diamond(1)
dil = morphology.dilation(labelimage, se)
ero = morphology.erosion(labelimage, se)
grad = dil - ero
res = np.zeros(labelimage.shape)
res[grad>0] = 255
return res