Stained Glass effect using average color

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
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Stained Glass effect using average color

Post by josephs »

Hi all,

Can anyone give me some guidance (or lead me in right direction) on how Fred's stain glass script could be modified so that cell color uses average color of cell and not point sample? This script is amazing but I need more accurate color representation for my purposes.

I am referring to this: http://www.fmwconcepts.com/imagemagick/ ... /index.php

I appreciate any help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stained Glass effect using average color

Post by fmw42 »

As an approximation, just blur the input image with a square size uniformly weighted convolution (-morphology convolve WxH:1 1 1 1 .....) or with a circular shaped uniformly weighted blur (-blur radx65000). For example,

Input:
Image

# default size is 16
stainedglass -r 100 -k random -b 150 -t 1 -r 56 birdofparadise.gif birdofparadise_sg.png
Image

#circular blur of radius=8
convert birdofparadise.gif -blur 8x65000 birdofparadise_b8.png
Image

# default size is 16
stainedglass -r 100 -k random -b 150 -t 1 -r 56 birdofparadise_b8.png birdofparadise_b8_sg.png
Image


To do it exactly, would be very time consuming and would really require that this script be implemented as a function of IM. But to script it, you would have to make a mask for each cell (one at a time), use the mask to get the average colors (see http://www.fmwconcepts.com/imagemagick/ ... shape_mean), then flood fill the region with the mean color. The repeat for each other cell. Then composite all the images together.

If the blur concept is acceptable, I can build it into the script as an option.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stained Glass effect using average color

Post by fmw42 »

One can even make shaped averages using -morphology, such as for an octagon shape we would have -morphology Convolve Octagon:N where N is the octagon shape argument that would need to be matched to the desired cell size. You can do squares, diamonds, octagons and circles.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Stained Glass effect using average color

Post by josephs »

Interesting solution blur. I would never have thought of this. I really like the idea of shaped averages using -morphology. I'm going to get working on this approach.

Thank you so much for the detailed response!
Post Reply