Copy link to clipboard
Copied
Hi!
I want to create a script that creates random (or near random) values for every single pixel of a document, similar to the "Add Noise..." filter, but with more control, such as "only b/w", "only grey", "all RGB" and "all RGB with alpha" and maybe even control over the probability distribution. Any idea how this could be tackled? Selecting every single pixel and applying a random color seems like something that would take a script hours...
Why do I need this?
I've started creating some filters in Pixel Bender (http://en.wikipedia.org/wiki/Adobe_Pixel_Bender). Since Pixel Bender doesn't really have any random generator (and workarounds are limited) I'm planning on passing on the random numbers through random pixel values. I'm well aware that this can only be used for filters in which Pixel Bender creates images from scratch, but that's the plan.
Thanks!
Copy link to clipboard
Copied
If you need the nosie generator inside pixel bender, then my suggestions that follow will not be of help. If you want to have a noise generator inside PS with the features you describe, you can do that.
- The existing noise filter allows one to do "All RGB" as well as monochromatic/only grey.
- You already have a uniform distribution and gaussian available.
- The starting point and ending point in the distribution is controlable both setting a fixed gray level if the startung image and adjusting the noise slider
- If you want just B&W, you just use a threshold blend on top of a gray noise image
- If you want to also randomize an alpha channel (you were not specific if this was to be the transparency of the image or the layer mask) this can be done by creating a separate gray image with desired noise and then having this moved to the Layer Mask or to Transparency
- Other Probability distributions can be created by combining several uniform or gaussian distributions using the blend math (e.g. Create uniform noise distribution from 0 to 127.5. Just add these two noise layers and you have a triangular distribution from 0 to 255)
All of the above operations are very quick since they run with the PS core engine.
Just thought I would mention another alternative that can be done even with Actions and is fast.
If you have more questions, ask away.
Copy link to clipboard
Copied
This would be well outside what I script in PS but could you not just script the writing of 'random' value to arrays to file and then have PS read this as data? I've seen a post on this in this forum before now but that kind of stuff is not what I use PS for… You could also take a look at Jongware's .png generator script thats posted in the Indesign scripting forum… With these you should be able to use math to create new files…
Copy link to clipboard
Copied
Thanks for the replies!
Creating the randomness outside of pixel bender is definetely and option. I've been playing around with the Add Noise filter, and from what I can tell, the result is the same when using same values; even when used on different colors, it's always a very very similar pattern. That would be fine if I wanted to create exactly one image in pixel bender, but I was hoping for several different ones. Combining noises sounds interesting.
Also, I haven't quite understood how the Add Noise filter works. What does the percentage do exactly? Which would be the right value for the highest possible randomness? 100%? 400%?
Filling and array with random values would work, but this would require one big array (otherwise visible patterns would emerge), and assigning a random value to every pixel would take forever (by means I know of). I'll have a look at Jongware's script, thanks!
Right now I'm thinking of creating my own plug-in to fulfill my needs. I mean, how hard can it be
Copy link to clipboard
Copied
Understanding the details of the Add Noise filter is probably beyond the scope of just a short post. Here is an approach to start learning what it does.
- Take a 50% gray level and make it a Smart Object.
- Open up the historgram panel (should show a spike right at 50%)
- Apply noise filter to Smart Object in monochrome building up from small percentages in small increments
- You will notice that for this option above, you end up with a uniform probability function over the entire tonality spread at 50% applied for uniform distribution.
There are a variety of ways to manipulate this function, through various blends.
Please note a couple things
1) I am using CS5 and though not documented anywhere that I have seen, the Noise Filter does work different than in CS4. In CS4, if you run the same noise filter twice on two identical objects, my experience is that you get the identical bit for bit result ( a random pattern yet not independent of the next run of the filter). Manipulating Probability Density Functions (PDFs) per my previous post requires that each run of the Noise Filter starts with a different "seed" so that the result is independent of the previous run. CS5 does this where succesive runs will create an independent noise result.
2) PS does not equally randomize R, G, and B. There are ways to get around this yet wanted to give you a heads up.
3) There are other ways to generate quick random patterns outside of PS and bring them in (using scripts). You would need to understand the format of the Photoshop Raw file. This type of file contains bytes with just the image pixel data. These types of files are easy to create and then load into PS. From a script (or even faster call a Python script) create this file and then load it into PS as a Photoshop Raw format file and use as an overlay. There is not question that this is faster than trying to manipulate individual PS pixesl through a script.
4) Please not the under Color Settings there is an option called Dither. If this is set, there are times where PS adds nosie into the image (I leave mine turned off). If is used in a number of places in PS other than what the documentation implies (more than just when moving between 8 bit color spaces)
Good luck if you are going after making a plug-in. I have never invested in that learning curve. Good luck.
Copy link to clipboard
Copied
Something I've been wanting to try for a while is generating Perlin noise within Pixel Bender. For a small initial starting array of values you should
be able to get decent looking noise over the plane.
Bob
Find more inspiration, events, and resources on the new Adobe Community
Explore Now