Random Pixel recoloring

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
phresh55
Posts: 1
Joined: 2018-01-09T22:52:07-07:00
Authentication code: 1152

Random Pixel recoloring

Post by phresh55 »

Is there already a script or something that will recolor a random pixel of a batch of images?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Random Pixel recoloring

Post by GeeMack »

phresh55 wrote: 2018-01-09T23:23:40-07:00Is there already a script or something that will recolor a random pixel of a batch of images?
There are probably several simple ways to do what you're asking, but we need a lot more information to point you in the right direction. Look over the suggestions at "Read This First", then let us know what platform you're working on, which version of ImageMagick you're using, and provide a little better explanation of exactly what result you're trying to achieve.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Random Pixel recoloring

Post by fmw42 »

Is it the same random pixel in all images or different random pixels in each image? Is it only one pixel that needs recoloring randomly? A better explanation or example images would help us understand your problem. Also always provide your IM version and platform since syntax and scripting may differ

You can compute a random number in Imagemagick using the "%[fx:random()]" with values between 0 and 1. You can scale the values by multiplying X*random() in the expression. You can compute that number once for w*random() and again for h*random. To get some random coordinate and then -draw a pixel of some color to that coordinate.

If you want to do this for all images at the same coordinate, then use mogrify to process all images in a directory at the same location. If you need each image to have a separate random coordinate changed, then you will need to write a script loop over each image.

See
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx
http://www.imagemagick.org/Usage/draw/#primitives
http://www.imagemagick.org/Usage/basics/#mogrify
Post Reply