本文整理汇总了Python中skimage.filters.threshold_adaptive函数的典型用法代码示例。如果您正苦于以下问题:Python threshold_adaptive函数的具体用法?Python threshold_adaptive怎么用?Python threshold_adaptive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了threshold_adaptive函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: transform_perspective
def transform_perspective(image, board):
ratio = image.shape[0] / 500.0
warped = transform.four_point_transform(image, board.reshape(4, 2) * ratio)
warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
warped = threshold_adaptive(warped, 250, offset = 10)
warped = warped.astype("uint8") * 255
cv2.imwrite("scanned.png", warped)
开发者ID:josecols,项目名称:sb-ubicomp,代码行数:7,代码来源:scan.py
示例2: compute_base_mask
def compute_base_mask(self, params):
"""Creates the base 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
To create the base mask, two algorithms are available, on based on the
threshold_isodata and the other one on the threshold_adaptive functions
of the scikit-image.threshold module.
"""
x0, y0, x1, y1 = self.clip
base_mask = np.copy(self.base_image[x0:x1, y0:y1])
if params.mask_algorithm == "Isodata":
isodata_threshold = threshold_isodata(base_mask)
base_mask = img_as_float(base_mask <= isodata_threshold)
elif params.mask_algorithm == "Local Average":
# need to invert because threshold_adaptive sets dark parts to 0
base_mask = 1.0 - threshold_adaptive(base_mask,
params.mask_blocksize,
offset=params.mask_offset)
else:
print "Not a valid mask algorithm"
self.base_mask = 1 - base_mask
开发者ID:brunomsaraiva,项目名称:eHooke_1.0,代码行数:26,代码来源:images.py
示例3: processImage
def processImage(self, fileBuffer):
# tmp_name = uuid.uuid4().__str__() + ".png"
try:
image = Image.open(fileBuffer)
image.thumbnail(self.size)
converted = image.convert("L")
# converted = ImageEnhance.Contrast(converted).enhance(1.1)
# converted = ImageEnhance.Brightness(converted).enhance(1.1)
converted = ImageEnhance.Sharpness(converted).enhance(1.4)
# image = np.array(converted)
image = matplotlib.image.pil_to_array(converted)
binary_adaptive = threshold_adaptive(image, 40, offset=10)
figsize = [x / float(self._dpi) for x in (binary_adaptive.shape[1], binary_adaptive.shape[0])]
fig = Figure(figsize=figsize, dpi=self._dpi, frameon=False)
canvas = FigureCanvasAgg(fig)
fig.figimage(binary_adaptive)
output = StringIO()
fig.savefig(output, format='png')
output.seek(0)
self.outfiles.append(output)
except IOError:
self.invalidFiles.append(fileBuffer)
开发者ID:urakozz,项目名称:python-pdfer,代码行数:27,代码来源:pdfer.py
示例4: adaptive_threshold_mask
def adaptive_threshold_mask(frame):
"""
adaptive thresholding with boolean output
"""
block_size = 15
frame = filters.threshold_adaptive(grayscale(frame), block_size=block_size)
return frame
开发者ID:grayhem,项目名称:inspection_port,代码行数:7,代码来源:primitives.py
示例5: 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
示例6: adaptive_threshold
def adaptive_threshold(frame):
"""
apply adaptive thresholding. grayscale output.
"""
block_size = 7
frame = filters.threshold_adaptive(grayscale(frame), block_size=block_size)
return frame.astype(np.uint8)*255
开发者ID:grayhem,项目名称:inspection_port,代码行数:7,代码来源:primitives.py
示例7: segment
def segment(self, image):
"""
"""
# image = src[:]
if self.use_adaptive_threshold:
bs = self.blocksize
if not bs % 2:
bs += 1
markers = threshold_adaptive(image, bs)
# n = markers[:].astype('uint8')
n = markers.astype('uint8')
# n[markers] = 255
# n[invert(markers)] = 1
# markers = n
return n
else:
markers = zeros_like(image)
# print('image',image.max(), image.min())
# print('le', image<self.threshold_low)
# print('ge', image>self.threshold_high)
markers[image <= self.threshold_low] = 1
markers[image > self.threshold_high] = 255
#elmap = sobel(image, mask=image)
elmap = canny(image, sigma=1)
wsrc = watershed(elmap, markers, mask=image)
return invert(wsrc)
开发者ID:NMGRL,项目名称:pychron,代码行数:30,代码来源:region.py
示例8: make_prediction
def make_prediction():
import sys
import numpy as np
import pandas as pd
from skimage.data import imread
from skimage.filters import threshold_adaptive
from skimage.restoration import denoise_tv_bregman
from sklearn.cross_validation import train_test_split
from sklearn.grid_search import GridSearchCV
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
from model_design import model_design
classifier = model_design()
X, IDs = [], range(6284, 12504)
for ID in IDs:
original = imread('../data/testResized/' + str(ID) +'.Bmp', as_grey=True)
denoised = denoise_tv_bregman(original, 3)
binarilized = threshold_adaptive(denoised, block_size=13, method='gaussian')
feature = binarilized.reshape(1,400)[0]
X.append(feature)
X = np.array(X)
y = classifier.predict(X)
result = pd.DataFrame({'Id': IDs, 'Class': y})
result.to_csv('../result/06-09-2015_AdaBoostXTC.csv', sep=',', index=None, columns=['Id', 'Class'])
开发者ID:pigeatshit,项目名称:Kaggle,代码行数:30,代码来源:make_prediction.py
示例9: intensity_object_features
def intensity_object_features(im, adaptive_t_radius=51, sample_size=None):
"""Segment objects based on intensity threshold and compute properties.
Parameters
----------
im : 2D np.ndarray of float or uint8.
The input image.
adaptive_t_radius : int, optional
The radius to calculate background with adaptive threshold.
sample_size : int, optional
Sample this many objects randomly, rather than measuring all
objects.
Returns
-------
f : 1D np.ndarray of float
The feature vector.
names : list of string
The list of feature names.
"""
tim1 = im > imfilter.threshold_otsu(im)
f1, names1 = object_features(tim1, im, sample_size=sample_size)
names1 = ['otsu-threshold-' + name for name in names1]
tim2 = imfilter.threshold_adaptive(im, adaptive_t_radius)
f2, names2 = object_features(tim2, im, sample_size=sample_size)
names2 = ['adaptive-threshold-' + name for name in names2]
f = np.concatenate([f1, f2])
return f, names1 + names2
开发者ID:koenvb,项目名称:microscopium,代码行数:28,代码来源:features.py
示例10: text_segments
def text_segments(img, min_h=20, max_h=50):
gray_scale_img = rgb2grayscale(img)
binarized_adaptive_img = threshold_adaptive(gray_scale_img, block_size=40, offset=20)
dilated = dilation(~binarized_adaptive_img, rectangle(1, 15))
for segment in extract_segments(dilated.copy()):
if min_h < height(segment) < max_h:
yield segment
开发者ID:sdanaipat,项目名称:Reverse-Engineer-Evernote-Camera,代码行数:8,代码来源:segmentation.py
示例11: get_nuclei
def get_nuclei(img, opening_radius=6, block_size=80, threshold_offset=0):
s = Sample(DOWNSAMPLE)
binary = threshold_adaptive(s.downsample(img), int(block_size / s.rate), offset=threshold_offset)
filled = fill_holes(binary)
opened = opening(filled, selem=disk(opening_radius / s.rate))
nuclei = apply_watershed(opened)
nuclei = s.upsample(nuclei)
return img_as_uint(nuclei)
开发者ID:feldman4,项目名称:lasagna,代码行数:8,代码来源:process.py
示例12: cut
def cut(image):
V = cv2.split(cv2.cvtColor(image, cv2.COLOR_BGR2HSV))[2]
thresh = threshold_adaptive(V, 29, offset=15).astype("uint8") * 255
thresh = cv2.bitwise_not(thresh)
# perform a connected components analysis and initialize the mask to store the locations
# of the character candidates
labels = measure.label(thresh, neighbors=8, background=0)
boxes = []
# loop over the unique components
for label in np.unique(labels):
# if this is the background label, ignore it
if label == 0:
continue
# otherwise, construct the label mask to display only connected components for the
# current label, then find contours in the label mask
labelMask = np.zeros(thresh.shape, dtype="uint8")
labelMask[labels == label] = 255
(_, cnts, _) = cv2.findContours(labelMask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# ensure at least one contour was found in the mask
if len(cnts) > 0:
# grab the largest contour which corresponds to the component in the mask, then
# grab the bounding box for the contour
c = max(cnts, key=cv2.contourArea)
(boxX, boxY, boxW, boxH) = cv2.boundingRect(c)
# compute the aspect ratio, solidity, and height ratio for the component
aspectRatio = boxW / float(boxH)
solidity = cv2.contourArea(c) / float(boxW * boxH)
heightRatio = boxH / float(thresh.shape[0])
# determine if the aspect ratio, solidity, and height of the contour pass
# the rules tests
keepAspectRatio = aspectRatio < 1.0
keepSolidity = solidity > 0.15
keepHeight = heightRatio > 0.4 and heightRatio < 0.95
# check to see if the component passes all the tests
if keepAspectRatio and keepSolidity and keepHeight:
# compute the convex hull of the contour and draw it on the character
# candidates mask
# hull = cv2.convexHull(c)
# cv2.drawContours(charCandidates, [hull], -1, 255, -1)
#
dX = min(35, 35 - boxW) // 2
boxX -= dX
boxW += (dX * 2)
boxes.append((boxX, boxY, boxX + boxW, boxY + boxH))
# sort the bounding boxes from left to right
boxes = sorted(boxes, key=lambda b: b[0])
return boxes, thresh
开发者ID:clavicule,项目名称:periscope,代码行数:58,代码来源:scissors.py
示例13: fixedThresholding
def fixedThresholding(img, threshold):
#func = lambda x: 0 if x>threshold else 255
def func(x):
if x > threshold:
return 0
else:
return 255
return filters.threshold_adaptive(img, 1, 'generic', param=func)
开发者ID:dengkunli,项目名称:Dithering,代码行数:9,代码来源:threshold.py
示例14: predict_data
def predict_data():
X, IDs = [], range(6284, 12504)
for ID in IDs:
original = imread('../data/testResized/' + str(ID) +'.Bmp', as_grey=True)
denoised = denoise_tv_bregman(original, 3)
binarilized = threshold_adaptive(denoised, block_size=13, method='gaussian')
feature = binarilized.reshape(1,400)[0]
X.append(feature)
X = np.array(X)
return X
开发者ID:pigeatshit,项目名称:Kaggle,代码行数:10,代码来源:stacking.py
示例15: image_to_scan_bird_style_view
def image_to_scan_bird_style_view(image, screenCnt, ratio):
# apply the four point transform to obtain a top-down
# view of the original image
warped = four_point_transform(image, screenCnt.reshape(4, 2) * ratio)
# convert the warped image to grayscale, then threshold it
# to give it that 'black and white' paper effect
warped = cv2.cvtColor(warped, cv2.COLOR_BGR2GRAY)
warped = threshold_adaptive(warped, 250, offset=10)
warped = warped.astype("uint8") * 255
return warped
开发者ID:marekrydlewski,项目名称:morse-code-reader,代码行数:10,代码来源:scan.py
示例16: binarisation_
def binarisation_(src_image):
if len(src_image.shape) == 3:
image = (src_image.sum(axis=2) / 3).astype('ubyte')
else:
image = src_image
block_size = 35
binary = threshold_adaptive(image, block_size, offset=20)
binary = binary.astype('ubyte')
#im = (binary * 255).astype('ubyte')
return binary
开发者ID:CoinLQ,项目名称:SegmentationCheck,代码行数:10,代码来源:layoutseg.py
示例17: preprocess_algae
def preprocess_algae(img):
# Crop the pictures as for raw images.
# Apply thresholds
img = filters.threshold_adaptive(img,25)
threshold = 0.3
idx = img > img.max() * threshold
idx2 = img < img.max() * threshold
img[idx] = 255
img[idx2] = 0
return util.img_as_int(img)
开发者ID:ZLoverty,项目名称:Hello-World,代码行数:11,代码来源:trak.py
示例18: adaptivethreshold
def adaptivethreshold(self, image):
'''Uses an adaptive threshold to change image to binary. This is done using
the Adaptive Thresholding technique, begins by using Gaussian filtering to
remove noise, follows by creating a binary image with Otsu's Method.
Reference: https://en.wikipedia.org/wiki/Otsus_method'''
# Image is thresholded, inverted, dilated, and has holes filled.
thresh = threshold_adaptive(image, 41, offset=10)
thresh = np.invert(thresh)
thresh = ndimage.grey_dilation(thresh, size=(2,2))
return ndimage.binary_fill_holes(thresh)
开发者ID:joshdryan,项目名称:machine-learning-scikit,代码行数:11,代码来源:isolatedigits.py
示例19: preprocessImages
def preprocessImages(self, rootDir, subdir, srcFile):
rootfilename, fileType = srcFile.rsplit(".", 1)
for subdir, dirs, files in os.walk(rootDir + "/gsPdfs/" + rootfilename + "-imgs"):
for src in files:
if(".DS_Store" in src):
continue
filename, fileType = src.rsplit(".", 1)
print("Processing image")
image = Image.open(subdir + "/" + src).convert('L')
image = np.asarray(image)
block_size = 7
binary_adaptive = threshold_adaptive(image, block_size, method='gaussian', offset=-35, param=37)
开发者ID:RandalMoss,项目名称:pdf-search,代码行数:12,代码来源:pdf_text_extractor.py
示例20: preprocess
def preprocess():
labels = pd.read_csv('../data/trainLabels.csv', sep=',')
X, y = [], np.array(labels.Class)
for ID in labels.ID:
original = imread('../data/trainResized/' + str(ID) +'.Bmp', as_grey=True)
denoised = denoise_tv_bregman(original, 3)
binarilized = threshold_adaptive(denoised, block_size=13, method='gaussian')
feature = binarilized.reshape(1,400)[0]
X.append(feature)
X = np.array(X)
return X, y
开发者ID:pigeatshit,项目名称:Kaggle,代码行数:12,代码来源:tuning_parameters.py
注:本文中的skimage.filters.threshold_adaptive函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论