note 87965 added to function.imageconvolution
| From: | php at pulseforce dot com | Date: | Fri, 02 Jan 2009 23:04:45 +0000 |
| Subject: | note 87965 added to function.imageconvolution | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148769@lists.php.net to get a copy of this message | ||
Here is something that you will find extremely handy while beta testing your convolution filters.
It's very time consuming to have something like:
$aFilter = array(
array(-1, 2, -1),
array(2, 4, 2),
array(-1, 2, -1)
);
Because every time you're making a change you have to jump around a lot, and are forced to be
careful with your edits to avoid destroying the array format (such as accidentally deleting a
parenthesis or comma). That's not fun at all and very counter productive. Wouldn't it be
good if you could just type the matrix out in text form and separate the entries with either spaces
or tabs or newlines? Ie any of the following:
-1 2 -1
2 4 2
-1 2 -1
or
-1
2
-1
2
4
2
-1
2
-1
Well, now you can! I'd like to emphasis that you should only use this function for development
purposes, while trying out different convolution matrices! And without further ado:
<?php
function convFilter($saFilter)
{
$aParts = preg_split('/\s+/s', $saFilter, -1, PREG_SPLIT_NO_EMPTY);
if (count($aParts) != 9) { return false; }
$aMatrix = array_chunk($aParts, 3);
return $aMatrix;
}
// Usage:
$aFilter = convFilter("
1.0 2.0 1.0
2.0 4.0 2.0
1.0 2.0 1.0
");
imageconvolution($rImg, $aFilter, 16, 0);
?>
Enjoy! You can now type your matrices out in any way you want (even floats), as long as any form of
whitespace separates the various numbers. Once you are done testing, just type the matrix out as a
normal array to save on processing time.
And please post your convolution filters if you come up with some useful ones so they can be
implemented by others. ;-)
----
Server IP: 80.67.2.2
Probable Submitter: 217.73.106.170
----
Manual Page -- http://www.php.net/manual/en/function.imageconvolution.php
Edit -- https://master.php.net/note/edit/87965
Del: integrated -- https://master.php.net/note/delete/87965/integrated
Del: useless -- https://master.php.net/note/delete/87965/useless
Del: bad code -- https://master.php.net/note/delete/87965/bad+code
Del: spam -- https://master.php.net/note/delete/87965/spam
Del: non-english -- https://master.php.net/note/delete/87965/non-english
Del: in docs -- https://master.php.net/note/delete/87965/in+docs
Del: other reasons-- https://master.php.net/note/delete/87965
Reject -- https://master.php.net/note/reject/87965
Search -- https://master.php.net/manage/user-notes.php