Skip to main content
paulah20358727
Participant
July 26, 2019
Question

calculating a percentage of a selection

  • July 26, 2019
  • 1 reply
  • 2767 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.

    Chuck Uebele
    Community Expert
    Community Expert
    July 26, 2019

    To run one of the scripts, save it as a plain text file with the extension .jsx and put it in the Photoshoo sub folder Presets\Scripts. You can then run. It from the main file menu. It will show the percentage in decimal formats 50% = .5. The first script requires that you make a rectangular selection of the area you want to measure. The second script will measure just the 100% transparent part of a layer, no matter what shape.