Skip to main content
paulah20358727
Participant
July 26, 2019
Question

calculating a percentage of a selection

  • July 26, 2019
  • 1 reply
  • 2750 views

I'm working on an image for window glazing. The whole image is now a single colour and transparent. I need to work out what percentage of the whole image's area is the colour (and therefore how much is transparent).... for compliance with building codes etc for visibility.

I am super familiar with some aspects of Photoshop, but a total newbie with others. I'd appreciate guidance.

    This topic has been closed for replies.

    1 reply

    Chuck Uebele
    Community Expert
    Community Expert
    July 26, 2019

    Is the window in your image one contiguous area (no mullins or more than one window), and is it straight on, no perspective? If so, you can try this script that will show the percent of a selection.

    var doc = activeDocument;

    try{

        var selArea = (doc.selection.bounds[2]-doc.selection.bounds[0]) * (doc.selection.bounds[3]-doc.selection.bounds[1]);

        var docArea = doc.width * doc.height

        alert(selArea / docArea)  

        }

    catch(e){

        alert('there is no selection')

        }

    If you merge the layers and have a single layer with transparency where the windows are, this script will tell you exactly the percent of transparent pixels. you need to have the merged layer selected for this to work.

    var doc = activeDocument

    var curLay = doc.activeLayer

    var trans = true;

    getSelc ();

    try{var b = doc.selection.bounds}

    catch(e){trans = false}

    var his = doc.histogram

    var hisCount = 0

    for (var i=0;i<his.length;i++){

        hisCount+= his

        }

    var perc= 1-(hisCount/(doc.width.value*doc.height.value))

    doc.selection.deselect()

    if(trans){alert (perc)}

    else{alert('The layer is transparent.')}

    function getSelc(){

           var idsetd = charIDToTypeID( "setd" );

            var desc7 = new ActionDescriptor();

            var idnull = charIDToTypeID( "null" );

                var ref5 = new ActionReference();

                var idChnl = charIDToTypeID( "Chnl" );

                var idfsel = charIDToTypeID( "fsel" );

                ref5.putProperty( idChnl, idfsel );

            desc7.putReference( idnull, ref5 );

            var idT = charIDToTypeID( "T   " );

                var ref6 = new ActionReference();

                var idChnl = charIDToTypeID( "Chnl" );

                var idChnl = charIDToTypeID( "Chnl" );

                var idTrsp = charIDToTypeID( "Trsp" );

                ref6.putEnumerated( idChnl, idChnl, idTrsp );

            desc7.putReference( idT, ref6 );

        executeAction( idsetd, desc7, DialogModes.NO );

        }

    paulah20358727
    Participant
    July 26, 2019

    hi

    the image is a single layer

    there is Colour (single colour)

    There is transparency.

    Its a single image in large format of 5830mm high by 4570mm wide, as i'm taking all the mullions etc out for purposes of this exercise.

    I need to know percentage of a band through eye height, so i assume i'm going to select that 1000mm x 4570mm section and can just make a new file for purposes of this calculation. So i'll have a file of 1000mm x 4570mm with only a single colour and then transparency.

    I have absolutely no idea what all that script you wrote means.

    Bojan Živković11378569
    Community Expert
    Community Expert
    July 26, 2019

    urghhhh That first sentence still makes absolutely no sense to me.... its language that I just dont use.


    Copy code provided to you using select > copy method as you will copy any text. Paste in your text editor like Notepad, Notepad++... Save file with somename.jsx in location specified above - C:\Program Files\Adobe\Adobe Photoshop CC 2019\Presets\Scripts.

    You can run script from File > Scripts > choose in Photoshop.