本文整理汇总了Python中skimage.morphology.erosion函数的典型用法代码示例。如果您正苦于以下问题:Python erosion函数的具体用法?Python erosion怎么用?Python erosion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了erosion函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:niklasmh,项目名称:ntnu,代码行数:25,代码来源:task3.py
示例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
开发者ID:stegben,项目名称:Competitions,代码行数:35,代码来源:train_whole_g_channel_3_class.py
示例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
开发者ID:rahulsingh786,项目名称:overlapped-fingerprint-seperator,代码行数:32,代码来源:utils.py
示例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
开发者ID:FromZeus,项目名称:new_diplom_work,代码行数:26,代码来源:neuro_tools.py
示例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()
开发者ID:brunomsaraiva,项目名称:eHooke_1.0,代码行数:32,代码来源:images.py
示例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
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:26,代码来源:segmentation_test.py
示例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
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:31,代码来源:segmentation_test.py
示例8: erode
def erode(data, erodrN = 2):
eroded = data.copy()
for i in range(erodrN):
eroded = erosion(eroded)
return eroded
开发者ID:sankhaMukherjee,项目名称:SEMimageSegmentation,代码行数:7,代码来源:image.py
示例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
开发者ID:fvermeij,项目名称:cad-doge,代码行数:35,代码来源:opticDiscVesselDetection.py
示例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
开发者ID:nathanieljevans,项目名称:vg_automated_microscope,代码行数:7,代码来源:Wafer.py
示例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)
开发者ID:FromZeus,项目名称:new_diplom_work,代码行数:28,代码来源:neuro_tools.py
示例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
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:7,代码来源:segmentation_test.py
示例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
开发者ID:niklasmh,项目名称:ntnu,代码行数:28,代码来源:task5a.py
示例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
开发者ID:ThomasWalter,项目名称:SelectiveIllumination,代码行数:7,代码来源:basic.py
示例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
开发者ID:ThomasWalter,项目名称:SelectiveIllumination,代码行数:8,代码来源:basic.py
示例16: ContourLabeled
def ContourLabeled(bin_image, radius):
copied = bin_image.copy()
copied = erosion(copied, disk(radius))
contour = bin_image.copy() - copied
res = np.zeros_like(bin_image, dtype='uint8')
res[bin_image == 1] = 255
res[contour == 1] = 127
return res
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:8,代码来源:BinTo3.py
示例17: fill_holes
def fill_holes(self, binary_image, selem, iterations):
image = binary_image.copy()
for j in range(0, iterations):
image = dilation(image, selem)
image = ndi.binary_fill_holes(image)
for j in range(0, iterations):
image = erosion(image, selem)
return image
开发者ID:elpisco,项目名称:hip-dysplasia,代码行数:8,代码来源:image_processing.py
示例18: add_contours
def add_contours(rgb_image, contour, ds = 2):
"""
The image has to be a binary image
"""
rgb = rgb_image.copy()
contour[contour > 0] = 1
boundery = contour - erosion(contour, disk(ds))
rgb[boundery > 0] = np.array([0, 0, 0])
return rgb
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:9,代码来源:RandomUtils.py
示例19: filter_wsl
def filter_wsl(self, imbin, ws_labels, imin):
# internal gradient of the cells:
se = morphology.diamond(1)
#ero = morphology.erosion(imbin, se)
#grad = imbin - ero
# watershed line
wsl = self.get_external_wsl(ws_labels)
#wsl = self.get_large_wsl(ws_labels)
wsl_remove = wsl.copy()
# watershed line outside the cells is 0
wsl_remove[imbin==0] = 0
# watershed line on the gradient (border of objects)
# is also not considered
#wsl_remove[grad>0] = 0
# gradient image
pref = 255 * filters.gaussian_filter(imin, 3.0)
pref[pref < 0] = 0
pref = pref.astype(np.dtype('uint8'))
ero = morphology.erosion(pref, se)
dil = morphology.dilation(pref, se)
grad = dil - ero
grad_filtered = grad
if self.settings.debug:
out_filename = os.path.join(self.settings.img_debug_folder, '%s09_watershed_regions.png' % self.prefix)
skimage.io.imsave(out_filename, ws_labels.astype(np.dtype('uint8')))
out_filename = os.path.join(self.settings.img_debug_folder, '%s09_wsl.png' % self.prefix)
skimage.io.imsave(out_filename, wsl.astype(np.dtype('uint8')))
out_filename = os.path.join(self.settings.img_debug_folder, '%s09_wsl_remove.png' % self.prefix)
skimage.io.imsave(out_filename, wsl_remove.astype(np.dtype('uint8')))
out_filename = os.path.join(self.settings.img_debug_folder, '%s09_wsl_gradient.png' % self.prefix)
skimage.io.imsave(out_filename, grad_filtered.astype(np.dtype('uint8')))
labimage = label(wsl_remove)
properties = measure.regionprops(labimage, grad_filtered)
mean_intensities = np.array([0.0] + [pr.mean_intensity for pr in properties])
filter_intensities = np.where(mean_intensities < self.settings.postfilter['wsl_mean_intensity'], 255, 0)
filter_intensities[0] = 0
wsl_remove = filter_intensities[labimage]
#print filter_intensities
#print mean_intensities
wsl[wsl_remove>0] = 0
if self.settings.debug:
out_filename = os.path.join(self.settings.img_debug_folder, '%s09_wsl_remove2.png' % self.prefix)
skimage.io.imsave(out_filename, wsl_remove.astype(np.dtype('uint8')))
return wsl
开发者ID:ThomasWalter,项目名称:SelectiveIllumination,代码行数:57,代码来源:basic.py
示例20: erode
def erode(data, radius):
"""
Erode data using ball structuring element
:param data: 2d or 3d array
:param radius: radius of structuring element
:return: data eroded
"""
from skimage.morphology import erosion, ball
selem = ball(radius)
return erosion(data, selem=selem, out=None)
开发者ID:poquirion,项目名称:spinalcordtoolbox,代码行数:10,代码来源:sct_maths.py
注:本文中的skimage.morphology.erosion函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论