Suggestions: gradually-revealing image

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
Docproc
Posts: 2
Joined: 2011-03-07T04:51:49-07:00
Authentication code: 8675308

Suggestions: gradually-revealing image

Post by Docproc »

Hi all

I'm relatively new to IM, and now have a job which I'm sure it can do, I'm just in need of some pointers as to the best way to go about it.

I have an image, which is the logo of the project I'm working on. I want to turn this into a series of images that can represent the progress of certain tasks. So I want 0% progress to be the image in grayscale, 25% progress to be the left-hand 25% of the image in colour, the rest greyscale, 50% being the left-hand half of the image in colour, and so on until the whole image is in colour representing 100%.

I plan to write a Perl script to automate this (I assume it'll be a series of IM convert commands), but I need to figure out how do it in principle first.

I assume I need to generate a series of masks of increasing width, and composite them with the original image, using an appropriate compositing method.

Am I on the right track here? Any tips will be gratefully appreciated.

Thanks in advance

Glenn.


IM 6.3.7 on Mac OS X 10.6.6
HugoRune
Posts: 90
Joined: 2009-03-11T02:45:12-07:00
Authentication code: 8675309

Re: Suggestions: gradually-revealing image

Post by HugoRune »

check out http://www.imagemagick.org/Usage/channels/#zeroing
http://www.imagemagick.org/Usage/channe ... bine_other
http://www.imagemagick.org/Usage/compose/#multiply

basically you need to select the saturation channel with
-colorspace HSL -channel G
then multiply the channel with a gradient mask
-compose Multiply

where the mask is black, the resulting image will be grayscale, and where it is white, it will be left unchanged
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Suggestions: gradually-revealing image

Post by fmw42 »

one way is to just crop the image by percent, create the appropriate transparent percent image and the appropriate grayscale percent image and append together horizontally. Just compute the image size and use your percent to get the crop amount and the sizes of the transparent and grayscale images.

Another way is to use binary masks thresholded from a horizontal gradient and multiple composites to create the 3 sections.

This does the left side and the rest transparent.

thresh=25
ww=`convert rose: -ping -format "%w" info:`
hh=`convert rose: -ping -format "%h" info:`
convert rose: \( -size ${hh}x${ww} gradient: -rotate 90 -threshold ${thresh}% -negate -write mpr:mask \) \
-alpha off -compose copy_opacity -composite rose_t25.png


You need to composite a grascale image over the right side.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Suggestions: gradually-revealing image

Post by anthony »

Does the logo contain transparency?

Without transparency you can simplify the process, especially if you don't want a sharp change between the left (color) and the right (greyscale) sides during the 'wipe'.

However as the same background transparency will be used between the first and final images, and thus all the images between, then you can make use of that simplification.

STEPS...
  • extract the transparency channel form the image (save it for later)
  • Generate a de-saturated version of the image (starting point)
  • create a animation sequence wiping from grey to color
    You can use Fred Weinhaus's 'transitions' script for that
    Or generate a sequence of transition masks, which you apply to the color image (which as the image has no transparency at this point makes it easier), and then overlay that transition sequence on top of the starting grey image.
  • Re-add the transparency mask to complete the animation
NOTE: you should NOT continually re-save the intermedite animation sequences as GIF as GIF is a lossy file format. Either do all the work in memory, or save as a multi-image MIFF file. Only the final animation should be saved as GIF.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Docproc
Posts: 2
Joined: 2011-03-07T04:51:49-07:00
Authentication code: 8675308

Re: Suggestions: gradually-revealing image

Post by Docproc »

Thanks for the helpful suggestions folks, I've succeeded in getting what I want. In the end I did the following:

- made a grayscale copy of the original image to serve as the "background"

- used -crop on the original image with increasing percentage widths to create coloured vertical slices

- composited each slice in turn with the gray background to produce the final images

I'm very happy with the result, I wouldn't have been able to do it without your help. Thanks a lot!

Glenn.
Post Reply