本文整理汇总了Python中skimage.filters.sobel函数的典型用法代码示例。如果您正苦于以下问题:Python sobel函数的具体用法?Python sobel怎么用?Python sobel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sobel函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: handle
def handle(self, *args, **options):
better_thans = BetterThan.objects.all() #.filter(pk__lte=50)
ds = SupervisedDataSet(204960, 1)
for better_than in better_thans:
bt = imread(better_than.better_than.image.file)
wt = imread(better_than.worse_than.image.file)
better_than.better_than.image.file.close()
better_than.worse_than.image.file.close()
bt = filters.sobel(bt)
wt = filters.sobel(wt)
bt_input_array = np.reshape(bt, (bt.shape[0] * bt.shape[1]))
wt_input_array = np.reshape(wt, (wt.shape[0] * wt.shape[1]))
input_1 = np.append(bt_input_array, wt_input_array)
input_2 = np.append(wt_input_array, bt_input_array)
ds.addSample(np.append(bt_input_array, wt_input_array), [-1])
ds.addSample(np.append(wt_input_array, bt_input_array), [1])
net = buildNetwork(204960, 2, 1)
train_ds, test_ds = ds.splitWithProportion(options['train_test_split'])
_, test_ds = ds.splitWithProportion(options['test_split'])
trainer = BackpropTrainer(net, ds)
avgerr = trainer.testOnData(dataset=test_ds)
print 'untrained avgerr: {0}'.format(avgerr)
trainer.train()
avgerr = trainer.testOnData(dataset=test_ds)
print 'trained avgerr: {0}'.format(avgerr)
开发者ID:722C,项目名称:nn-art-critic,代码行数:34,代码来源:nn1.py
示例2: nrOfEdgePixels
def nrOfEdgePixels(rgbimage, intensityImage):
redEdges = sobel(rgbimage[:,:,0])
grayEdges = sobel(intensityImage)
t = redEdges - grayEdges
t[t < 0.05] = 0
t[t >= 0.05] = 1
return convolve2d(t, np.ones((17,17)), mode="same")
开发者ID:fvermeij,项目名称:cad-doge,代码行数:7,代码来源:whitelesionfeatures.py
示例3: getSubImages
def getSubImages(img, pixels, size):
subImages = []
originals = []
for i in range(len(img)):
subImageRow = []
originalRow = []
for j in range(len(img[i])):
if i % pixels == 0 and j % pixels == 0 and i+size-1 < len(img) and j+size-1 < len(img[i]):
subImage = []
for k in range(i, i+size, int(size/20)):
line = []
for l in range(j, j+size, int(size/20)):
line.append(img[k][l])
subImage.append(line)
originalRow.append(subImage)
if preprocess == preprocessing.SOBEL:
subImage = denoise_bilateral(subImage, sigma_range=0.1, sigma_spatial=15)
subImage = sobel(subImage)
elif preprocess == preprocessing.HOG:
subImage = useHoG(subImage)
else:
subImage = denoise_bilateral(subImage, sigma_range=0.1, sigma_spatial=15)
subImage = sobel(subImage)
subImage = useHoG(subImage)
subImageRow.append(subImage)
if len(subImageRow) > 0:
subImages.append(subImageRow)
originals.append(originalRow)
return subImages, originals
开发者ID:morteano,项目名称:TDT4173,代码行数:29,代码来源:OCR.py
示例4: sobel
def sobel(data, sliceId=2):
edges = np.zeros(data.shape)
if sliceId == 2:
for idx in range(data.shape[2]):
edges[:, :, idx] = skifil.sobel(data[:, :, idx])
elif sliceId == 0:
for idx in range(data.shape[0]):
edges[idx, :, :] = skifil.sobel(data[idx, :, :])
return edges
开发者ID:mjirik,项目名称:lisa,代码行数:9,代码来源:tools.py
示例5: color_edge
def color_edge():
image=data.astronaut()
r=np.abs(filters.sobel(image[:,:,0]))
r=np.uint8(r/r.max()*255)
io.imsave('astronautedger.png',r)
g=np.abs(filters.sobel(image[:,:,1]))
g=np.uint8(g/g.max()*255)
io.imsave('astronautedgeg.png',g)
b=np.abs(filters.sobel(image[:,:,2]))
b=np.uint8(b/b.max()*255)
io.imsave('astronautedgeb.png',b)
开发者ID:xingnix,项目名称:learning,代码行数:11,代码来源:colorimage.py
示例6: filter_bank
def filter_bank(img, coeff_resolution):
"""
Calculates the responses of an image to M filters.
Returns 2-d array of the vectorial responses
"""
h, w = img.shape
im = np.reshape(img, (h*w, 1))
e1 = np.reshape(entropy(img, disk(coeff_resolution*5)), (h*w, 1))
e2 = np.reshape(entropy(img, disk(coeff_resolution*8)), (h*w, 1))
e3 = np.reshape(entropy(img, disk(coeff_resolution*10)), (h*w, 1))
g1 = np.reshape(gradient(img, disk(1)), (h*w, 1))
g2 = np.reshape(gradient(img, disk(coeff_resolution*3)), (h*w, 1))
g3 = np.reshape(gradient(img, disk(coeff_resolution*5)), (h*w, 1))
m1 = np.reshape(ndi.maximum_filter(256-img, size=coeff_resolution*2, mode='constant'), (h*w, 1))
m2 = np.reshape(ndi.maximum_filter(256-img, size=coeff_resolution*4, mode='constant'), (h*w, 1))
m3 = np.reshape(ndi.maximum_filter(256-img, size=coeff_resolution*7, mode='constant'), (h*w, 1))
#c = np.reshape(canny(img), (h*w, 1))
s = np.reshape(sobel(img), (h*w, 1))
return np.column_stack((im, e1, e2, e3, g1, g2, g3, m1, m2, m3, s))
开发者ID:charleygros,项目名称:AxonSegmentation,代码行数:26,代码来源:features_extraction.py
示例7: pestFeatureExtraction
def pestFeatureExtraction(filename):
selem = disk(8)
image = data.imread(filename,as_grey=True)
thresh = threshold_otsu(image)
elevation_map = sobel(image)
markers = np.zeros_like(image)
if ((image<thresh).sum() > (image>thresh).sum()):
markers[image < thresh] = 1
markers[image > thresh] = 2
else:
markers[image < thresh] = 2
markers[image > thresh] = 1
segmentation = morphology.watershed(elevation_map, markers)
segmentation = dilation(segmentation-1, selem)
segmentation = ndimage.binary_fill_holes(segmentation)
segmentation = np.logical_not(segmentation)
image[segmentation]=0;
hist = np.histogram(image.ravel(),256,[0,1])
hist = list(hist[0])
hist[:] = [float(x) / (sum(hist) - hist[0]) for x in hist]
hist.pop(0)
features = np.empty( (1, len(hist)), 'float' )
a = np.array(list(hist))
f = a.astype('float')
features[0,:]=f[:]
return features
开发者ID:SPKhan,项目名称:sarai-pest-diseases,代码行数:34,代码来源:api.py
示例8: prepare
def prepare(img):
"""
Pre-process the image before translation detection, here we transform to black and white and use edge-detection.
:param img: An image (as numpy array)
:return: The preprocessed image (as numpy array)
"""
return sobel(rgb2gray(img))
开发者ID:pmoret,项目名称:deshake,代码行数:7,代码来源:deshake.py
示例9: testSkimage
def testSkimage():
img = Image.open('../img/1.png')
img = np.array(img)
imggray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# (thresh, imgbw) = cv2.threshold(imggray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
# canny detector
# from skimage.feature import canny
# edges = canny(imggray/ 255.)
from scipy import ndimage as ndi
# fill_imgbw = ndi.binary_fill_holes(edges)
# label_objects, nb_labels = ndi.label(fill_imgbw)
# sizes = np.bincount(label_objects.ravel())
# mask_sizes = sizes > 20
# mask_sizes[0] = 0
# cleaned_imgbw = mask_sizes[label_objects]
markers = np.zeros_like(imggray)
markers[imggray < 120] = 1
markers[imggray > 150] = 2
from skimage.filters import sobel
elevation_map = sobel(imggray)
from skimage.morphology import watershed
segmentation = watershed(elevation_map, markers)
# from skimage.color import label2rgb
# segmentation = ndi.binary_fill_holes(segmentation - 10)
# labeled_coins, _ = ndi.label(segmentation)
# image_label_overlay = label2rgb(labeled_coins, image=imggray)
plt.imshow(segmentation, cmap='gray')
plt.show()
return
开发者ID:yinchuandong,项目名称:DBN_clustering,代码行数:33,代码来源:process.py
示例10: _segment_watershed
def _segment_watershed(image):
elevation_map = sobel(image)
markers = np.zeros(image.shape) # initialize markers as zero array
# determine thresholds for markers
sorted_pixels = np.sort(image, axis=None)
max_int = np.mean(sorted_pixels[-10:])
min_int = np.mean(sorted_pixels[:10])
#max_int = np.max(orig_image)
#min_int = np.min(orig_image)
alpha_min = 0.01
alpha_max = 0.4
thresh_background = (1-alpha_min)*min_int + alpha_min*max_int
thresh_spots = (1-alpha_max)*min_int + alpha_max*max_int
markers[image < thresh_background] = 1 # mark background
markers[image > thresh_spots] = 2 # mark background
segmentation = watershed(elevation_map, markers)
segmentation = segmentation-1
segmentation = ndi.binary_fill_holes(segmentation) # fill holes
return segmentation
开发者ID:afrutig,项目名称:Moloreader,代码行数:25,代码来源:detection.py
示例11: _calc_crispness
def _calc_crispness(self, grey_array):
"""Calculate three measures of the crispness of an channel.
PARAMETERS
----------
grey_array : 2D numpy array
Raw data for the grey channel.
PRODUCES
--------
crispnesses : list
Three measures of the crispness in the grey channel of types:
- ``sobel``, ``canny``, and ``laplace``
"""
grey_array = grey_array/255
sobel_var = filters.sobel(grey_array).var()
canny_array = feature.canny(grey_array, sigma=1).var()
canny_ratio = np.sum(canny_array == True)/float(
len(canny_array.flatten()))
laplace_var = filters.laplace(grey_array, ksize=3).var()
self.feature_data.extend([sobel_var, canny_ratio, laplace_var])
if self.columns_out:
self.column_names.extend(['crisp_sobel', 'crisp_canny',
'crisp_laplace'])
开发者ID:MPMakris,项目名称:Photo_Pro,代码行数:25,代码来源:read_image.py
示例12: filter
def filter(data,filtType,par):
if filtType == "sobel": filt_data = sobel(data)
elif filtType == "roberts": filt_data = roberts(data)
elif filtType == "canny": filt_data = canny(data)
elif filtType == "lowpass_avg":
from scipy import ndimage
p=int(par)
kernel = np.ones((p,p),np.float32)/(p*p)
filt_data = ndimage.convolve(data, kernel)
elif filtType == "highpass_avg":
from scipy import ndimage
p=int(par)
kernel = np.ones((p,p),np.float32)/(p*p)
lp_data = ndimage.convolve(data, kernel)
filt_data = data - lp_data
elif filtType == "lowpass_gaussian":
filt_data = gaussian(data, sigma=float(par))
elif filtType == "highpass_gaussian":
lp_data = gaussian(data, sigma=float(par))
filt_data = data - lp_data
#elif filtType == "gradient":
return filt_data
开发者ID:yunjunz,项目名称:PySAR,代码行数:25,代码来源:filter_spatial.py
示例13: transform
def transform(self,X):
imgs = []
for x in X:
if x.ndim == 3:
x =self.rgb2gray(x)
imgs.append(sobel(x).ravel())
return np.vstack(imgs)
开发者ID:cthorey,项目名称:Crater_Classification,代码行数:7,代码来源:LR_Worker.py
示例14: op_vs_ip
def op_vs_ip(subid, image_types, imagepaths, op_direc, overlays):
img_data_group=[]
img_shape_group=[]
ol_data_group=[]
ol_shape_group=[]
for i, path in enumerate(imagepaths):
axial_slice, cor_slice, sag_slice, img_aspect_axial, img_aspect_cor, img_aspect_sag = pull_midslices(path)
if os.path.isfile(overlays[i]):
axial_slice_ol, cor_slice_ol, sag_slice_ol, img_aspect_axial_ol, img_aspect_cor_ol, img_aspect_sag_ol = pull_midslices(overlays[i])
ol_data_group.append([axial_slice_ol, cor_slice_ol, sag_slice_ol])
ol_shape_group.append([img_aspect_axial_ol, img_aspect_cor_ol, img_aspect_sag_ol])
else:
ol_data_group.append(['null','null','null'])
ol_shape_group.append(['null','null','null'])
## Append to Matrices
img_data_group.append([axial_slice, cor_slice, sag_slice])
img_shape_group.append([img_aspect_axial,img_aspect_cor,img_aspect_sag])
my_cmap=plt.cm.gray
fig, axarr = plt.subplots(ncols=np.shape(img_shape_group)[1], nrows=np.shape(img_shape_group)[0], figsize=(np.shape(img_shape_group)[0]*5,np.shape(img_shape_group)[1]*5))
plt.suptitle(subid+' File Comparison', fontsize=20)
titlearray=['Axial', 'Coronal', 'Saggital']
for x in range(0,np.shape(img_shape_group)[0]):
for y in range(0,np.shape(img_shape_group)[1]):
im = axarr[x, y].imshow(img_data_group[x][y], cmap=my_cmap, aspect=img_shape_group[x][y])
axarr[x, y].set_xlabel('(Right) Radiological Convention (Left)', fontsize=10)
axarr[x, y].set_title(image_types[x]+' '+titlearray[y])
#divider = make_axes_locatable(axarr[x, y])
#cax_ = divider.append_axes("right", size="5%", pad=0.05)
#cbar = plt.colorbar(im, cax=cax_, ticks=MultipleLocator(round(np.max(img_data_group[x][y])/5, 1)))
axarr[x, y].xaxis.set_visible(False)
axarr[x, y].yaxis.set_visible(False)
if os.path.isfile(overlays[x]):
if x == 1:
thresh=0.25
if x == 2:
thresh=0.4
sl=np.array(ol_data_group[x][y]).astype(np.float64)
sl=filters.sobel(sl)
sl=preprocessing.binarize(sl, np.max(sl)*thresh)
sl[sl < 1] = 'Nan'
axarr[x, y].imshow(sl, cmap='autumn', aspect=ol_shape_group[x][y])
#plt.show()
plt.tight_layout()
plt.autoscale()
plt.savefig(op_direc)
开发者ID:DaveOC90,项目名称:Tissue-Segmentation,代码行数:60,代码来源:plot_overlay_imgs.py
示例15: main
def main():
"""Load image, apply sobel (to get x/y gradients), plot the results."""
img = data.camera()
sobel_y = np.array([[-1, -2, -1], [0, 0, 0], [1, 2, 1]])
sobel_x = np.rot90(sobel_y) # rotates counter-clockwise
# apply x/y sobel filter to get x/y gradients
img_sx = signal.correlate(img, sobel_x, mode="same")
img_sy = signal.correlate(img, sobel_y, mode="same")
# combine x/y gradients to gradient magnitude
# scikit-image's implementation divides by sqrt(2), not sure why
img_s = np.sqrt(img_sx ** 2 + img_sy ** 2) / np.sqrt(2)
# create binarized image
threshold = np.average(img_s)
img_s_bin = np.zeros(img_s.shape)
img_s_bin[img_s > threshold] = 1
# generate ground truth (scikit-image method)
ground_truth = skifilters.sobel(data.camera())
# plot
util.plot_images_grayscale(
[img, img_sx, img_sy, img_s, img_s_bin, ground_truth],
[
"Image",
"Sobel (x)",
"Sobel (y)",
"Sobel (magnitude)",
"Sobel (magnitude, binarized)",
"Sobel (Ground Truth)",
],
)
开发者ID:aleju,项目名称:computer-vision-algorithms,代码行数:35,代码来源:sobel.py
示例16: number_nucleus
def number_nucleus(image):
elevation_map = sobel(image)
markers = np.zeros_like(image)
markers[image < 250] = 1
markers[image > 2000] = 2
segmentation = watershed(elevation_map, markers)
label_img = label(segmentation)
prop = regionprops(label_img)
width, height = plt.rcParams['figure.figsize']
plt.rcParams['image.cmap'] = 'gray'
image_label_overlay = label2rgb(label_img, image=image)
fig, (ax1, ax2) = plt.subplots(ncols=2, nrows=1, figsize=(15, 8))
ax1.imshow(image_label_overlay)
ax2.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
# create list of region with are < 1000
image_labeled = [region for region in prop if region.area > 5000]
return len(image_labeled)
开发者ID:cespenel,项目名称:image_processing,代码行数:25,代码来源:blobs_per_cell.py
示例17: main
def main():
from skimage import data, io, filters
testfolder='/Users/davidgreenfield/Downloads/pics_boots/'
testimage='B00A0GVP8A.jpg'
image = io.imread(testfolder+testimage,flatten=True) # or any NumPy array!
edges = filters.sobel(image)
io.imshow(edges)
io.show()
开发者ID:dgreenfi,项目名称:ImageRec,代码行数:8,代码来源:image_tests.py
示例18: sobel
def sobel(frame):
"""
return the sobel importance of an rgb image
"""
frame = grayscale(frame)
frame = filters.sobel(frame)
# print(frame.max())
return normalize(frame)
开发者ID:grayhem,项目名称:inspection_port,代码行数:8,代码来源:primitives.py
示例19: getContourImage
def getContourImage(imageFile):
planeImage = data.imread(imageFile,True)
imageArray = np.asarray(planeImage)
averageColor = np.mean(imageArray)
imageArray = getBlackAndWhiteImage(imageArray,averageColor*0.85)
imageArray = filters.sobel(imageArray)
imageArray = morphology.dilation(imageArray,morphology.disk(3))
return imageArray
开发者ID:Yamadads,项目名称:kck,代码行数:8,代码来源:planes3.py
示例20: test_sobel_vertical
def test_sobel_vertical():
"""Sobel on a vertical edge should be a vertical line."""
i, j = np.mgrid[-5:6, -5:6]
image = (j >= 0).astype(float)
result = filters.sobel(image) * np.sqrt(2)
j[np.abs(i) == 5] = 10000
assert (np.all(result[j == 0] == 1))
assert (np.all(result[np.abs(j) > 1] == 0))
开发者ID:lotteanna,项目名称:scikit-image,代码行数:8,代码来源:test_edges.py
注:本文中的skimage.filters.sobel函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论