Page 1 of 1

Why use point, the processing speed is so slowly

Posted: 2014-08-19T21:54:33-07:00
by webwudi
i use imagick function point in PHP write a code to operate pixel to change image brightness.
but the processing speed surprisingly slow ! Need several minutes to estimate ! Just like the browser collapsed !

but if use imagick to resize image or add Text on image ... and so on
these common functions are very quickly !

i don't know why ? please help me !!!!!!!!!!!!!!
----------------------------------------------------------------------------------------------------------------------
<?php
$im = new Imagick($src);
$imgSize = $im->getImageGeometry();
$w = $imgSize["width"];
$h = $imgSize["height"];

$image = new Imagick($src);
$image->newImage($w, $h, "transparent");
$draw = new ImagickDraw();

for($y=0; $y<50; $y++){
for($x=0; $x<$w; $x++) {
$p = $im->getImagePixelColor($x, $y);
//i deleted the code for change brightness for the code looks shortly
$draw->setFillColor($p);
$draw->point($x, $y); //use point to redraw image Pixel
}
}

$image->drawImage($draw);

$image->setImageFormat('jpeg');
header('Content-type: image/jpeg');
echo $image;
destroy($image);
?>

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-19T22:02:25-07:00
by snibgo
Using any interpreted language to loop through all the pixels, one by one, will be slow. For interpreted languages, always use a higher-level process that acts on the entire image in a single command.

If you must do processing pixel-by-pixel, use a compiled language.

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-19T22:14:25-07:00
by webwudi
snibgo wrote:If you must do processing pixel-by-pixel, use a compiled language.
Thanks snibgo :) I have a little understand
but my programming technology is little superficial hehe

so how should I do in the PHP procedure ,
is use of PHP function to call ImagickMagick command line In order to realize this goal ? ????

can U give some suggestions ?
thanks thanks thanks

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-19T22:28:54-07:00
by fmw42
I am not much of a programmer, but it looks like all you are doing is cropping a subsection from an image and making it into a new image.

see
http://us3.php.net/manual/en/imagick.cropimage.php

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-19T23:16:15-07:00
by webwudi
fmw42 wrote:to fmw42 Not the corpImage
My thoughts was pixel-to-pixel rewrite a image ,
Although it looks like the corpImage , but it could change any pixels color !

snibgo tould : use a compiled language. i think he is right ! hehe
i just don't know how to use in PHP code ??

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T09:25:13-07:00
by fmw42
The whole point of Imagemagick is to avoid your having to process pixel-by-pixel on your own. Imagemagick has compiled code to do most of the things you want to do to process images. So they take care of the pixel-to-pixel processing. You just have to find the right method to do what you want.

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T16:42:19-07:00
by snibgo
I think webwudi wants to apply change the brightness of pixels within a certain rectangle (the entire image width, but just the first 50 lines). For example, at the command line (Windows BAT syntax):

Code: Select all

convert ^
  in.png ^
  -region x50 ^
  -brightness-contrast 30 ^
  out.png
I don't know how to do this in PHP.

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T16:49:02-07:00
by fmw42
As far as I know (though I am not an Imagick expert), Imagick has no equivalent to -region or -brightness-contrast. However, the something like the latter can be achieved by using either http://us3.php.net/manual/en/imagick.levelimage.php or http://us3.php.net/manual/en/imagick.si ... timage.php. To work on a subsection, one would have to use http://us3.php.net/manual/en/imagick.cropimage.php, then use one either levelImage or sigmoidalcontrastImage to make the brightness contrast adjustments, the composite the modified subsection back into the original to make the output using http://us3.php.net/manual/en/imagick.compositeimage.php

Note that Imagick is not as well supported, nor as fully functional as Imagemagick. So you may want to just use PHP exec() to run Imagemagick commands such as the one provided by user snibgo.

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T20:21:50-07:00
by webwudi
snibgo wrote:to snibgo :
ThankS although I know this comand !~

perhaps my thoughts was strange,
But if U think :
if U don't want change the whole image brightness but just only want change a local of the image brightness !!!

In this case, you cannot use a simple command to realize it
:?

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T20:31:05-07:00
by fmw42
snibgo's command allows you to change the brightness only is a small rectangular region. Imagemagick has other masking operations to do it in an irregular region.

Re: Why use point, the processing speed is so slowly

Posted: 2014-08-20T21:32:19-07:00
by snibgo
As Fred says, use a mask. Examples, where m.png is black/white mask:

Code: Select all

convert ^
  in.png ^
  -mask m.png ^
  -brightness-contrast 50 ^
  +mask ^
  bm.png

convert ^
  in.png ^
  -mask m.png ^
  +level 90%%,100%% ^
  +mask ^
  bm2.png

convert ^
  in.png ^
  ( +clone ^
    +level 90%%,100%% ^
  ) ^
  +swap ^
  m.png ^
  -composite ^
  bm3.png