1

Looking to see if this is possible for some artwork we could put in our office. I have some complex line drawings based on some of our very old engineering drawings. They are basically 2 layer files, white line details and a black background layer.

I am looking to randomly color the image and wonder if a script can be made rather than doing it manually. I have made a few photoshop scripts but this is beyond my programming skills.

I am curious if a script can be made which does the following...

  1. moves mouse to a random X,Y % location on the image
  2. checks if the color is 0,0,0 (black)
  3. if YES, paint bucket fill with given color and return to step 1
  4. if NO, return to step 1

Repeat 100 times

So the script moves around the image and bucket fills a color if the color at current cursor location is black. Hopefully this will fill in all the engineering details on these images at random, without accidentally filling in the foreground details which are WHITE/GRAY and not black.

Can this be done theoretically?

Thanks

dan z
  • 11
  • 3
  • Is photoshop a requirement here? This would seem to be possible with (for example) python + PIL http://stackoverflow.com/questions/10026346/how-to-flood-fill-part-of-a-bitmap-enclosed-by-a-black-border-with-my-chosen-col – James K Aug 25 '16 at 21:09
  • Can PIL work the tiff files and create layers? if so then that would be fine. I just assumed photoshop would be the way to go but anything that gets the job done is fine with me. – dan z Aug 25 '16 at 22:41

1 Answers1

0

These methods are from old Photoshop scripts I made ~10 years ago, but they might be helpful. There are two functions, one to perform a eyedropper click on a x,y point to get the color and another to perform a magic wand click on a x,y point. For your example, you could eyedrop a point and if it returns black, you can magic wand the same point to make a selection of the area, then perform a fill on that selection.

function eyedropper(doc,x,y) {
// don't mess with spacing inside function, seesm to braek it
Stdlib = function() {}; 
Stdlib.selectBounds = function(doc, b, type, feather, antialias) { 
    doc.selection.select([[ b[0], b[1] ], 
                          [ b[2], b[1] ], 
                          [ b[2], b[3] ], 
                          [ b[0], b[3] ]], 
                      type, feather, antialias); 
    }; 

    // getColorAt 
    // based on: 
    //     fazstp@adobeforums.com wrote: 
    //     news://adobeforums.com:119/3bb84060.0@webx.la2eafNXanI 
    // 

       // make new 1 pixel selection 
        x = Math.floor(x); 
        y = Math.floor(y); 

        Stdlib.selectBounds(doc, [x, y, x+1, y+1]); 

        try { 
            function findPV(h) { 
                for (var i = 0; i <= 255; i++ ) { 
                    if (h[i]) { return i; } 
                } 
             return 0; 
        } 

        var pColour = new SolidColor(); 

        pColour.rgb.red   = findPV(doc.channels["Red"].histogram); 
        pColour.rgb.green = findPV(doc.channels["Green"].histogram); 
        pColour.rgb.blue  = findPV(doc.channels["Blue"].histogram); 

        } finally { 
            doc.selection.deselect(); 
        } 
    return pColour; 
};

Also, here is my function for performing the magic wand:

function wand(x,y,tol,option)
{
    // options:
    // setd = initial selection
    // AddT = add to selection

    var id9466 = charIDToTypeID( option );
        var desc1828 = new ActionDescriptor();
        var id9467 = charIDToTypeID( "null" );
            var ref1340 = new ActionReference();
            var id9468 = charIDToTypeID( "Chnl" );
            var id9469 = charIDToTypeID( "fsel" );
            ref1340.putProperty( id9468, id9469 );
        desc1828.putReference( id9467, ref1340 );
        var id9470 = charIDToTypeID( "T   " );
            var desc1829 = new ActionDescriptor();
            var id9471 = charIDToTypeID( "Hrzn" );
            var id9472 = charIDToTypeID( "#Pxl" );
            desc1829.putUnitDouble( id9471, id9472, x );
            var id9473 = charIDToTypeID( "Vrtc" );
            var id9474 = charIDToTypeID( "#Pxl" );
            desc1829.putUnitDouble( id9473, id9474, y );
        var id9475 = charIDToTypeID( "Pnt " );
        desc1828.putObject( id9470, id9475, desc1829 );
        var id9476 = charIDToTypeID( "Tlrn" );
        desc1828.putInteger( id9476, tol );
        var id9477 = charIDToTypeID( "AntA" );
        desc1828.putBoolean( id9477, true );
    executeAction( id9466, desc1828, DialogModes.NO );
};
Patrick
  • 679
  • 1
  • 9
  • 20