Mahotas – RGB 到棕褐色的转换
在本文中,我们将了解如何将 rgb 图像转换为 mahotas 中的棕褐色图像。 RGB 图像(有时称为真彩色图像)作为 m×n×3 数据数组存储在 MATLAB 中,该数组定义了每个像素的红色、绿色和蓝色分量。棕褐色调效果在摄影中非常常用。它是改变灰度图像的每个像素颜色的强度的过程,也就是所谓的黑白。
在本教程中,我们将使用“lena”图像,下面是加载它的命令。
mahotas.demos.load('lena')
下面是莉娜的图片
为此,我们将使用 mahotas.colors.rgb2sepiamethod
Syntax : mahotas.colors.rgb2sepia(img)
Argument :It takes image object as argument
Return : It returns image object
下面是实现
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()
# rgb to sepia
new_img = mahotas.colors.rgb2sepia(img)
# showing new image
print("New Image")
imshow(new_img)
show()
Python3
# importing required libraries
import mahotas
import numpy as np
import matplotlib.pyplot as plt
import os
# loading image
img = mahotas.imread('dog_image.png')
# filtering image
img = img[:, :, :3]
# showing image
print("Image")
imshow(img)
show()
# rgb to sepia
new_img = mahotas.colors.rgb2sepia(img)
# showing new image
print("New Image")
imshow(new_img)
show()
输出 :
Image
New Image
另一个例子
Python3
# importing required libraries
import mahotas
import numpy as np
import matplotlib.pyplot as plt
import os
# loading image
img = mahotas.imread('dog_image.png')
# filtering image
img = img[:, :, :3]
# showing image
print("Image")
imshow(img)
show()
# rgb to sepia
new_img = mahotas.colors.rgb2sepia(img)
# showing new image
print("New Image")
imshow(new_img)
show()
输出 :
Image
New Image