以编程方式执行Photoshop的“Luminosity”过滤器

时间:2022-07-26 00:23:00

I have two JPEG's and would like to overlay one on the other with the same results as the "Luminosity" mode available in Photoshop (and Fireworks). You can read more about Luminosity mode here: http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode

我有两个JPEG,并希望将一个叠加在另一个上,其结果与Photoshop(和Fireworks)中提供的“亮度”模式相同。您可以在此处阅读有关亮度模式的更多信息:http://www.adobetutorialz.com/articles/662/1/Photoshop%92s-Luminosity-Mode

How can I do this? Programming language doesn't matter much, but I am most fluent with Python and PHP (in that order). Python Imaging Library seems like a perfect fit, but luminosity is not a built-in function and I do not know the proper procedure. See http://effbot.org/imagingbook/imagechops.htm

我怎样才能做到这一点?编程语言并不重要,但我最熟悉Python和PHP(按此顺序)。 Python Imaging Library看起来非常合适,但是光度不是内置函数,我不知道正确的程序。见http://effbot.org/imagingbook/imagechops.htm

5 个解决方案

#1


I don't know about this specific filter but I can tell you how to follow Coincoin steps in PIL. I didn't actually run the code, but you can use it as a reference:

我不知道这个特定的过滤器,但我可以告诉你如何遵循PIL中的Coincoin步骤。我实际上没有运行代码,但您可以将其用作参考:

Load both the source and target JPEGs

加载源和目标JPEG

from PIL import Image
img1 = Image.open('image1.jpg')
img2 = Image.open('image2.jpg')

Convert the pixels from RGB color space to Lab color space (or any other color space with luminosirty information)

将像素从RGB颜色空间转换为Lab颜色空间(或具有luminosirty信息的任何其他颜色空间)

# Color matrix for Lab
colorMatrix = (
    x1, y1, z1, 0,
    x2, y2, z2, 0,
    x3, y3, z3, 0
)
img1 = img1.convert("RGB", colorMatrix)
img2 = img2.convert("RGB", colorMatrix)

Preserve target color channels and replace its luminosity channel by source's luminosity

保留目标颜色通道并根据光源的亮度替换其亮度通道

l1, a1, b1 = img1.split()
l2, a2, b2 = img2.split()
img1.putdata(zip(l1.getdata(), a2.getdata(), b2.getdata()))

Convert back to RGB space

转换回RGB空间

# Color matrix for RGB
RGBcolorMatrix = (
    x1, y1, z1, 0,
    x2, y2, z2, 0,
    x3, y3, z3, 0
)
img1 = img1.convert("RGB", RGBcolorMatrix)

Save the JPEG

保存JPEG

img1.save('new_image.jpg')

#2


First you need to understand what Photoshop does.

首先,您需要了解Photoshop的功能。

It preserves under layer perceptual color information and replaces it's luminosity with the top layer's perceptual luminosity information. To do that, you need to convert the images to the right color space.

它保留了层下的感知颜色信息,并用顶层的感知光度信息替换它的亮度。为此,您需要将图像转换为正确的颜色空间。

Here is the shoping list of things you will need to do if you decide to implement everything by yourself:

以下是您决定自己实施所有内容时需要做的购物清单:

  • Load both the source and target JPEGs
  • 加载源和目标JPEG

  • Convert the pixels from RGB color space to Lab color space (or any other color space with luminosirty information)
  • 将像素从RGB颜色空间转换为Lab颜色空间(或具有luminosirty信息的任何其他颜色空间)

  • Preserve target color channels and replace its luminosity channel by source's luminosity
  • 保留目标颜色通道并根据光源的亮度替换其亮度通道

  • Convert back to RGB space
  • 转换回RGB空间

  • Save the JPEG
  • 保存JPEG

If you think Lab is too complicated, you can also use HSL color space, it's much simpler but it will give inferior results.

如果您认为Lab过于复杂,您也可以使用HSL色彩空间,它会更简单,但会产生较差的结果。

#3


In pseudo-code:

foreach rgb_pixel1, rgb_pixel2 in image1, image2 {
    hsl1 = RgbToHsl(rgb_pixel1);
    hsl2 = RgbToHsl(rgb_pixel2);
    hsl3 = hsl(hsl1.h, hsl1.s, hsl2.l);
    output_rgb = HslToRgb(hsl3);
}

Conversion from rgb to hsl and back is here.

从rgb到hsl和back的转换就在这里。

#4


