Best Python code snippet using lisa_python
filter.py
Source:filter.py
...14 else:15 w_pad_r = w_pad_l16 kernel_padded = np.pad(kernel, ((h_pad_l, h_pad_r), (w_pad_l, w_pad_r)))17 return kernel_padded18def _apply_filter(image_grey, kernel):19 kernel = _pad_kernel(image_grey, kernel)20 result = signal.fftconvolve(image_grey, kernel, mode='same')21 # result = signal.convolve2d(image_grey, kernel, mode='same', boundary='sym')22 result[0, :] = np.zeros_like(result[0, :])23 result[-1, :] = np.zeros_like(result[-1, :])24 result[:, 0] = np.zeros_like(result[:, 0])25 result[:, -1] = np.zeros_like(result[:, -1])26 return result27# brenner variations28def brenner_y(image_grey):29 f = image_grey[:-2, :]30 f = np.pad(f, ((1, 1), (0, 0)))31 f_padded = image_grey[2:, :]32 f_padded = np.pad(f_padded, ((1, 1), (0, 0)))33 return f**2 + f_padded**2 - 2*f*f_padded34def brenner_x(image_grey):35 f = image_grey[:, :-2]36 f = np.pad(f, ((0, 0), (1, 1)))37 f_padded = image_grey[:, 2:]38 f_padded = np.pad(f_padded, ((0, 0), (1, 1)))39 return f**2 + f_padded**2 - 2*f*f_padded40def brenner_xy(image_grey):41 x = brenner_x(image_grey)42 y = brenner_y(image_grey)43 return (x + y)/244def squared_gradient_y(image_grey):45 f = image_grey[:-1, :]46 f = np.pad(f, ((1, 0), (0, 0)))47 f_padded = image_grey[1:, :]48 f_padded = np.pad(f_padded, ((1, 0), (0, 0)))49 return f ** 2 + f_padded ** 2 - 2 * f * f_padded50def squared_gradient_x(image_grey):51 f = image_grey[:, :-1]52 f = np.pad(f, ((0, 0), (1, 0)))53 f_padded = image_grey[:, 1:]54 f_padded = np.pad(f_padded, ((0, 0), (1, 0)))55 return f**2 + f_padded**2 - 2*f*f_padded56# first order derivative operators57def different_h(image_grey):58 kernel = np.array([[0, 0, 0],59 [-1, 0, 1],60 [0, 0, 0]])61 return _apply_filter(image_grey, kernel)62def different_v(image_grey):63 kernel = np.array([[0, -1, 0],64 [0, 0, 0],65 [0, 1, 0]])66 return _apply_filter(image_grey, kernel)67def sobel_h(image_grey):68 kernel = np.array([[-1, 0, 1],69 [-2, 0, 2],70 [-1, 0, 1]])71 return _apply_filter(image_grey, kernel)72def sobel_v(image_grey):73 kernel = np.array([[-1, -2, -1],74 [0, 0 ,0],75 [1, 2, 1]])76 return _apply_filter(image_grey, kernel)77def scharr_h(image_grey):78 kernel = np.array([[-3, 0, 3],79 [-10, 0, 10],80 [-3, 0, 3]])81 return _apply_filter(image_grey, kernel)82def scharr_v(image_grey):83 kernel = np.array([[-3, -10, -3],84 [0, 0, 0],85 [3, 10, 3]])86 return _apply_filter(image_grey, kernel)87def roberts_h(image_grey):88 kernel = np.array([[0, 0, 0],89 [0, 1, 0],90 [-1, 0, 0]])91 return _apply_filter(image_grey, kernel)92def roberts_v(image_grey):93 kernel = np.array([[0, 0, 0],94 [0, 1, 0],95 [0, 0, -1]])96 return _apply_filter(image_grey, kernel)97def prewitt_h(image_grey):98 kernel = np.array([[-1, 0, 1],99 [-1, 0, 1],100 [-1, 0, 1]])101 return _apply_filter(image_grey, kernel)102def prewitt_v(image_grey):103 kernel = np.array([[-1, -1, -1],104 [0, 0, 0],105 [1, 1, 1]])106 return _apply_filter(image_grey, kernel)107# second order derivative operators108def laplacian(image_grey):109 kernel = np.array([[-1, -1, -1],110 [-1, 8, -1],111 [-1, -1, -1]])112 return _apply_filter(image_grey, kernel)113def sobel2_h(image_grey):114 kernel = np.array([[1, 2, 1],115 [-2, -4, -2],116 [1, 2, 1]])117 return _apply_filter(image_grey, kernel)118def sobel2_v(image_grey):119 kernel = np.array([[1, -2, 1],120 [2, -4, 2],121 [1, -2, 1]])122 return _apply_filter(image_grey, kernel)123def cross_sobel(image_grey):124 kernel = np.array([[-1, 0, 1],125 [0, 0, 0],126 [1, 0, -1]])...
filters.py
Source:filters.py
1from PIL import Image, ImageFilter2def _apply_filter(image: Image.Image, filter) -> Image.Image:3 return image.filter(filter)4def blur(image: Image.Image) -> Image.Image:5 return _apply_filter(image, ImageFilter.BLUR())6def contour(image: Image.Image) -> Image.Image:7 return _apply_filter(image, ImageFilter.CONTOUR())8def detail(image: Image.Image) -> Image.Image:9 return _apply_filter(image, ImageFilter.DETAIL())10def edge_enhance(image: Image.Image) -> Image.Image:11 return _apply_filter(image, ImageFilter.EDGE_ENHANCE())12def edge_enhance_plus(image: Image.Image) -> Image.Image:13 return _apply_filter(image, ImageFilter.EDGE_ENHANCE_MORE())14def emboss(image: Image.Image) -> Image.Image:15 return _apply_filter(image, ImageFilter.EMBOSS())16def find_edges(image: Image.Image) -> Image.Image:17 return _apply_filter(image, ImageFilter.FIND_EDGES())18def sharpen(image: Image.Image) -> Image.Image:19 return _apply_filter(image, ImageFilter.SHARPEN())20def smooth(image: Image.Image) -> Image.Image:21 return _apply_filter(image, ImageFilter.SMOOTH())22def smooth_plus(image: Image.Image) -> Image.Image:23 return _apply_filter(image, ImageFilter.SMOOTH_MORE())24def filter_image(image: Image.Image, filter: str) -> Image.Image:25 filtered_image = None26 if filter == "blur":27 filtered_image = blur(image)28 elif filter == "contour":29 filtered_image = contour(image)30 elif filter == "detail":31 filtered_image = detail(image)32 elif filter == "edge_enhance":33 filtered_image = edge_enhance(image)34 elif filter == "edge_enhance_plus":35 filtered_image = edge_enhance_plus(image)36 elif filter == "emboss":37 filtered_image = emboss(image)...
npysNPSFilteredData.py
Source:npysNPSFilteredData.py
...9 def get_all_values(self):10 return self._values11 def set_filter(self, this_filter):12 self._filter = this_filter13 self._apply_filter()14 def filter_data(self):15 # should set self._filtered_values to the filtered values16 raise Exception("You need to define the way the filter operates")17 18 def get(self):19 self._apply_filter()20 return self._filtered_values21 def _apply_filter(self):22 # Could do some caching here - but the default definition does not.23 self._filtered_values = self.filter_data()24 25class NPSFilteredDataList(NPSFilteredDataBase):26 def filter_data(self):27 if self._filter and self.get_all_values():28 return [x for x in self.get_all_values() if self._filter in x]29 else:30 return self.get_all_values()31 ...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!