Skip to main content
Damon D Bell
Known Participant
February 6, 2016
Question

RGB values into array?

  • February 6, 2016
  • 3 replies
  • 1939 views

Is there a way to import/export rgb values for all pixels into a multi-dimensional array with JSX?

This topic has been closed for replies.

3 replies

SuperMerlin
Inspiring
February 7, 2016

There is yet another way and that is to use a bitmap in Bridge.

Here is an example it requires a file selected in Bridge, then run the script from ExtendScript Toolkit.

//To be run from ExtendScript Toolkit

#target bridge

getImage();

function getImage() {

var image, bit, data;

image = app.document.selections[0];

bit = new BitmapData( image.spec );

//resize

bit = bit.resize( 100, 'bicubicSharper' );

//get pixel data

data = readColorData( bit );

//example of geing the hex value at x,y

alert(data.x40y34);

//save object to file for later use.

var f = new File(Folder.desktop +"/objData.dat");

f.open('w');

f.write(data.toSource());

f.close();

//empty data object

data={};

//example of loading and using the object

f.open('r');

var newOBJ = eval(f.read());

f.close();

alert("X = 20 Y = 23 Hex Value = " + newOBJ.x20y23);

alert("X = 19 Y = 33 Hex Value = " + newOBJ.x19y33);

};

function readColorData( bitMap ) {

   var pix, row, x, y;

   //create and populate dynamic object to hold pixel data

   mainObj = {};

   for ( y = 0; y < bitMap.height; y++ ) {

      for ( x = 0; x < bitMap.width; x++ ) {

           mainObj ["x"+x+"y"+y] = new Color(bitMap.getPixel(x,y)).toString().match(/[A-Fa-f0-9]{6}$/);

      };

   };

return mainObj;

};

Inspiring
February 7, 2016

It's a bit of a hack, but you could probably save it as Photoshop Raw and then read the values directly from the file as binary stream.

c.pfaffenbichler
Community Expert
Community Expert
February 7, 2016

Paul Riggott once posted something along those lines …

Easy way to extract all pixel Lab values - plea... | Adobe Community

Chuck Uebele
Community Expert
Community Expert
February 7, 2016

Nice, Christoph! I'm going to have to play with that script also, as I do some stuff along those lines.

Chuck Uebele
Community Expert
Community Expert
February 7, 2016

Only way I know of, just using javascript is to use the eyedropper tool, which would be beyond slow for this purpose. I've done it with sampling various areas, at the most every 50px, and that can still take up to a half hour for a full 4000X3000 image.