Randomly Generated Pixels

Discussion of automation, image workflow and raw image workflow

Moderator: PS-Moderators

Randomly Generated Pixels

Postby Squis » Wed Mar 23, 2011 2:47 pm

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!
Squis
 
Posts: 17
Joined: Tue Mar 15, 2011 12:21 pm

Re: Randomly Generated Pixels

Postby txuku » Thu Mar 24, 2011 8:56 am

Hello Squis

Maybe something like this - with a dialog box :
Code: Select all
docRef = activeDocument;

//docRef.changeMode(ChangeMode.GRAYSCALE);  // only grey

//docRef.channels[1].duplicate();          // Copy Green channel

var docH = activeDocument.width;
var docV = activeDocument.height;

for(j=0;j<docH ; j++ )
{
  for(i=0;i< docV ;i++ )
  {
      // selextion 1 px
    TOP = i
    LEFT= j
    BOTTOM = TOP + 1;
    RIGHT = LEFT + 1
    var selRef = [
                  [LEFT,TOP],
                  [LEFT,BOTTOM],
                  [RIGHT,BOTTOM],
                  [RIGHT,TOP]
                  ]

    docRef.selection.select( selRef);
    //rempliCoul();                     // RGB
    rempliCoulBW();                     // B&W
  }
}

function rempliCoul()
{
    var Colour = new SolidColor;
    Colour.rgb.red = Math.ceil(255*Math.random());
    Colour.rgb.green = Math.ceil(255*Math.random());
    Colour.rgb.blue = Math.ceil(255*Math.random());
    docRef.selection.fill(Colour);
}   

function rempliCoulBW()
{
    var Colour = new SolidColor;
    Colour.rgb.red = Math.ceil(255*Math.random());
    Colour.rgb.green = Colour.rgb.red;
    Colour.rgb.blue = Colour.rgb.red;
    docRef.selection.fill(Colour);
}   


But it will be very very long if the size of the image is large ! :x
txuku
 
Posts: 340
Joined: Tue Apr 15, 2008 2:15 pm
Location: France - Pays Basque

Re: Randomly Generated Pixels

Postby Squis » Thu Mar 24, 2011 1:19 pm

Wow! Thanks for the code! I've been trying to keep away from single pixel editing, since it would take quite long. But I should just go ahead and try it to see how long it really takes.
Squis
 
Posts: 17
Joined: Tue Mar 15, 2011 12:21 pm

Re: Randomly Generated Pixels

Postby txuku » Thu Mar 24, 2011 1:28 pm

I've tried 100x100: manageable!

3504x2336 .... hard ! :)
txuku
 
Posts: 340
Joined: Tue Apr 15, 2008 2:15 pm
Location: France - Pays Basque

Re: Randomly Generated Pixels

Postby jacobolus » Fri Mar 25, 2011 9:21 am

My recommendation would be to use the add noise filter, and combine it with other tools to change the output. For example, you can change the probability distribution by applying curves to the uniform noise or making two noise layers and combining them with adjustable blend mode and transparency. For black/white make grayscale noise and then use the Threshhold adjustment. You can make the noise apply to particular channels by unchecking the channel visibility of the others in the Advanced Blending options. You can apply noise to the alpha by way of a layer mask. And so forth.

If that doesn't work, then my recommendation would be to create your noise in an external program. If I was doing it, I would use Python and Numpy, in which creating whatever kind of noise you want is trivial.
jacobolus
 
Posts: 161
Joined: Tue Mar 22, 2011 11:30 pm


Return to Automation & Image Workflow

Who is online

Users browsing this forum: No registered users and 1 guest