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 » 2018-01-09T23:23:40-07:00

Is there already a script or something that will recolor a random pixel of a batch of images?

User avatar
GeeMack
Posts: 654
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Random Pixel recoloring

Post by GeeMack » 2018-01-10T08:40:00-07:00

phresh55 wrote:
2018-01-09T23:23:40-07:00
Is 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: 24148
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Random Pixel recoloring

Post by fmw42 » 2018-01-10T11:14:03-07:00

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