苹果模糊滤镜_通过使用用户定义的中值模糊滤镜执行模糊操作来平滑灰度图像...

爱被打了一巴掌 2023-03-05 06:27 28阅读 0赞

苹果模糊滤镜

Image Blurring refers to making the image less clear or distinct. The Median Filter often used to remove noise from an image or signal. Median filtering is very widely used in digital image processing because, under certain conditions, it preserves edges while removing noise.

图像模糊是指使图像不太清晰或鲜明。 中值滤波器通常用于去除图像或信号中的噪声。 中值滤波在数字图像处理中非常广泛地使用,因为在某些条件下,它可以保留边缘,同时消除噪声。

In this program, we will be using two functions of OpenCV-python (cv2) module.. let’s see their syntax and descriptions first:

在此程序中,我们将使用OpenCV-python(cv2)模块的两个功能。.让我们首先查看它们的语法和说明:

1) imread():
It takes an absolute path/relative path of your image file as an argument and returns its corresponding image matrix.

1)imread():
它以图像文件的绝对路径/相对路径作为参数,并返回其对应的图像矩阵。

If flag value is:

如果标志值为:

  • 1: Loads a color image.

    1 :加载彩色图像。

  • 0: Loads image in grayscale mode.

    0 :以灰度模式加载图像。

  • -1: Loads image as such including alpha channel.

    -1 :加载图像,包括alpha通道。

If the flag value is not given then show the original image, which path is given.

如果未给出标志值,则显示原始图像,并给出哪个路径。

2) imshow():
It takes window name and image matrix as an argument in order to display an image in a display window with a specified window name.

2)imshow():
它以窗口名称和图像矩阵为参数,以便在具有指定窗口名称的显示窗口中显示图像。

Also In this program, we will be using one function of numpy module.

同样在此程序中,我们将使用numpy模块的一个功能。

median(): It takes array and returns the median of the array.

mean():获取数组并返回数组的中位数。

Also, in this program we are using the concept of array slicing

另外,在此程序中,我们使用数组切片的概念

Let, A is 1-d array:
A[start:stop:step]

设A为一维数组:
A [开始:停止:步骤]

  1. start: Starting number of the sequence.

    start:序列的起始编号。

  2. stop: Generate numbers up to, but not including this number.

    停止:生成不超过此数字的数字,但不包括此数字。

  3. step: Difference between each number in the sequence.

    步骤:序列中每个数字之间的差。

Example:

例:

  1. A = [1,2,3,4,5,6,7,8,9,10]
  2. print(A[ 1: 5])
  3. Output:
  4. [2,3,4,5]

Python程序可平滑灰度图像 (Python program for smoothen a grayscale image )

  1. # import cv2 module
  2. import cv2
  3. # import numpy module as np
  4. import numpy as np
  5. # Define a function for performing
  6. # Median Blur on images
  7. def MedianBlur(img,size) :
  8. Ic = img
  9. # run a loop from half of the size + 1 to upto
  10. # number of rows present in the image
  11. for i in range(size//2 + 1, Ic.shape[0]) :
  12. # run a loop from half of the size + 1 upto
  13. # number of columns present in the image
  14. for j in range(size//2 +1, Ic.shape[1]) :
  15. # Take a sub-matrix of specifed order form Ic image matrix
  16. N = Ic[i-size//2 : i+ size//2 + 1, j - size//2: j+ size//2 + 1]
  17. # find out median of submatrix
  18. med = np.median(N)
  19. # assing that medium value to the specified pixel coordinates
  20. img[i, j] = med
  21. # return blur image
  22. return img
  23. # Driver code
  24. if __name__ == "__main__" :
  25. # read an image using imread() function of cv2
  26. # we have to pass the path of the image
  27. # and tha value of flag which is optional
  28. img = cv2.imread(r'C:\Users\user\Desktop\pic6.jpg',0)
  29. # displaying the gray scale image
  30. cv2.imshow('original image',img)
  31. # order of the submatrix
  32. order = 5
  33. # MedianBlur function calling
  34. img = MedianBlur(img,order)
  35. # displaying the smoothen image
  36. cv2.imshow("smooth image",img)

Output

输出量

Smoothen a grayscale image in Python - output

翻译自: https://www.includehelp.com/python/smoothen-a-grayscale-image-by-performing-blurring-operation-using-user-defined-median-blur-filter.aspx

苹果模糊滤镜

发表评论

表情:
评论列表 (有 0 条评论,28人围观)

还没有评论,来说两句吧...

相关阅读

    相关 【Photoshop】详解

    一、抽出:抽出命令为隔离前景对象并抹除它在图层上的背景提供了一种高级方法。 二、液化:液化命令可用于通过交互方式拼凑、推、拉、旋转、折叠和膨胀图像的任意选区。 三

    相关 ,如此简单

      图像处理中,滤镜是一个很常用的处理方法。今天我将带领大家一起走进图片滤镜的世界,其实,滤镜是如此的简单。先看看我们今天要实现的几个效果图对比吧: <table> <t

    相关 css 属性

    CSS3中强大的filter(滤镜)属性 博主最近在做网站的过程中发现了一个非常强大的CSS3属性,就是filter(滤镜)属性,喜欢p图的朋友看名字都应该知道这是什么神器了