本文整理汇总了Python中skimage.morphology.remove_small_objects函数的典型用法代码示例。如果您正苦于以下问题:Python remove_small_objects函数的具体用法?Python remove_small_objects怎么用?Python remove_small_objects使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了remove_small_objects函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: 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
示例2: polylinesFromBinImage
def polylinesFromBinImage(img, minimum_cluster_size=6,
remove_small_obj_size=3,
reconnect_size=3,
max_n_contours=None, max_len_contour=None,
copy=True):
'''
return a list of arrays of un-branching contours
img -> (boolean) array
optional:
---------
minimum_cluster_size -> minimum number of pixels connected together to build a contour
##search_kernel_size -> TODO
##min_search_kernel_moment -> TODO
numeric:
-------------
max_n_contours -> maximum number of possible contours in img
max_len_contour -> maximum contour length
'''
assert minimum_cluster_size > 1
assert reconnect_size % 2, 'ksize needs to be odd'
# assert search_kernel_size == 0 or search_kernel_size > 2 and search_kernel_size%2, 'kernel size needs to be odd'
# assume array size parameters, is not given:
if max_n_contours is None:
max_n_contours = max(img.shape)
if max_len_contour is None:
max_len_contour = sum(img.shape[:2])
# array containing coord. of all contours:
contours = np.zeros(shape=(max_n_contours, max_len_contour, 2),
dtype=np.uint16) # if not search_kernel_size else np.float32)
if img.dtype != np.bool:
img = img.astype(bool)
elif copy:
img = img.copy()
if remove_small_obj_size:
remove_small_objects(img, remove_small_obj_size,
connectivity=2, in_place=True)
if reconnect_size:
# remove gaps
maximum_filter(img, reconnect_size, output=img)
# reduce contour width to 1
img = skeletonize(img)
n_contours = _populateContoursArray(img, contours, minimum_cluster_size)
contours = contours[:n_contours]
l = []
for c in contours:
ind = np.zeros(shape=len(c), dtype=bool)
_getValidInd(c, ind)
# remove all empty spaces:
l.append(c[ind])
return l
开发者ID:radjkarl,项目名称:imgProcessor,代码行数:60,代码来源:polylinesFromBinImage.py
示例3: predict
def predict(self, times, frames, output_times):
nout = len(output_times)
nf = len(frames)
last_idx = np.argmax(times)
zt = frames[last_idx] < self.thresh
skmorph.remove_small_objects(zt, min_size=self.min_size, in_place=True)
d = morphology.distance_transform_edt(np.invert(zt))
return np.tile(d, (nout,1,1))
开发者ID:ecgeil,项目名称:radar,代码行数:9,代码来源:distance.py
示例4: build_skeleton
def build_skeleton(frame):
"""
build a corner tree, skeletonize, dilate
"""
tree = trees.tree_corners(frame)
tree = morphology.skeletonize(tree)
# tree = morphology.binary_dilation(tree)
morphology.remove_small_objects(tree, min_size=20, connectivity=2, in_place=True)
tree = morphology.binary_dilation(tree)
return tree
开发者ID:grayhem,项目名称:inspection_port,代码行数:10,代码来源:primitives.py
示例5: distance_trend
def distance_trend(times, frames, threshold=25, min_size=12):
nf = len(frames)
zt = filters.gaussian_filter(frames,1.5) > threshold
d_outer = np.zeros((nf,) + frames[0].shape)
d_inner = np.zeros((nf,) + frames[0].shape)
for i in range(nf):
skmorph.remove_small_objects(zt, min_size=min_size, in_place=True)
d_outer[i] = morphology.distance_transform_edt(np.invert(zt[i]))
d_inner[i] = morphology.distance_transform_edt(zt[i])
return d_outer, d_inner
开发者ID:ecgeil,项目名称:radar,代码行数:12,代码来源:distance.py
示例6: nuclei_regions
def nuclei_regions(comp_map):
"""
NUCLEI_REGIONS: extract "support regions" for nuclei. This function
expects as input a "tissue components map" (as returned, for example,
by segm.tissue_components) where values of 1 indicate pixels having
a color corresponding to nuclei.
It returns a set of compact support regions corresponding to the
nuclei.
:param comp_map: numpy.ndarray
A mask identifying different tissue components, as obtained
by classification in RGB space. The value 0
See segm.tissue.tissue_components()
:return:
"""
# Deprecated:...
# img_hem, _ = rgb2he(img0, normalize=True)
# img_hem = denoise_tv_bregman(img_hem, HE_OPTS['bregm'])
# Get a mask of nuclei regions by unsupervised clustering:
# Vector Quantization: background, mid-intensity Hem and high intensity Hem
# -train the quantizer for 3 levels
# vq = KMeans(n_clusters=3)
# vq.fit(img_hem.reshape((-1,1)))
# -the level of interest is the brightest:
# k = np.argsort(vq.cluster_centers_.squeeze())[2]
# mask_hem = (vq.labels_ == k).reshape(img_hem.shape)
# ...end deprecated
# Final mask:
mask = (comp_map == 1) # use the components classified by color
# mask = morph.closing(mask, selem=HE_OPTS['strel1'])
# mask = morph.opening(mask, selem=HE_OPTS['strel1'])
# morph.remove_small_objects(mask, in_place=True)
# mask = (mask > 0)
mask = mahotas.close_holes(mask)
morph.remove_small_objects(mask, in_place=True)
dst = mahotas.stretch(mahotas.distance(mask))
Bc=np.ones((9,9))
lmax = mahotas.regmax(dst, Bc=Bc)
spots, _ = mahotas.label(lmax, Bc=Bc)
regions = mahotas.cwatershed(lmax.max() - lmax, spots) * mask
return regions
# end NUCLEI_REGIONS
开发者ID:gitter-badger,项目名称:WSItk,代码行数:52,代码来源:nuclei.py
示例7: stk_to_rois
def stk_to_rois(stk, threshold, min_size, max_window=8, downscale_factor=2):
thresholded_stk = stk > threshold
thresholded_stk = remove_small_objects(thresholded_stk, min_size)
distance = ndi.distance_transform_edt(thresholded_stk)
cropped_stk = stk.copy()
cropped_stk[np.logical_not(thresholded_stk)] = 0
combined_stk = cropped_stk + distance/distance.max()
local_max = peak_local_max(combined_stk, indices=False,
footprint=np.ones((max_window, max_window)),
labels=thresholded_stk)
markers = ndi.label(local_max)[0]
labels = watershed(-combined_stk, markers, mask=thresholded_stk)
new_markers = markers.copy()
for i in set(labels.flatten()):
if i == 0: continue
if np.sum(labels==i) < min_size:
new_markers[markers==i] = 0
labels = watershed(-combined_stk, new_markers, mask=thresholded_stk)
labels_set = set(labels.flatten())
rois = []
for label in labels_set:
if label == 0: continue
if np.sum((labels==label).astype(int)) < min_size: continue
nroi = np.zeros((stk.shape[0], stk.shape[1]))
cx,cy = np.where(labels==label)
cx,cy = int(cx.mean()), int(cy.mean())
x,y = np.ogrid[0:nroi.shape[0], 0:nroi.shape[1]]
r = 4
mask = (cx-x)**2 + (cy-y)**2 <= r*r
nroi[mask] = 1
#nroi[labels==label] = 1
rois.append(zoom(nroi, downscale_factor, order=0))
rois = np.array(rois)
return rois, thresholded_stk, labels
开发者ID:cyrilzhang,项目名称:livemau5,代码行数:34,代码来源:nn_all.py
示例8: segment_roi
def segment_roi(roi):
# step 1. phase congruency (edge detection)
Mm = phasecong_Mm(roi)
# step 2. hysteresis thresholding (of edges)
B = hysthresh(Mm,HT_T1,HT_T2)
# step 3. trim pixels off border
B[B[:,1]==0,0]=0
B[B[:,-2]==0,-1]=0
B[0,B[1,:]==0]=0
B[-1,B[-2,:]==0]=0
# step 4. threshold to find dark areas
dark = dark_threshold(roi, DARK_THRESHOLD_ADJUSTMENT)
# step 5. add dark areas back to blob
B = B | dark
# step 6. binary closing
B = binary_closing(B,SE3)
# step 7. binary dilation
B = binary_dilation(B,SE2)
# step 8. thinning
B = bwmorph_thin(B,3)
# step 9. fill holes
B = binary_fill_holes(B)
# step 10. remove blobs smaller than BLOB_MIN
B = remove_small_objects(B,BLOB_MIN,connectivity=2)
# done.
return B
开发者ID:joefutrelle,项目名称:oii,代码行数:26,代码来源:segmentation.py
示例9: get_bg_mask
def get_bg_mask(img):
#if img.ndim == 3:
# bg_mask = img.any(axis=-1)
# bg_mask = np.invert(bg_mask) # consistent with np.ma, True if masked
# # make multichannel (is it really this hard?)
# bg_mask = np.repeat(bg_mask[:,:,np.newaxis], 3, axis=2)
#
#else:
# bg_mask = (img != 0)
# bg_mask = np.invert(bg_mask) # see above
#bound = segmentation.find_boundaries(bg_mask, mode='inner', background=1)
#bg_mask[bound] = 1
#min_size = img.shape[0] * img.shape[1] // 4
#holes = morphology.remove_small_holes(bg_mask, min_size=min_size)
#bg_mask[holes] = 1
bg_mask = segmentation.find_boundaries(img)
bg_mask = morphology.remove_small_objects(bg_mask)
bg_mask = morphology.remove_small_holes(bg_mask)
bg_mask = np.invert(bg_mask)
return bg_mask
开发者ID:wukm,项目名称:cakepy,代码行数:25,代码来源:get_base2.py
示例10: load_cell_image
def load_cell_image(self, sensitivity = 5., min_cell_size = 4000):
'''Load cell image and add cells to self'''
pic_nuclei = self.get_source_pic_nuclei()
self.shape = pic_nuclei.shape
nuclei = find_nuclei(pic_nuclei, sensitivity, min_cell_size)
self.cell_detect_params = (sensitivity, min_cell_size)
labels = measure_label(nuclei)
labelcount = np.bincount(labels.ravel())
bg = np.argmax(labelcount)
labels += 1
labels[labels == bg + 1] = 0
labels = remove_small_objects(labels, min_cell_size)
self.nuclei = labels
self.create_cells_from_nuclei(pic_nuclei)
self.rescale_nuclei()
开发者ID:varnivey,项目名称:darfi,代码行数:27,代码来源:pic_an.py
示例11: pred_f
def pred_f(image, stepSize=stepSize, windowSize=windowSize, param=param,
marge=None, marge_cut_off=0, ClearSmallObjects=20, list_f=list_f):
caffe.set_mode_cpu()
cn_1 = "FCN_0.01_0.99_0.0005"
wd_1 = "/share/data40T_v2/Peter/pretrained_models"
net_1 = GetNet(cn_1, wd_1)
cn_2 = "DeconvNet_0.01_0.99_0.0005"
net_2 = GetNet(cn_2, wd_1)
prob_image, bin_image, thresh = pred_image_from_two_nets(image, net_1, net_2, stepSize, windowSize,
param=param, marge=marge, method="avg",
ClearBorder="Reconstruction")
segmentation_mask = DynamicWatershedAlias(prob_image, param)
segmentation_mask = remove_small_objects(segmentation_mask, ClearSmallObjects)
table = bin_analyser(image, segmentation_mask, list_f, marge_cut_off)
segmentation_mask[segmentation_mask > 0] = 1.
contours = dilation(segmentation_mask, disk(2)) - \
erosion(segmentation_mask, disk(2))
x, y = np.where(contours == 1)
image[x, y] = np.array([0, 0, 0])
segmentation_mask = img_as_ubyte(segmentation_mask)
segmentation_mask[segmentation_mask > 0] = 255
if marge_cut_off != 0:
c = marge_cut_off
image = image[c:-c, c:-c]
segmentation_mask = segmentation_mask[c:-c, c:-c]
prob_image = prob_image[c:-c, c:-c]
return image, table, segmentation_mask, prob_image
开发者ID:PeterJackNaylor,项目名称:PhD_Fabien,代码行数:32,代码来源:DistributedVersion.py
示例12: cleanImage
def cleanImage(img, min_size, scale_factor, img_otsu=None, saver=lambda n,x: x):
img, exposure_data = normalize_exposure2(img)
img = saver("01-exposure", img)
img_otsu = ski.filter.threshold_otsu(img) if not img_otsu else img_otsu
print('otsu:',img_otsu, ski.filter.threshold_otsu(img))
img = saver("02-zoom", scipy.ndimage.zoom(img, scale_factor, order=3))
print("shape after zoom:", img.shape)
# img_pil = PIL.Image.fromarray(img).resize((np.array(img.shape)*scale_factor).tolist()[:2], resample=PIL.Image.BICUBIC)
# img = saver("02-zoom", PIL2array(img_pil))
print("img:",img.shape,img.dtype)
img_cleaned = saver("03-bw", (img > img_otsu))
# img_cleaned = saver("03-bw", (img > 0.2))
dbg = DebugData()
img_cleaned = morphology.binary_erosion(img_cleaned,morphology.disk(int(2*scale_factor)))
img_cleaned = saver("04-erosion", img_cleaned, dbg=dbg)
img_cleaned = morphology.remove_small_objects(img_cleaned, min_size=int(min_size*scale_factor), connectivity=2)
img_cleaned = saver("05-remove", img_cleaned)
cleaned_sum = np.sum(img_cleaned)
print("img_cleaned size:",cleaned_sum)
# if cleaned_sum < 1000 or cleaned_sum > 300000:
# display(Image(str(dbg.saved_path)))
# raise Exception("Image not cleaned correctly"+str(locals()))
return img_cleaned, exposure_data
开发者ID:manasdas17,项目名称:scilab-2,代码行数:31,代码来源:image_measurements_auto.py
示例13: blobs
def blobs(image, remove_mb = None, val = 160, size = 100):
""" Convolve a kernel on the image and a gaussian filter to highligh blobs. Find blobs using the
Difference of Gaussian. Remove from the list of blobs the blobs that are at the membrane.
return 3 different list
"""
thresh = threshold_otsu(image)
#Find all the blobs in the image using Difference of Gaussian
blobs_in_image = feature.blob_dog(image, min_sigma=0.01,
max_sigma=3, threshold=thresh)
blob_list = []
for blob in blobs_in_image:
y, x, r = blob
blob_list.append((y, x))
if remove_mb == None:
blob_in_image_after_binary = set(blob_list)
else:
#Create a mask to remove blobs that are at the membrane and surrounded
#by bright big object
binary = image >= val*thresh/100
binary = dilation(binary, square(3))
binary = remove_small_objects(binary, min_size=size)
# Create a list of coordinate with the binary image
coor_binary = np.nonzero(binary)
list_blob_masked = zip(*coor_binary)
#Substract the list of coordinate from the binary image to the list of blobs
blob_in_image_after_binary = (set(blob_list) - set (list_blob_masked))
return blob_in_image_after_binary
开发者ID:cespenel,项目名称:image_processing,代码行数:34,代码来源:blobs_per_cell.py
示例14: label_nuclei
def label_nuclei(binary, min_size):
'''Label, watershed and remove small objects'''
distance = medial_axis(binary, return_distance=True)[1]
distance_blured = gaussian_filter(distance, 5)
local_maxi = peak_local_max(distance_blured, indices=False, labels=binary, min_distance = 30)
markers = measure_label(local_maxi)
# markers[~binary] = -1
# labels_rw = segmentation.random_walker(binary, markers)
# labels_rw[labels_rw == -1] = 0
# labels_rw = segmentation.relabel_sequential(labels_rw)
labels_ws = watershed(-distance, markers, mask=binary)
labels_large = remove_small_objects(labels_ws,min_size)
labels_clean_border = clear_border(labels_large)
labels_from_one = relabel_sequential(labels_clean_border)
# plt.imshow(ndimage.morphology.binary_dilation(markers))
# plt.show()
return labels_from_one[0]
开发者ID:SimaGuseva,项目名称:darfi,代码行数:31,代码来源:pic_an_calc.py
示例15: func
def func(frame):
frame = frame.astype(bool)
binary = remove_small_objects(frame, smooth_size)
#binary = ndi.binary_fill_holes(binary)
#opened = binary_opening(frame, disk(smooth_size))
#opened = opened & frame
return binary
开发者ID:merlinzone,项目名称:MEHI,代码行数:7,代码来源:segmentation.py
示例16: segment_cells
def segment_cells(frame, mask=None):
"""
Compute the initial segmentation based on ridge detection + watershed.
This works reasonably well, but is not robust enough to use by itself.
"""
blurred = filters.gaussian_filter(frame, 2)
ridges = enhance_ridges(frame)
# threshold ridge image
thresh = filters.threshold_otsu(ridges)
thresh_factor = 0.6
prominent_ridges = ridges > thresh_factor*thresh
prominent_ridges = morphology.remove_small_objects(prominent_ridges, min_size=256)
prominent_ridges = morphology.binary_closing(prominent_ridges)
prominent_ridges = morphology.binary_dilation(prominent_ridges)
# skeletonize
ridge_skeleton = morphology.medial_axis(prominent_ridges)
ridge_skeleton = morphology.binary_dilation(ridge_skeleton)
ridge_skeleton *= mask
ridge_skeleton -= mask
# label
cell_label_im = measure.label(ridge_skeleton)
# morphological closing to fill in the cracks
for cell_num in range(1, cell_label_im.max()+1):
cell_mask = cell_label_im==cell_num
cell_mask = morphology.binary_closing(cell_mask, disk(3))
cell_label_im[cell_mask] = cell_num
return cell_label_im
开发者ID:brikeats,项目名称:Cell-Tracking,代码行数:33,代码来源:track_cell.py
示例17: main
def main():
plt.figure(figsize=(25, 24))
planes = ['samolot00.jpg', 'samolot01.jpg', 'samolot03.jpg', 'samolot04.jpg', 'samolot05.jpg','samolot07.jpg',
'samolot08.jpg', 'samolot09.jpg', 'samolot10.jpg', 'samolot11.jpg', 'samolot12.jpg', 'samolot13.jpg',
'samolot14.jpg', 'samolot15.jpg', 'samolot16.jpg', 'samolot17.jpg', 'samolot18.jpg', 'samolot20.jpg']
i = 1
for file in planes:
img = data.imread(file, as_grey=True)
img2 = data.imread(file)
ax = plt.subplot(6, 3, i)
ax.axis('off')
img **= 0.4
img = filter.canny(img, sigma=3.0)
img = morphology.dilation(img, morphology.disk(4))
img = ndimage.binary_fill_holes(img)
img = morphology.remove_small_objects(img, 1000)
contours = measure.find_contours(img, 0.8)
ax.imshow(img2, aspect='auto')
for n, contour in enumerate(contours):
ax.plot(contour[:, 1], contour[:, 0], linewidth=1.5)
center = (sum(contour[:, 1])/len(contour[:, 1]), sum(contour[:, 0])/len(contour[:, 0]))
ax.scatter(center[0], center[1], color='white')
i += 1
plt.savefig('zad2.pdf')
开发者ID:gracz21,项目名称:KCK,代码行数:25,代码来源:Zad_2.py
示例18: load_scenes
def load_scenes(filename):
zipped_scenes = []
print 'Working on: ' + filename
img = data.imread('scenes/' + filename, as_grey=True)
tmp = img
tmp = filter.canny(tmp, sigma=2.0)
tmp = ndimage.binary_fill_holes(tmp)
#tmp = morphology.dilation(tmp, morphology.disk(2))
tmp = morphology.remove_small_objects(tmp, 2000)
contours = measure.find_contours(tmp, 0.8)
ymin, xmin = contours[0].min(axis=0)
ymax, xmax = contours[0].max(axis=0)
if xmax - xmin > ymax - ymin:
xdest = 1000
ydest = 670
else:
xdest = 670
ydest = 1000
src = np.array(((0, 0), (0, ydest), (xdest, ydest), (xdest, 0)))
dst = np.array(((xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)))
tform3 = tf.ProjectiveTransform()
tform3.estimate(src, dst)
warped = tf.warp(img, tform3, output_shape=(ydest, xdest))
tmp = filter.canny(warped, sigma=2.0)
tmp = morphology.dilation(tmp, morphology.disk(2))
descriptor_extractor.detect_and_extract(tmp)
obj_key = descriptor_extractor.keypoints
scen_desc = descriptor_extractor.descriptors
zipped_scenes.append([warped, scen_desc, obj_key, filename])
return zipped_scenes
开发者ID:gracz21,项目名称:KCK,代码行数:30,代码来源:image.py
示例19: extract_yellow
def extract_yellow(rgb, depth, T_w_k):
"""
extract red points and grey points and downsample
"""
hsv = cv2.cvtColor(rgb, cv2.COLOR_BGR2HSV)
h = hsv[:,:,0]
s = hsv[:,:,1]
v = hsv[:,:,2]
hh = h[220:300, 550:580]
ss = s[220:300, 550:580]
vv = v[220:300, 550:580]
r = rgb[220:300, 550:580, :]
#cv2.imshow("r", r)
#cv2.waitKey()
#IPython.embed()
h_mask = (h>0) & (h<40)
s_mask = (s>20) & (s<90)
v_mask = (v>200) & (v<255)
yellow_mask = h_mask & s_mask & v_mask
valid_mask = depth > 0
xyz_k = clouds.depth_to_xyz(depth, berkeley_pr2.f)
xyz_w = xyz_k.dot(T_w_k[:3,:3].T) + T_w_k[:3,3][None,None,:]
z = xyz_w[:,:,2]
z0 = xyz_k[:,:,2]
height_mask = xyz_w[:,:,2] > .50 # TODO pass in parameter
good_mask = yellow_mask & height_mask
good_mask = skim.remove_small_objects(good_mask,min_size=64)
if DEBUG_PLOTS:
#cv2.imshow("z0",z0/z0.max())
#cv2.imshow("z",z/z.max())
cv2.imshow("hue", h_mask.astype('uint8')*255)
cv2.imshow("sat", s_mask.astype('uint8')*255)
cv2.imshow("val", v_mask.astype('uint8')*255)
#cv2.imshow("yellow", yellow_mask.astype('uint8')*255)
cv2.imshow("final",good_mask.astype('uint8')*255)
#cv2.imshow("small", small)
cv2.imshow("rgb", rgb)
cv2.waitKey()
good_xyz = xyz_w[good_mask]
return clouds.downsample(good_xyz, .0125)
开发者ID:warriorarmentaix,项目名称:rapprentice,代码行数:60,代码来源:cloud_proc_funcs.py
示例20: morphOps
def morphOps( imgIn, sizeSE, sizeCC ):
imgOut = imgIn.astype(bool) #boolean image
imgOut = ~imgOut #img negative
imgOut = morphology.remove_small_objects( imgOut, sizeCC ) #cclargest
SE = morphology.selem.disk( sizeSE ) #structuring element
imgOut = morphology.closing(imgOut, SE)
return imgOut
开发者ID:vsimonis,项目名称:worm1,代码行数:7,代码来源:imgProc.py
注:本文中的skimage.morphology.remove_small_objects函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论