如何使用 imageconvolution() 在 PHP 中應用 3×3 卷積矩陣?
imageconvolution() 是 PHP 中的一個內建函式,用於應用 3×3 卷積矩陣,使用影像中的係數和偏移量。
語法
bool imageconvolution ( $image, $matrix, $div, $offset)
引數
imageconvolution() 接受四個引數:$image、$matrix、$div 和 $offset。
$image − 此引數用於使用影像建立函式(例如 imagecreatetruecolor())建立影像大小。
$matrix − 此引數包含一個 3×3 浮點陣列矩陣。
$div − 用於歸一化。
$offset − 此引數用於設定顏色偏移量。
返回值
如果成功,imageconvolution() 返回 True;如果失敗,則返回 False。
示例 1
<?php // load the PNG image by using imagecreatefrompng function. $image = imagecreatefrompng('C:\xampp\htdocs\Images\img59.png'); // Applied the 3X3 array matrix $matrix = array( array(2, 0, 0), array(0, -1, 0), array(0, 0, -1) ); // imageconvolution function to modify image elements imageconvolution($image, $matrix, 1, 127); // show the output image in the browser header('Content-Type: image/png'); imagepng($image, null, 9); ?>
輸出
在使用 imageconvolution() 函式之前輸入的 PNG 影像
.png)
使用 imageconvolution() 函式後輸出的 PNG 影像
.jpg)
示例 2
<?php $image = imagecreatetruecolor(700, 300); // Writes the text and apply a gaussian blur on the image imagestring($image, 50, 25, 8, 'Gaussian Blur Text image', 0x00ff00); $gaussian = array( array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0) ); imageconvolution($image, $gaussian, 16, 0); // Rewrites the text for comparison imagestring($image, 15, 20, 18, 'Gaussian Blur Text image', 0x00ff00); header('Content-Type: image/png'); imagepng($image, null, 9); ?>
輸出
.jpg)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP