RESOLVED Dithering with Symbol Patterns (FX)

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
resoai

RESOLVED Dithering with Symbol Patterns (FX)

Post 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.
Last edited by resoai on 2010-09-07T11:47:23-07:00, edited 1 time in total.
resoai

Re: Dithering with Symbol Patterns (FX)

Post by resoai »

Anyone?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Dithering with Symbol Patterns (FX)

Post 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
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Dithering with Symbol Patterns (FX)

Post 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");
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Dithering with Symbol Patterns (FX)

Post by el_supremo »

@resoai: Which version of IM are you using and is it configured for HDRI?

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Dithering with Symbol Patterns (FX)

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Dithering with Symbol Patterns (FX)

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
resoai

Re: Dithering with Symbol Patterns (FX)

Post by resoai »

@ el_supremo Thank, I will try setting virtual pixel now. I am using ImageMagick 6.5.8-10 2010-03-10 Q16
resoai

Re: Dithering with Symbol Patterns (FX)

Post 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;

?>
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: RESOLVED Dithering with Symbol Patterns (FX)

Post by anthony »

resoai wrote:I'm trying to reproduce the example from
http://www.smileygenerator.us/imagick6/ ... index.html
i.e. Dithering with Symbol Patterns
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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply