在python/django中灰度的最佳方法是什么? [英] What's the best way to greyscale in python/django?
问题描述
我想对要上传到django中的图像进行灰度处理.因此,我找到了两种方法,opencv或imagemagick.在imagemagick中,imagemagickWand可能会更好,因为它已减少.
I want to greyscale my images that will be uploaded into django. So I found two ways, either opencv or imagemagick. And within imagemagick, imagemagickWand might be better because it's reduced.
从教程中,我认为openCV易于实现.
From the tutorials I think openCV is easier to implement.
有什么想法吗?
推荐答案
在python/django中进行灰度处理的最佳方法是什么?
What's the best way to greyscale in python/django?
选择.
ImageMagick的魔杖库
ImageMagick's wand library
from wand.image import Image
with Image(filename='logo:') as img:
img.colorspace = 'gray'
img.save(filename='logo_gray.jpg')
或CV2
import cv2
img = cv2.imread('example.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imwrite('example_gray.jpg',gray)
这两个项目都很成熟,稳定,并且拥有庞大的社区基础.尝试安装两个库,然后进行试验.
Both projects are mature, stable, and have a large community base. Try installing both libraries, and experimenting.
最后,灰度只是(来自维基百科).
In the end grayscale is just (from wikipedia).
Y = 0.2126 * RED + 0.7152 * GREEN + 0.0722 * BLUE
两者都做得很好,并依赖委托(即libjpeg)来读取&编写图像格式.
Both do this well, and depend on delegates (i.e. libjpeg) to read & write image formats.
这篇关于在python/django中灰度的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!