Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'/home/gongxijun/data/苹果',
'/home/gongxijun/data/山楂',
'/home/gongxijun/data/西瓜',
'/home/gongxijun/data/object-detector/11',
'/home/gongxijun/data/灯笼',
'/home/gongxijun/data/test3',
'/home/gongxijun/文档'
]
# Read the image
root_path = list[-1]
_cnt = 0;
_num = 0
for image_path in os.listdir(root_path):
img = cv2.imread(os.path.join(root_path, image_path))
img = transform.resize(img, (400, 400))
imt = color.rgb2gray(img)
min_wdw_sz = (90, 128)
step_size = (10, 5)
downscale = args['downscale']
visualize_det = args['visualize']
# Load the classifier
clf = joblib.load(model_path)
# List to store the detections
detections = []
# The current scale of the image
scale = 0
# Downscale the image and iterate
for im_scaled in pyramid_gaussian(imt, downscale=downscale):
# This list contains detections at the current scale
cd = []
def ProPhotoRGB2Lab(img):
if not img.shape[2] == 3:
print('pp_rgb shape', img.shape)
raise UtilImageError('image channel number is not 3')
img = linearize_ProPhotoRGB(img)
xyz = ProPhotoRGB2XYZ(img)
lab = color.xyz2lab(xyz)
return lab
----------
image: ndarray
Image for which edgelets are to be computed.
sigma: float
Smoothing to be used for canny edge detection.
Returns
-------
locations: ndarray of shape (n_edgelets, 2)
Locations of each of the edgelets.
directions: ndarray of shape (n_edgelets, 2)
Direction of the edge (tangent) at each of the edgelet.
strengths: ndarray of shape (n_edgelets,)
Length of the line segments detected for the edgelet.
"""
gray_img = color.rgb2gray(image)
edges = feature.canny(gray_img, sigma)
lines = transform.probabilistic_hough_line(edges, line_length=3,
line_gap=2)
locations = []
directions = []
strengths = []
for p0, p1 in lines:
p0, p1 = np.array(p0), np.array(p1)
locations.append((p0 + p1) / 2)
directions.append(p1 - p0)
strengths.append(np.linalg.norm(p1 - p0))
# convert to numpy arrays and normalize
locations = np.array(locations)
import skimage.io, skimage.color
import numpy
import matplotlib.pyplot
import HOG
img = skimage.io.imread("im_patch.jpg")
img = skimage.color.rgb2gray(img)
horizontal_mask = numpy.array([-1, 0, 1])
vertical_mask = numpy.array([[-1],
[0],
[1]])
horizontal_gradient = HOG.calculate_gradient(img, horizontal_mask)
vertical_gradient = HOG.calculate_gradient(img, vertical_mask)
grad_magnitude = HOG.gradient_magnitude(horizontal_gradient, vertical_gradient)
grad_direction = HOG.gradient_direction(horizontal_gradient, vertical_gradient)
grad_direction = grad_direction % 180
hist_bins = numpy.array([10,30,50,70,90,110,130,150,170])
# Histogram of the first cell in the first block.
def load_image(self, image_id):
"""Load the specified image and return a [H,W,4] Numpy array.
"""
# Load image
image = skimage.io.imread(self.image_info[image_id]['path'])
# If grayscale. Convert to RGB for consistency.
if image.ndim != 3:
image = skimage.color.gray2rgb(image)
# If has no alpha channel, complain
if image.shape[-1] != 4:
raise Exception('image %d ("%s") has no alpha channel' % (
image_id, self.image_info[image_id]['path']))
# Convert from RGBA to RGB+Text+Address
tmask = image[:,:,3:4] > 0
amask = image[:,:,3:4] == 255
image = np.concatenate([image[:,:,:3],
255 * tmask.astype(np.uint8),
255 * amask.astype(np.uint8)],
axis=2)
return image
### Example script showing how to perform a 2D Total-Variation filtering with proxTV
import prox_tv as ptv
import matplotlib.pyplot as plt
import time
import skimage as ski
from skimage import io, color, util
import os
# Load image
here = os.path.dirname(os.path.abspath(__file__))
X = io.imread(here + '/colors.png')
X = ski.img_as_float(X)
X = color.rgb2gray(X)
# Introduce noise
noiseLevel = 0.01
N = util.random_noise(X, mode='speckle', var=noiseLevel)
# Filter using 2D TV-L1
lam=0.15;
print('Filtering image with 2D TV-L1...')
start = time.time()
F = ptv.tv1_2d(N, lam)
end = time.time()
print('Elapsed time ' + str(end-start))
# Plot results
plt.subplot(1, 3, 1)
io.imshow(X)
def multi_mask_to_overlay(multi_mask):
overlay = skimage.color.label2rgb(multi_mask, bg_label=0, bg_color=(0, 0, 0)) * 255
overlay = overlay.astype(np.uint8)
return overlay
def to_light(img, new_dims, new_scale, interp_order=1 ):
"""
Turn an image into lightness
Args:
im : (H x W x K) ndarray
new_dims : (height, width) tuple of new dimensions.
new_scale : (min, max) tuple of new scale.
interp_order : interpolation order, default is linear.
Returns:
a lightness version of the original image
"""
img = skimage.img_as_float( img )
img = resize_image( img, new_dims, interp_order )
img = skimage.color.rgb2lab(img)[:,:,0]
img = rescale_image( img, new_scale, current_scale=[0,100])
return np.expand_dims(img,2)