在PHP中是否存在逐像素处理图像的快速方法 [英] Is there a fast way of pixel-by-pixel proceccing images in PHP

查看:130
本文介绍了在PHP中是否存在逐像素处理图像的快速方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PHP中使用我自己的algotirhm图像。
算法逐个像素地放置三个输入图像(所有相同大小的图像)并在输出图像中设置像素:

I apply my own algotirhm on images in PHP. The algorithm goes on three input images pixel by pixel (all images of the same size) and sets the pixel in the output image:

for ($x = 0; $x < $width; $x++)
{
  for ($y = 0; $y < $height; $y++)
  {
    $color1 = imagecolorat ($image1, $x, $y);
    $color2 = imagecolorat ($image2, $x, $y);
    $color3 = imagecolorat ($image3, $x, $y);

    $color4 = my_function ($color1, $color2, $color3);

    imagesetpixel ($image4, $x, $y, $color4);
   }
}

问题是这对于大图像来说真的很慢,因为PHP是一种解释型语言。

The problem is that this is really slow for large images, because of PHP being an interpreted language.

PHP中有一些特殊的方法可以有效地为数组的所有成员调用一个函数,如:array_map,array_filter,array_reduce, array_walk。

There are special methods in PHP which allow efficiently call a function for all members of array, like: array_map, array_filter, array_reduce, array_walk.

是否有类似的图像方法,即为一个(或几个)图像的所有像素调用一些函数?

Are there similar methods for images, i.e. call some function for all pixels of one (or several) images?

或许有一种方法可以在PHP中以图像的形式访问图像?

Or maybe there is a way to access image as an array in PHP?

提前感谢...

推荐答案


PHP中有一些特殊的方法可以有效地为数组的所有成员调用一个函数

There are special methods in PHP which allow efficiently call a function for all members of array

我担心这个陈述你错了。

这些函数效率不高。

You are wrong with this statement, I am afraid.
These functions aren't that efficient.

无论如何,没有 - GD库没有类似的功能。

Anyway, no - there are no similar functions for the GD library.

你可以在google上搜索一些像素访问库 - 我相信可能已经写了一些。

You can search google for some pixel access library - there may be some already written, I believe.

这篇关于在PHP中是否存在逐像素处理图像的快速方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