Dithering with symbol patterns

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mozz
Posts: 2
Joined: 2013-01-10T07:53:36-07:00
Authentication code: 6789

Dithering with symbol patterns

Post by mozz »

Hello,

I am investigating the Dithering with symbol patterns example.
It doesn't work for me. Could someone explain a bit more the fx function: 'u[floor(15.9999*u)+1]'

Here is what I get at the moment :
Image

I am using IM 6.8.1 if this matters.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Dithering with symbol patterns

Post by anthony »

Note the example was updated recently to correctly deal with colorspace issues.


You need to use the multi-image GIF file for the symbols to tile, and not the single image montage of those images which is purely for display purposes.

Code: Select all

 'u[floor(15.9999*u)+1]'
In memory is 17 seperate images. The enlarged image (grayscale squares) of the image to be tiled, and 16 small tiling image which are all the same size as the greyscale squares.

u[...] selects an image from whcih to get a pixel.
The pixel location is at the same position as the pixel it is replacing in the first (zeroth) greyscale tile image.
That location uses the tiled virtual-pixel so even though the location is beyond the bounds of the smaller tiling images, a valid 'tiled' pixel is retrieved.
The floor(15.9999*u)+1 selects the tileing image. +1 to skip the first or 'zero' image,
It is based on the value of the source image color (u)

So at some particular location, i,j somewhere in the source image, (and for each of the color channels, os essectually the whole pixel). the greyscale value 'u' is extracted from the first image. This is then used to 'index' one of the tile images, and from that image u[index] the pixel value is transferred to the output image replacing the original greyscale value.


The Previous examples on dithering used similar techniques, but looking up from a set of images that were progressive 'whiter' in color. In this case the images are symbols that are only roughly 'lighter' in color.

Remember 'u' means the first image 'v' means the second image and 'u[x]' means the x image (starting at zero). As such u is equivalent to u[0] and v is equivalent to u[1]
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
mozz
Posts: 2
Joined: 2013-01-10T07:53:36-07:00
Authentication code: 6789

Re: Dithering with symbol patterns

Post by mozz »

Hello again,

I found out my mistake - I was not using the correct animated gif.

I have couple of other questions now :)
1) Is it possible to determine which color is swapped with which image from the animated gif? For example is it true that the pixel at 1,1 is swapped with the 1st image from the gif, then the next different color pixel is swapped with the second one etc.?
2) What will happen if the image to be converted has 20 different colors and the animated gif consists of 30 images? What should be the floor number in the fx function in this case?

Thank you for your help!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Dithering with symbol patterns

Post by anthony »

Which image is based on the grayscale level. the formula should (nearly) evenly and linearly distribute the range across all the images provided.

So if the replacement pixel is to come from say image 3, the pixel in image 3 than is used is equivalent to the pixel that would be overlaid if image 3 was tiled over the whole input image.

the top left corner is just a firect 1:1 position selection. beyond that it is the -virtual-pixel tile setting that defines what pixel from image 3 is used. You could for example 'mirror tile' the dither images, instead.

You can of course add include a position formula to the FX expression. for example...

Code: Select all

'u[floor(15.9999*u)+1].p{-i,j}'
will cause the tiling images to be horizontally flipped when copied!
Or you can generate formulas to 'roll' the tile pattern, or just select a specific pixel of the tile patterns.

This is the point of FX.. it is the 'Do It Yourself' operator, that can be used to do just about any operation you can think of (abet more slowly).
See IM Examples, Image Transforms... Using FX, The DIY Image Operator
http://www.imagemagick.org/Usage/transform/#fx
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply