📜  Mahotas – 获取每个像素的不聚焦

📅  最后修改于: 2022-05-13 01:54:43.341000             🧑  作者: Mango

Mahotas – 获取每个像素的不聚焦

在本文中,我们将了解如何获得 mahotas 中每个像素的不聚焦。为了得到每个像素的不聚焦,我们将使用 sobel运算符。 Sobel运算符,有时称为 Sobel-Feldman运算符或 Sobel 滤波器,用于图像处理和计算机视觉,特别是在边缘检测算法中,它创建强调边缘的图像。

在本教程中,我们将使用“lena”图像,下面是加载它的命令。

mahotas.demos.load('lena')

下面是莉娜的图片

下面是实现

Python3
# importing required libraries
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
  
# loading image
img = mahotas.demos.load('lena')
 
# showing image
print("Image")
imshow(img)
show()
 
# getting infocusness of each pixel
focus = np.array([mahotas.sobel(t, just_filter = True) for t in img])
 
# showing focus pixel
print("Focus Image")
imshow(focus)
show()


Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
  
# loading image
img = mahotas.imread('dog_image.png')
       
# filtering image
img = img[:, :, :3]
 
# showing image
print("Image")
imshow(img)
show()
 
# getting infocusness of each pixel
focus = np.array([mahotas.sobel(t, just_filter = True) for t in img])
 
# showing focus pixel
print("Foucs Image")
imshow(focus)
show()


输出 :

Image

Focus Image

另一个例子

Python3

# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
  
# loading image
img = mahotas.imread('dog_image.png')
       
# filtering image
img = img[:, :, :3]
 
# showing image
print("Image")
imshow(img)
show()
 
# getting infocusness of each pixel
focus = np.array([mahotas.sobel(t, just_filter = True) for t in img])
 
# showing focus pixel
print("Foucs Image")
imshow(focus)
show()

输出 :

Image 

Focus Image