The Gimp would be another option - it has a scripting interface ans a python api - here is an article on luminosity and the Gimp. Not sure if it is the same effect you are going for though.

Gimp将是另一种选择 - 它有一个脚本接口和一个python api - 这是一篇关于发光度和Gimp的文章。不确定它是否与你想要的效果相同。

#5


You could have a look at the OpenCV image processing library. It has Python bindings and handles a lot of these lower level image manipulation tasks for you, or at least makes them easier.

您可以查看OpenCV图像处理库。它具有Python绑定并为您处理许多这些较低级别的图像处理任务,或者至少使它们更容易。

#1


I don't know about this specific filter but I can tell you how to follow Coincoin steps in PIL. I didn't actually run the code, but you can use it as a reference:

我不知道这个特定的过滤器,但我可以告诉你如何遵循PIL中的Coincoin步骤。我实际上没有运行代码,但您可以将其用作参考:

Load both the source and target JPEGs

加载源和目标JPEG

from PIL import Image
img1 = Image.open('image1.jpg')
img2 = Image.open('image2.jpg')

Convert the pixels from RGB color space to Lab color space (or any other color space with luminosirty information)

将像素从RGB颜色空间转换为Lab颜色空间(或具有luminosirty信息的任何其他颜色空间)

# Color matrix for Lab
colorMatrix = (
    x1, y1, z1, 0,
    x2, y2, z2, 0,
    x3, y3, z3, 0
)
img1 = img1.convert("RGB", colorMatrix)
img2 = img2.convert("RGB", colorMatrix)

Preserve target color channels and replace its luminosity channel by source's luminosity

保留目标颜色通道并根据光源的亮度替换其亮度通道

l1, a1, b1 = img1.split()
l2, a2, b2 = img2.split()
img1.putdata(zip(l1.getdata(), a2.getdata(), b2.getdata()))

Convert back to RGB space

转换回RGB空间

# Color matrix for RGB
RGBcolorMatrix = (
    x1, y1, z1, 0,
    x2, y2, z2, 0,
    x3, y3, z3, 0
)
img1 = img1.convert("RGB", RGBcolorMatrix)

Save the JPEG

保存JPEG

img1.save('new_image.jpg')

#2


First you need to understand what Photoshop does.

首先,您需要了解Photoshop的功能。

It preserves under layer perceptual color information and replaces it's luminosity with the top layer's perceptual luminosity information. To do that, you need to convert the images to the right color space.

它保留了层下的感知颜色信息,并用顶层的感知光度信息替换它的亮度。为此,您需要将图像转换为正确的颜色空间。

Here is the shoping list of things you will need to do if you decide to implement everything by yourself:

以下是您决定自己实施所有内容时需要做的购物清单:

  • Load both the source and target JPEGs
  • 加载源和目标JPEG

  • Convert the pixels from RGB color space to Lab color space (or any other color space with luminosirty information)
  • 将像素从RGB颜色空间转换为Lab颜色空间(或具有luminosirty信息的任何其他颜色空间)

  • Preserve target color channels and replace its luminosity channel by source's luminosity
  • 保留目标颜色通道并根据光源的亮度替换其亮度通道

  • Convert back to RGB space
  • 转换回RGB空间

  • Save the JPEG
  • 保存JPEG

If you think Lab is too complicated, you can also use HSL color space, it's much simpler but it will give inferior results.

如果您认为Lab过于复杂,您也可以使用HSL色彩空间,它会更简单,但会产生较差的结果。

#3


In pseudo-code:

foreach rgb_pixel1, rgb_pixel2 in image1, image2 {
    hsl1 = RgbToHsl(rgb_pixel1);
    hsl2 = RgbToHsl(rgb_pixel2);
    hsl3 = hsl(hsl1.h, hsl1.s, hsl2.l);
    output_rgb = HslToRgb(hsl3);
}

Conversion from rgb to hsl and back is here.

从rgb到hsl和back的转换就在这里。

#4


The Gimp would be another option - it has a scripting interface ans a python api - here is an article on luminosity and the Gimp. Not sure if it is the same effect you are going for though.

Gimp将是另一种选择 - 它有一个脚本接口和一个python api - 这是一篇关于发光度和Gimp的文章。不确定它是否与你想要的效果相同。

#5


You could have a look at the OpenCV image processing library. It has Python bindings and handles a lot of these lower level image manipulation tasks for you, or at least makes them easier.

您可以查看OpenCV图像处理库。它具有Python绑定并为您处理许多这些较低级别的图像处理任务,或者至少使它们更容易。