我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用skimage.color.rgb2grey()。
def _extract_lines(img, edges=None, mask=None, min_line_length=20, max_line_gap=3): global __i__ __i__ += 1 if edges is None: edges = canny(rgb2grey(img)) if mask is not None: edges = edges & mask # figure() # subplot(131) # imshow(img) # subplot(132) #vimshow(edges) # subplot(133) # if mask is not None: # imshow(mask, cmap=cm.gray) # savefig('/home/shared/Projects/Facades/src/data/for-labelme/debug/foo/{:06}.jpg'.format(__i__)) lines = np.array(probabilistic_hough_line(edges, line_length=min_line_length, line_gap=max_line_gap)) return lines
def phash64(img): """Compute a perceptual hash of an image. :param img: a rgb image to be hashed :type img: numpy.ndarray :return: a perceptrual hash of img coded on 64 bits :rtype: int """ resized = rgb2grey(resize(img, (8, 8))) mean = resized.mean() boolean_matrix = resized > mean hash_lst = boolean_matrix.reshape((1, 64))[0] hash_lst = list(map(int, hash_lst)) im_hash = 0 for v in hash_lst: im_hash = (im_hash << 1) | v return im_hash
def dhash(img): """Compute a perceptual has of an image. Algo explained here : https://blog.bearstech.com/2014/07/numpy-par-lexemple-une-implementation-de-dhash.html :param img: an image :type img: numpy.ndarray :return: a perceptual hash of img coded on 64 bits :rtype: int """ TWOS = np.array([2 ** n for n in range(7, -1, -1)]) BIGS = np.array([256 ** n for n in range(7, -1, -1)], dtype=np.uint64) img = rgb2grey(resize(img, (9, 8))) h = np.array([0] * 8, dtype=np.uint8) for i in range(8): h[i] = TWOS[img[i] > img[i + 1]].sum() return (BIGS * h).sum()
def get_joly_scenes_sementation(imgs, nb_std_above_mean_th=5.): """This function return the a list of potential scene chament segmentation without perceptual hash function. :param imgs: the list of frames (in grayscale) of the video to segment :param nb_std_above_mean_th: number of std above the mean of differences between frame to set a segmentation threshold :type imgs: list(np.array) :type nb_std_above_mean_th: float :return: the list of indexes of begining / ending sequences... :rtype: list(tupple) """ #compute diff between images diffs = [0] im1 = rgb2grey(resize(imgs[0], (8, 8))) im1 = (im1 - im1.min()) / (im1.max() - im1.min()) * 255 #dynamic expension for i in range(len(imgs) - 1): im2 = rgb2grey(resize(imgs[i + 1], (8, 8))) im2 = (im2 - im2.min()) / (im2.max() - im2.min()) * 255 diffs.append(abs(im1 - im2).sum()) im1 = im2 diffs = np.array(diffs) scene_change_threshold = diffs.mean() + diffs.std() * nb_std_above_mean_th #make the scene segmentation scenes = [] changes = diffs > scene_change_threshold #list(bollinger(diffs, lag=5, th=nb_std_above_mean_th)) sequence_begining = 0 for i in range(len(changes)): if changes[i]: scenes.append((sequence_begining, i)) sequence_begining = i return scenes
def to_grey(picture): return color.rgb2grey(picture)
def extract_and_describe(img,kmeans): features = daisy(rgb2grey(img), step = 4).reshape((-1,200)) assignments = kmeans.predict(features) histogram, _= np.histogram(assignments,bins=500,range=(0,499)) return histogram
def _scharr(img): # Invert the image to ease edge detection. img = 1. - img grey = skc.rgb2grey(img) return skf.scharr(grey)
def detect_edges(filename): """Return a normalized gray scale image.""" LOGGER.debug(filename) image = rgb2grey(imread(filename)) # rgb2gray can be a noop image = image / image.max() return canny(image, sigma=CANNY_SIGMA)
def _calc_gradient_matrix(self): # TODO: find a better method to calc the gradient height, width = self.working_image.shape[:2] grey_image = rgb2grey(self.working_image) grey_image[self.working_mask == 1] = None gradient = np.nan_to_num(np.array(np.gradient(grey_image))) gradient_val = np.sqrt(gradient[0]**2 + gradient[1]**2) max_gradient = np.zeros([height, width, 2]) front_positions = np.argwhere(self.front == 1) for point in front_positions: patch = self._get_patch(point) patch_y_gradient = self._patch_data(gradient[0], patch) patch_x_gradient = self._patch_data(gradient[1], patch) patch_gradient_val = self._patch_data(gradient_val, patch) patch_max_pos = np.unravel_index( patch_gradient_val.argmax(), patch_gradient_val.shape ) max_gradient[point[0], point[1], 0] = \ patch_y_gradient[patch_max_pos] max_gradient[point[0], point[1], 1] = \ patch_x_gradient[patch_max_pos] return max_gradient
def analyze_image(args): """Analyze all wells from all trays in one image.""" filename, config = args LOGGER.debug(filename) rows = config["rows"] columns = config["columns"] well_names = config["well_names"] name = splitext(basename(filename))[0] if config["parse_dates"]: try: index = convert_to_datetime(fix_date(name)) except ValueError as err: return {"error": str(err), "filename": filename} else: index = name try: image = rgb2grey(imread(filename)) except OSError as err: return {"error": str(err), "filename": filename} plate_images = cut_image(image) data = dict() for i, (plate_name, plate_image) in enumerate( zip(config["plate_names"], plate_images)): plate = data[plate_name] = dict() plate[config["index_name"]] = index if i // 3 == 0: calibration_plate = config["left_image"] positions = config["left_positions"] else: calibration_plate = config["right_image"] positions = config["right_positions"] try: edge_image = canny(plate_image, CANNY_SIGMA) offset = align_plates(edge_image, calibration_plate) # Add the offset to get the well centers in the analyte plate well_centers = generate_well_centers( np.array(positions) + offset, config["plate_size"], rows, columns) assert len(well_centers) == rows * columns plate_image /= (1 - plate_image + float_info.epsilon) well_intensities = [find_well_intensity(plate_image, center) for center in well_centers] for well, intensity in zip(well_names, well_intensities): plate[well] = intensity except (AttributeError, IndexError) as err: return {"error": str(err), "filename": filename} return data