Python PIL.ImageFilter.FIND_EDGES Examples
The following are 16
code examples of PIL.ImageFilter.FIND_EDGES().
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
PIL.ImageFilter
, or try the search function
.
Example #1
Source File: test_image_filter.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_sanity(self): def filter(filter): for mode in ["L", "RGB", "CMYK"]: im = hopper(mode) out = im.filter(filter) self.assertEqual(out.mode, im.mode) self.assertEqual(out.size, im.size) filter(ImageFilter.BLUR) filter(ImageFilter.CONTOUR) filter(ImageFilter.DETAIL) filter(ImageFilter.EDGE_ENHANCE) filter(ImageFilter.EDGE_ENHANCE_MORE) filter(ImageFilter.EMBOSS) filter(ImageFilter.FIND_EDGES) filter(ImageFilter.SMOOTH) filter(ImageFilter.SMOOTH_MORE) filter(ImageFilter.SHARPEN) filter(ImageFilter.MaxFilter) filter(ImageFilter.MedianFilter) filter(ImageFilter.MinFilter) filter(ImageFilter.ModeFilter) filter(ImageFilter.GaussianBlur) filter(ImageFilter.GaussianBlur(5)) filter(ImageFilter.BoxBlur(5)) filter(ImageFilter.UnsharpMask) filter(ImageFilter.UnsharpMask(10)) self.assertRaises(TypeError, filter, "hello")
Example #2
Source File: test_image_filters.py From pliers with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_pillow_image_filter_filter(): stim = ImageStim(join(IMAGE_DIR, 'thai_people.jpg')) with pytest.raises(ValueError): filt = PillowImageFilter() filt = PillowImageFilter('BLUR') blurred = filt.transform(stim) assert blurred is not None from PIL import ImageFilter filt2 = PillowImageFilter(ImageFilter.FIND_EDGES) edges = filt2.transform(stim) assert np.array_equal(edges.data[0, 0], [134, 85, 45]) filt3 = PillowImageFilter(ImageFilter.MinFilter(3)) min_img = filt3.transform(stim) assert np.array_equal(min_img.data[0, 0], [122, 74, 36]) filt4 = PillowImageFilter('MinFilter') min_img = filt4.transform(stim) assert np.array_equal(min_img.data[0, 0], [122, 74, 36]) filt5 = PillowImageFilter(ImageFilter.MaxFilter, size=3) med_img = filt5.transform(stim) assert np.array_equal(med_img.data[0, 0], [136, 86, 49])
Example #3
Source File: pilutil.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def imfilter(arr, ftype): """ Simple filtering of an image. Parameters ---------- arr : ndarray The array of Image in which the filter is to be applied. ftype : str The filter that has to be applied. Legal values are: 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more', 'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'. Returns ------- imfilter : ndarray The array with filter applied. Raises ------ ValueError *Unknown filter type.* If the filter you are trying to apply is unsupported. """ _tdict = {'blur': ImageFilter.BLUR, 'contour': ImageFilter.CONTOUR, 'detail': ImageFilter.DETAIL, 'edge_enhance': ImageFilter.EDGE_ENHANCE, 'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE, 'emboss': ImageFilter.EMBOSS, 'find_edges': ImageFilter.FIND_EDGES, 'smooth': ImageFilter.SMOOTH, 'smooth_more': ImageFilter.SMOOTH_MORE, 'sharpen': ImageFilter.SHARPEN } im = toimage(arr) if ftype not in _tdict: raise ValueError("Unknown filter type.") return fromimage(im.filter(_tdict[ftype]))
Example #4
Source File: picmaker.py From pds-tools with Academic Free License v3.0 | 6 votes |
def FilterImage(image, filter_name): """Applies an arbitrary filtering to a PIL image. Note that this does not work for two-byte images. Input: image a PIL image as 8-bit RGB or grayscale. filter_name name of the filter to be applied. Choices are "NONE", "BLUR", "CONTOUR", "DETAIL" ,"EDGE_ENHANCE", "EDGE_ENHANCE_MORE", "EMBOSS", "FIND_EDGES", "SMOOTH", "SMOOTH_MORE", "SHARPEN", "MEDIAN_3", "MEDIAN_5", "MEDIAN_7", "MINIMUM_3", "MINIMUM_5", "MINIMUM_7" ,"MAXIMUM_3", "MAXIMUM_5", and "MAXIMUM_7". Return: a pointer to the filtered image. """ if type(image) == list: raise ValueError("filtering of 2-byte images is not supported") # Look up filter method if filter: filter_method = FILTER_DICT[filter_name.upper()] else: filter_method = None # Apply filter if necessary if filter_method: image = image.filter(filter_method) return image ################################################################################ # Re-size a PIL image ################################################################################
Example #5
Source File: pilutil.py From lambda-packs with MIT License | 5 votes |
def imfilter(arr, ftype): """ Simple filtering of an image. This function is only available if Python Imaging Library (PIL) is installed. .. warning:: This function uses `bytescale` under the hood to rescale images to use the full (0, 255) range if ``mode`` is one of ``None, 'L', 'P', 'l'``. It will also cast data for 2-D images to ``uint32`` for ``mode=None`` (which is the default). Parameters ---------- arr : ndarray The array of Image in which the filter is to be applied. ftype : str The filter that has to be applied. Legal values are: 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more', 'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'. Returns ------- imfilter : ndarray The array with filter applied. Raises ------ ValueError *Unknown filter type.* If the filter you are trying to apply is unsupported. """ _tdict = {'blur': ImageFilter.BLUR, 'contour': ImageFilter.CONTOUR, 'detail': ImageFilter.DETAIL, 'edge_enhance': ImageFilter.EDGE_ENHANCE, 'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE, 'emboss': ImageFilter.EMBOSS, 'find_edges': ImageFilter.FIND_EDGES, 'smooth': ImageFilter.SMOOTH, 'smooth_more': ImageFilter.SMOOTH_MORE, 'sharpen': ImageFilter.SHARPEN } im = toimage(arr) if ftype not in _tdict: raise ValueError("Unknown filter type.") return fromimage(im.filter(_tdict[ftype]))
Example #6
Source File: wx_jump_py3.py From wx_jump with MIT License | 5 votes |
def get_des_position(_img_path: '临时图片路径', _self_point: '起始点坐标'): """ 获取目标点位置 """ _img = Image.open(_img_path) # 两次边缘检测 _img = _img.filter(ImageFilter.FIND_EDGES) _img = _img.filter(ImageFilter.FIND_EDGES) # 2 value _img = _img.convert('1') _img.save('temp1.png') # 排除顶端的干扰 _img = np.array(_img)[IGNORE_HEIGHT[0]:] # 按行扫描图片 for index, each in enumerate(_img): old_line = _img[index-1] # 如果有变化说明检测到顶端 if (each[1:-1] - old_line[1:-1]).any(): # black line if any(map(lambda x: list(x).count(True) > int(len(each)/2), (each, old_line))): continue else: des_x = _get_des_x(each, old_line) des_y = _get_des_y(index, des_x, _img) if abs(des_x - self_point[0]) < CHESS_WIDTH * 2: continue else: break else: raise ValueError('Something error.') return des_x, des_y
Example #7
Source File: pilutil.py From Computable with MIT License | 5 votes |
def imfilter(arr,ftype): """ Simple filtering of an image. Parameters ---------- arr : ndarray The array of Image in which the filter is to be applied. ftype : str The filter that has to be applied. Legal values are: 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more', 'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'. Returns ------- imfilter : ndarray The array with filter applied. Raises ------ ValueError *Unknown filter type.* If the filter you are trying to apply is unsupported. """ _tdict = {'blur':ImageFilter.BLUR, 'contour':ImageFilter.CONTOUR, 'detail':ImageFilter.DETAIL, 'edge_enhance':ImageFilter.EDGE_ENHANCE, 'edge_enhance_more':ImageFilter.EDGE_ENHANCE_MORE, 'emboss':ImageFilter.EMBOSS, 'find_edges':ImageFilter.FIND_EDGES, 'smooth':ImageFilter.SMOOTH, 'smooth_more':ImageFilter.SMOOTH_MORE, 'sharpen':ImageFilter.SHARPEN } im = toimage(arr) if ftype not in _tdict: raise ValueError("Unknown filter type.") return fromimage(im.filter(_tdict[ftype]))
Example #8
Source File: drawTriangles.py From Delaunay_Triangulation with ISC License | 5 votes |
def loadAndFilterImage(name): start = time.clock() orig = Image.open(name) im = orig.convert("L") im = im.filter(ImageFilter.GaussianBlur(radius=5)) im = im.filter(ImageFilter.FIND_EDGES) im = brightenImage(im, 20.0) im = im.filter(ImageFilter.GaussianBlur(radius=5)) print "Bild laden: %.2fs" % (time.clock()-start) return (orig, im)
Example #9
Source File: interval.py From NotSoBot with MIT License | 5 votes |
def edge(pixels, image, angle): img = Image.open(image) img = img.rotate(angle, expand=True) edges = img.filter(ImageFilter.FIND_EDGES) edges = edges.convert('RGBA') edge_data = edges.load() filter_pixels = [] edge_pixels = [] intervals = [] for y in range(img.size[1]): filter_pixels.append([]) for x in range(img.size[0]): filter_pixels[y].append(edge_data[x, y]) for y in range(len(pixels)): edge_pixels.append([]) for x in range(len(pixels[0])): if util.lightness(filter_pixels[y][x]) < 0.25: edge_pixels[y].append(constants.white_pixel) else: edge_pixels[y].append(constants.black_pixel) for y in range(len(pixels) - 1, 1, -1): for x in range(len(pixels[0]) - 1, 1, -1): if edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][x - 1] == constants.black_pixel: edge_pixels[y][x] = constants.white_pixel for y in range(len(pixels)): intervals.append([]) for x in range(len(pixels[0])): if edge_pixels[y][x] == constants.black_pixel: intervals[y].append(x) intervals[y].append(len(pixels[0])) return intervals
Example #10
Source File: interval.py From NotSoBot with MIT License | 5 votes |
def file_edges(pixels, image, angle): img = Image.open(image) img = img.rotate(angle, expand=True) img = img.resize((len(pixels[0]), len(pixels)), Image.ANTIALIAS) edges = img.filter(ImageFilter.FIND_EDGES) edges = edges.convert('RGBA') edge_data = edges.load() filter_pixels = [] edge_pixels = [] intervals = [] for y in range(img.size[1]): filter_pixels.append([]) for x in range(img.size[0]): filter_pixels[y].append(edge_data[x, y]) for y in range(len(pixels)): edge_pixels.append([]) for x in range(len(pixels[0])): if util.lightness(filter_pixels[y][x]) < 0.25: edge_pixels[y].append(constants.white_pixel) else: edge_pixels[y].append(constants.black_pixel) for y in range(len(pixels) - 1, 1, -1): for x in range(len(pixels[0]) - 1, 1, -1): if edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][x - 1] == constants.black_pixel: edge_pixels[y][x] = constants.white_pixel for y in range(len(pixels)): intervals.append([]) for x in range(len(pixels[0])): if edge_pixels[y][x] == constants.black_pixel: intervals[y].append(x) intervals[y].append(len(pixels[0])) return intervals
Example #11
Source File: interval.py From Trusty-cogs with MIT License | 5 votes |
def edge(pixels, image, angle): img = Image.open(image) img = img.rotate(angle, expand=True) edges = img.filter(ImageFilter.FIND_EDGES) edges = edges.convert("RGBA") edge_data = edges.load() filter_pixels = [] edge_pixels = [] intervals = [] for y in range(img.size[1]): filter_pixels.append([]) for x in range(img.size[0]): filter_pixels[y].append(edge_data[x, y]) for y in range(len(pixels)): edge_pixels.append([]) for x in range(len(pixels[0])): if util.lightness(filter_pixels[y][x]) < 0.25: edge_pixels[y].append(constants.white_pixel) else: edge_pixels[y].append(constants.black_pixel) for y in range(len(pixels) - 1, 1, -1): for x in range(len(pixels[0]) - 1, 1, -1): if ( edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][x - 1] == constants.black_pixel ): edge_pixels[y][x] = constants.white_pixel for y in range(len(pixels)): intervals.append([]) for x in range(len(pixels[0])): if edge_pixels[y][x] == constants.black_pixel: intervals[y].append(x) intervals[y].append(len(pixels[0])) return intervals
Example #12
Source File: interval.py From Trusty-cogs with MIT License | 5 votes |
def file_edges(pixels, image, angle): img = Image.open(image) img = img.rotate(angle, expand=True) img = img.resize((len(pixels[0]), len(pixels)), Image.ANTIALIAS) edges = img.filter(ImageFilter.FIND_EDGES) edges = edges.convert("RGBA") edge_data = edges.load() filter_pixels = [] edge_pixels = [] intervals = [] for y in range(img.size[1]): filter_pixels.append([]) for x in range(img.size[0]): filter_pixels[y].append(edge_data[x, y]) for y in range(len(pixels)): edge_pixels.append([]) for x in range(len(pixels[0])): if util.lightness(filter_pixels[y][x]) < 0.25: edge_pixels[y].append(constants.white_pixel) else: edge_pixels[y].append(constants.black_pixel) for y in range(len(pixels) - 1, 1, -1): for x in range(len(pixels[0]) - 1, 1, -1): if ( edge_pixels[y][x] == constants.black_pixel and edge_pixels[y][x - 1] == constants.black_pixel ): edge_pixels[y][x] = constants.white_pixel for y in range(len(pixels)): intervals.append([]) for x in range(len(pixels[0])): if edge_pixels[y][x] == constants.black_pixel: intervals[y].append(x) intervals[y].append(len(pixels[0])) return intervals
Example #13
Source File: interval.py From pixelsort with MIT License | 5 votes |
def edge(image, lower_threshold, **kwargs): edge_data = image.filter(ImageFilter.FIND_EDGES).convert('RGBA').load() intervals = [] for y in range(image.size[1]): intervals.append([]) flag = True for x in range(image.size[0]): if lightness(edge_data[x, y]) < lower_threshold: flag = True elif flag: intervals[y].append(x) flag = False return intervals
Example #14
Source File: interval.py From pixelsort with MIT License | 5 votes |
def file_edges(image, interval_image, lower_threshold, **kwargs): edge_data = interval_image.filter( ImageFilter.FIND_EDGES).convert('RGBA').load() intervals = [] for y in range(image.size[1]): intervals.append([]) flag = True for x in range(image.size[0]): if lightness(edge_data[x, y]) < lower_threshold: flag = True elif flag: intervals[y].append(x) flag = False return intervals
Example #15
Source File: pilutil.py From GraphicDesignPatternByPython with MIT License | 4 votes |
def imfilter(arr, ftype): """ Simple filtering of an image. This function is only available if Python Imaging Library (PIL) is installed. .. warning:: This function uses `bytescale` under the hood to rescale images to use the full (0, 255) range if ``mode`` is one of ``None, 'L', 'P', 'l'``. It will also cast data for 2-D images to ``uint32`` for ``mode=None`` (which is the default). Parameters ---------- arr : ndarray The array of Image in which the filter is to be applied. ftype : str The filter that has to be applied. Legal values are: 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more', 'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'. Returns ------- imfilter : ndarray The array with filter applied. Raises ------ ValueError *Unknown filter type.* If the filter you are trying to apply is unsupported. """ _tdict = {'blur': ImageFilter.BLUR, 'contour': ImageFilter.CONTOUR, 'detail': ImageFilter.DETAIL, 'edge_enhance': ImageFilter.EDGE_ENHANCE, 'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE, 'emboss': ImageFilter.EMBOSS, 'find_edges': ImageFilter.FIND_EDGES, 'smooth': ImageFilter.SMOOTH, 'smooth_more': ImageFilter.SMOOTH_MORE, 'sharpen': ImageFilter.SHARPEN } im = toimage(arr) if ftype not in _tdict: raise ValueError("Unknown filter type.") return fromimage(im.filter(_tdict[ftype]))
Example #16
Source File: image.py From Fruit-API with GNU General Public License v3.0 | 4 votes |
def imfilter(arr, ftype): """ Simple filtering of an image. This function is only available if Python Imaging Library (PIL) is installed. .. warning:: This function uses `bytescale` under the hood to rescale images to use the full (0, 255) range if ``mode`` is one of ``None, 'L', 'P', 'l'``. It will also cast data for 2-D images to ``uint32`` for ``mode=None`` (which is the default). Parameters ---------- arr : ndarray The array of Image in which the filter is to be applied. ftype : str The filter that has to be applied. Legal values are: 'blur', 'contour', 'detail', 'edge_enhance', 'edge_enhance_more', 'emboss', 'find_edges', 'smooth', 'smooth_more', 'sharpen'. Returns ------- imfilter : ndarray The array with filter applied. Raises ------ ValueError *Unknown filter type.* If the filter you are trying to apply is unsupported. """ _tdict = {'blur': ImageFilter.BLUR, 'contour': ImageFilter.CONTOUR, 'detail': ImageFilter.DETAIL, 'edge_enhance': ImageFilter.EDGE_ENHANCE, 'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE, 'emboss': ImageFilter.EMBOSS, 'find_edges': ImageFilter.FIND_EDGES, 'smooth': ImageFilter.SMOOTH, 'smooth_more': ImageFilter.SMOOTH_MORE, 'sharpen': ImageFilter.SHARPEN } im = toimage(arr) if ftype not in _tdict: raise ValueError("Unknown filter type.") return fromimage(im.filter(_tdict[ftype]))