Page 1 of 1
RESOLVED Dithering with Symbol Patterns (FX)
Posted: 2009-10-30T07:40:48-07:00
by resoai
I'm trying to reproduce the example from
http://www.smileygenerator.us/imagick6/ ... index.html
i.e. Dithering with Symbol Patterns
The following command works from the command line:
Code: Select all
convert eyes.gif +matte -colorspace Gray -scale 1600% -negate \
dpat_symbols.gif -virtual-pixel tile -fx 'u[floor(16*u)+1]' \
eyes_syms.gif
Reproduce code:
---------------
Code: Select all
<?
$img=new Imagick();
$img->readImage('eyes.gif');
$img->setImageColorspace(Imagick::COLORSPACE_GRAY);
$img->setImageMatte(true);
$img->scaleImage(288,288);
$img->negateImage(false);
$src=new Imagick();
$src->readImage('dpat_symbols.gif');
$src->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TILE);
$img->addImage($src);
$img=$img->fxImage("u[floor(15.9999*u)+1]");
header("Content-type: image/jpeg");
echo $img;
?>
Expected result:
----------------
This should produce something like this:
http://www.smileygenerator.us/imagick6/ ... s_syms.gif
but only one image from gif sequence i.e. 16x16px is shown.
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-24T16:41:28-07:00
by resoai
Anyone?
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-24T18:37:56-07:00
by fmw42
The following command works from the command line:
convert eyes.gif +matte -colorspace Gray -scale 1600% -negate \
dpat_symbols.gif -virtual-pixel tile -fx 'u[floor(16*u)+1]' \
eyes_syms.gif
Reproduce code:
---------------
CODE: SELECT ALL
<?
$img=new Imagick();
$img->readImage('eyes.gif');
$img->setImageColorspace(Imagick::COLORSPACE_GRAY);
$img->setImageMatte(true);
$img->scaleImage(288,288);
$img->negateImage(false);
$src=new Imagick();
$src->readImage('dpat_symbols.gif');
$src->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TILE);
$img->addImage($src);
$img=$img->fxImage("u[floor(15.9999*u)+1]");
header("Content-type: image/jpeg");
echo $img;
?>
I am no expert on Imagick, but it looks to me like you have some of the commands backwards.
1) put your matte command before colorspace to emulate the command line
2) +matte disables the matte channel, (-matte enables it). however, in IMagick you are enabling it with "true"
3) -negate reverses the grayscale, but in Imagick you have $img->negateImage(false); which I would take to mean disable or not negate
check your Imagick commands at
http://us3.php.net/manual/en/book.imagick.php
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-24T19:34:26-07:00
by el_supremo
I've been trying to replicate that command using C and MagickWand (I don't use IMagick) but I'm also not having any luck.
I've attached an edited version of my code . The image produced immediately after the Negate is the same as that of the command line version but the result of the FX is not even close.
Pete
Code: Select all
mw = NewMagickWand();
MagickReadImage(mw,"eyes.gif");
// +matte
MagickSetImageAlphaChannel(mw,DeactivateAlphaChannel);
// -colorspace Gray
// NOTE setImageColorspace doesn't seem to do anything
// so use these two functions instead
MagickSetImageType(mw, GrayscaleType);
MagickQuantizeImage(mw, 16, GRAYColorspace, 0 , 0, 0);
// -scale 1600%
w = (int)MagickGetImageWidth(mw);
h = (int)MagickGetImageHeight(mw);
MagickScaleImage(mw,w*16,h*16);
// -negate
MagickNegateImage(mw,MagickFalse);
MagickReadImage(mw,"dpat_symbols.gif");
// -virtual-pixel tile
MagickSetImageVirtualPixelMethod(mw,TileVirtualPixelMethod);
// -fx 'u[floor(16*u)+1]'
mwfx = MagickFxImage(mw,"u[floor(16*u)+1]");
/* Write the image */
MagickWriteImage(mwfx,"eyes_syms.gif");
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-25T15:11:13-07:00
by el_supremo
@resoai: Which version of IM are you using and is it configured for HDRI?
Pete
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-25T20:38:33-07:00
by el_supremo
See the reply from Magick in
viewtopic.php?f=3&t=16925.
You have to set the virtual pixel method in every image.
Pete
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-08-25T20:43:28-07:00
by el_supremo
Thanks Magick. That fixed up the first example.
But the second example didn't use virtual pixel method. I tried it anyway but it didn't make any difference. The colours are still in the wrong order compared to the command line.
Pete
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-09-07T05:18:02-07:00
by resoai
@ el_supremo Thank, I will try setting virtual pixel now. I am using ImageMagick 6.5.8-10 2010-03-10 Q16
Re: Dithering with Symbol Patterns (FX)
Posted: 2010-09-07T11:46:37-07:00
by resoai
Thanks, it worked!
Code: Select all
<?
$img = new Imagick();
$img->readImage('eyes.gif');
$img->setImageMatte(false);
$img->setImageType(Imagick::IMGTYPE_GRAYSCALE);
$img->scaleImage(288, 288);
$img->negateImage(false);
$img->readImage('dpat_symbols.gif');
$img_count = $img->getNumberImages();
for ($i = 1; $i < $img_count; $i++)
{
$img->setIteratorIndex($i);
$img->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TILE);
}
$img->setIteratorIndex(0);
$img = $img->fxImage("u[floor(15.9999*u)+1]");
header("Content-type: image/jpeg");
echo $img;
?>
Re: RESOLVED Dithering with Symbol Patterns (FX)
Posted: 2010-09-16T20:49:31-07:00
by anthony
WARNING: that copy of IM Examples, has not been updated in a very long time.
The version number at the bottom of the page is IM 6.2.9 and dated from 2006!
however the dithering example has not changed so should work as expected.
Nice to see someone making use of that technique.