Page 1 of 1

How to add unsharp mask to this code?

Posted: 2016-12-16T10:30:20-07:00
by Amin Sabet
I am using a forum software called Xenforo, which resizes images using Imagick.

If the code says:

Code: Select all

foreach ($this->_image AS $frame)
			{
				$frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9, true);  // keep EXIF
				$frame->setImagePage($frame->getImageWidth(), $frame->getImageHeight(), 0, 0);
			}
and later in the code this:

Code: Select all

if ($scaleUp)
   {
       $frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9, true);
   }
   else if ($oldImagick)
   {
       $frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9, true);  // keep EXIF
   }
   else
   {
       $frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9, true);   // higher-quality scaling + EXIF retained
   }
   $frame->setImagePage($width, $height, 0, 0);
}
How can I add a little unsharp mask to those resize operations?

Re: How to add unsharp mask to this code?

Posted: 2016-12-16T10:58:39-07:00
by Bonzo
It is interesting that all four resize options do exactly the same thing.

I do not use Imagick but would try adding this line below the $frame->resizeImage( option you are using:

$frame->unsharpMaskImage(0 , 0.5 , 1 , 0.05);

Re: How to add unsharp mask to this code?

Posted: 2016-12-16T13:12:02-07:00
by Amin Sabet
In the default Xenforo code, the resize options does different things:

Code: Select all

foreach ($this->_image AS $frame)
{
   if ($scaleUp)
   {
      $frame->resizeImage($width, $height, Imagick::FILTER_QUADRATIC, .5, true);
   }
   else if ($oldImagick)
   {
      $frame->thumbnailImage($width, $height, true);
   }
   else
   {
      $frame->thumbnailImage($width, $height, true, true);
   }
   $frame->setImagePage($width, $height, 0, 0);
}
I changed them to do the same thing because I didn't want them to strip out EXIF. I suppose I could have taken out the if / else stuff and just written it once :).

Thanks for your help, I will try what you wrote.

Re: How to add unsharp mask to this code?

Posted: 2016-12-16T13:24:25-07:00
by Amin Sabet
So this is what I put:

Code: Select all

foreach ($this->_image AS $frame)
			{
				$frame->resizeImage($width, $height, Imagick::FILTER_LANCZOS, 0.9, true);
				$frame->unsharpMaskImage(0 , 0.5 , 1 , 0.05);
				$frame->setImagePage($frame->getImageWidth(), $frame->getImageHeight(), 0, 0);
But as far as I can tell there is no difference in sharpening being applied.

Re: How to add unsharp mask to this code?

Posted: 2016-12-16T13:34:09-07:00
by snibgo
0.5 is a small amount of unsharpening. A larger number like 5 is more obvious.