4 Replies Latest reply on Jan 29, 2016 11:23 AM by SuperMerlin

    Read pixel data from a selection

    bagonterman Level 1

      I have been looking at some samples and it looks like you can get the coordinates of a selection. However i would like to get the pixel data found in the selection. For instance each pixel coordinates and corresponding color value.

      Is there away to recognized the bounds of the selection at each pixel?

        • 1. Re: Read pixel data from a selection
          c.pfaffenbichler Level 9

          What are you trying to achieve exactly?

          How do you intend to treat pixels that are not fully selected (that refers to the value of the corresponding pixel in the Selection, not to the "geometry")?

          • 2. Re: Read pixel data from a selection
            oliverIntergrafika Level 2

            I was searching for this info a while ago without success. The only way what is found is to save the .png and .jpg. Load this file into an <image> tag in a html panel, and copy out it's bitmap information (or something) array. Weird!
            If You find a way to access pixels from JSX, let me know!

            • 3. Re: Read pixel data from a selection

              I've only been able to determine the number of pixels of certain colors (bounded by the selection) using the histogram, but unfortunately it doesn't provide you with the pixel coordinates, just a general count.

              • 4. Re: Read pixel data from a selection
                SuperMerlin Level 5

                You can do the same sort of thing in Bridge.

                If co-ordinates of the full image are required get the bounds of the selected x= bounds[0] y = bounds[1] these can then be added to the script.

                Save the selection as a PNG  (no other format will do if you want alpha)

                select the png in Bridge and run the following script, this will create a csv file with X,Y,Red,Green,Blue,Opacity


                #target bridge;
                var thumb = app.document.selections[0];
                function pixelData(thumb){
                    var image, bit, x, y,line;
                    var f=new File(Folder.desktop +"/PixelData.csv");
                    bit = new BitmapData( thumb.spec ); 
                    for ( y = 0; y < bit.height; y++ ) {
                        for ( x = 0; x < bit.width; x++ ) {
                            line=x+","+y + "," +((Number(bit.getPixel32(x, y )>>16) & 0xff)).toFixed(0); //Red
                            line+=","+   ((Number(bit.getPixel32(x, y )>>8) & 0xff)).toFixed(0); //Green
                            line+=","+   ((Number(bit.getPixel32(x, y )) & 0xff)).toFixed(0); //Blue
                            line+=","+    ((Number(bit.getPixel32(x, y )>>24) & 0xff)*0.3922).toFixed(0); //opacity 
                            f.writeln(line); line='';
                alert(f + " has been created");
                }catch(e){alert(e + " - " + e.line);};