Python skimage.filters() Examples
The following are 5
code examples of skimage.filters().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage
, or try the search function
.
Example #1
Source File: features.py From selective_search_py with MIT License | 6 votes |
def __calc_gradient_histogram(self, label, gaussian, n_region, nbins_orientation = 8, nbins_inten = 10): op = numpy.array([[-1, 0, 1]], dtype=numpy.float32) h = scipy.ndimage.filters.convolve(gaussian, op) v = scipy.ndimage.filters.convolve(gaussian, op.transpose()) g = numpy.arctan2(v, h) # define each axis for texture histogram bin_width = 2 * math.pi / 8 bins_label = range(n_region + 1) bins_angle = numpy.linspace(-math.pi, math.pi, nbins_orientation + 1) bins_inten = numpy.linspace(.0, 1., nbins_inten + 1) bins = [bins_label, bins_angle, bins_inten] # calculate 3 dimensional histogram ar = numpy.vstack([label.ravel(), g.ravel(), gaussian.ravel()]).transpose() hist = numpy.histogramdd(ar, bins = bins)[0] # orientation_wise intensity histograms are serialized for each region return numpy.reshape(hist, (n_region, nbins_orientation * nbins_inten))
Example #2
Source File: segmentation_test.py From DRFNS with MIT License | 5 votes |
def difference_of_gaussian(self, imin, bigsize=30.0, smallsize=3.0): g1 = filters.gaussian_filter(imin, bigsize) g2 = filters.gaussian_filter(imin, smallsize) diff = 255*(g1 - g2) diff[diff < 0] = 0.0 diff[diff > 255.0] = 255.0 diff = diff.astype(np.uint8) return diff
Example #3
Source File: SPM.py From pySPM with Apache License 2.0 | 5 votes |
def get_bin_threshold(self, percent, high=True, adaptive=False, binary=True, img=False): """ Threshold the image into binary values Parameters ---------- percent : float The percentage where the thresholding is made high : bool If high a value of 1 is returned for values > percent adaptive : bool If True, performs an adaptive thresholding (see skimage.filters.threshold_adaptive) binary : bool If True return bool data (True/False) otherwise numeric (0/1) img : bool If True return a SPM_image otherwise a numpy array """ if adaptive: if binary: return self.pixels > threshold_local(self.pixels, percent) return threshold_local(self.pixels, percent) mi = np.min(self.pixels) norm = (self.pixels-mi)/(np.max(self.pixels)-mi) if high: r = norm > percent else: r = norm < percent if not img: if binary: return r return np.ones(self.pixels.shape)*r else: I = copy.deepcopy(self) I.channel = "Threshold from "+I.channel if binary: I.pixels = r else: I.pixels = np.ones(self.pixels.shape)*r return I
Example #4
Source File: BlurDetectionModule.py From HistoQC with BSD 3-Clause Clear License | 5 votes |
def identifyBlurryRegions(s, params): logging.info(f"{s['filename']} - \tidentifyBlurryRegions") blur_radius = int(params.get("blur_radius", 7)) blur_threshold = float(params.get("blur_threshold", .1)) img = s.getImgThumb(params.get("image_work_size", "2.5x")) img = rgb2gray(img) img_laplace = np.abs(skimage.filters.laplace(img)) mask = skimage.filters.gaussian(img_laplace, sigma=blur_radius) <= blur_threshold mask = skimage.transform.resize(mask, s.getImgThumb(s["image_work_size"]).shape, order=0)[:, :, 1] # for some reason resize takes a grayscale and produces a 3chan mask = s["img_mask_use"] & (mask > 0) io.imsave(s["outdir"] + os.sep + s["filename"] + "_blurry.png", img_as_ubyte(mask)) s["img_mask_blurry"] = (mask * 255) > 0 prev_mask = s["img_mask_use"] s["img_mask_use"] = s["img_mask_use"] & ~s["img_mask_blurry"] s.addToPrintList("percent_blurry", printMaskHelper(params.get("mask_statistics", s["mask_statistics"]), prev_mask, s["img_mask_use"])) if len(s["img_mask_use"].nonzero()[0]) == 0: # add warning in case the final tissue is empty logging.warning( f"{s['filename']} - After BlurDetectionModule.identifyBlurryRegions NO tissue remains detectable! Downstream modules likely to be incorrect/fail") s["warnings"].append( f"After BlurDetectionModule.identifyBlurryRegions NO tissue remains detectable! Downstream modules likely to be incorrect/fail") return
Example #5
Source File: features.py From selective_search_py with MIT License | 5 votes |
def __init_texture(self, n_region): gaussian = skimage.filters.gaussian_filter(self.image, sigma = 1.0, multichannel = True).astype(numpy.float32) r_hist = self.__calc_gradient_histogram(self.label, gaussian[:, :, 0], n_region) g_hist = self.__calc_gradient_histogram(self.label, gaussian[:, :, 1], n_region) b_hist = self.__calc_gradient_histogram(self.label, gaussian[:, :, 2], n_region) hist = numpy.hstack([r_hist, g_hist, b_hist]) l1_norm = numpy.sum(hist, axis = 1).reshape((n_region, 1)) hist = numpy.nan_to_num(hist / l1_norm) return {i : hist[i] for i in range(n_region)}