2 Replies Latest reply on Jan 5, 2012 2:56 AM by c.pfaffenbichler

    Checking pixels alpha

    syrad

      Hello again,

       

      I have a question, is it possible to check alpha of a single pixel? Or is it possible to verify is over a half of pixels at the picture got alpha on a 0-10% level?

       

      Thank You guys in advance.

       

      Best regards,

      Maciej Siwek

        • 1. Re: Checking pixels alpha
          c.pfaffenbichler Level 9

          Hasn’t that already come up recently?

           

          At the very least it should be possible to check a pixels transparency by loading the transparency and measuring with a ColorSampler in Quick Mask Mode or a saved channel.

          As for the overall distribution a saved Selection could be used to assess a histogram.

          See this thread for quantifying regions of certain brightness’ in a histogram:

          http://forums.adobe.com/thread/936743?tstart=0

          • 2. Re: Checking pixels alpha
            c.pfaffenbichler Level 9

            You could give this a try.

            It evaluates the active layer, though, and not the whole of a multi-layered file, but that could also be done.

            // alert the percentage of pixels in the active layer that are 10% opaque or less;
            // 2011, use it at your own risk;
            #target photoshop
            if (app.documents.length > 0) {
            var myDocument = app.activeDocument;
            // set to pixels;
            var originalRulerUnits = app.preferences.rulerUnits;
            app.preferences.rulerUnits = Units.PIXELS;
            loadTransparency();
            myDocument.quickMaskMode = true;
            // add up the range in the histogram;
            var theHistogram = myDocument.channels[myDocument.channels.length - 1].histogram;
            var total = myDocument.width * myDocument.height;
            var theTarget = 0;
            var thePerc = 10;
            var theNumber = Math.round(255 - (thePerc * (255 / 100)));
            for (var index = 0; index <= theNumber; index++ ) {
                      theTarget = theTarget + theHistogram[index]
                      };
            // alert;
            myDocument.quickMaskMode = false;
            alert ((theTarget / total * 100) + "% of the pixels are up to 10% opaque");
            // reset;
            app.preferences.rulerUnits = originalRulerUnits;
            };
            ////////////////////////////////////
            ////////////////////////////////////
            ////////////////////////////////////
            ////// load transparency //////
            function loadTransparency () {
            // =======================================================
            var idsetd = charIDToTypeID( "setd" );
                var desc3 = new ActionDescriptor();
                var idnull = charIDToTypeID( "null" );
                    var ref2 = new ActionReference();
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idfsel = charIDToTypeID( "fsel" );
                    ref2.putProperty( idChnl, idfsel );
                desc3.putReference( idnull, ref2 );
                var idT = charIDToTypeID( "T   " );
                    var ref3 = new ActionReference();
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idChnl = charIDToTypeID( "Chnl" );
                    var idTrsp = charIDToTypeID( "Trsp" );
                    ref3.putEnumerated( idChnl, idChnl, idTrsp );
                desc3.putReference( idT, ref3 );
            executeAction( idsetd, desc3, DialogModes.NO );
            };