Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

RGB values into array?

Engaged ,
Feb 06, 2016 Feb 06, 2016

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

TOPICS
Actions and scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Feb 06, 2016 Feb 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 07, 2016 Feb 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2016 Feb 07, 2016

Paul Riggott once posted something along those lines …

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2016 Feb 07, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 07, 2016 Feb 07, 2016

It is a pity that Paul stopped contributing here …

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2016 Feb 07, 2016

That is very interesting.  I'll need to give the raw file thing a try.

Also, I wonder if a script file together with a simple filter/plugin file that imports and exports the RGB data could be created? Is it possible for a script to get data from a filter plugin file? Ultimately, what I want is to be able to get the RGB data into an array (and preferable the HSB data too if possible), have the script (or plugin file) create a new array with modified values and then update a layer into photoshop with the new values.  I still need the main program to use the JSX scripting because it needs to do a lot of script related tasks.  I only have one particular layer that I want to manually calculate new values for each pixel and export directly back into photoshop somehow.  I've never create a plugin filter before but I'm thinking that just importing and exporting RGB data would be the first step to learn when creating a plugin filter.  Maybe a plugin file that does just that task wouldn't be too hard to create????

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 07, 2016 Feb 07, 2016

It would be way more effective to perform all calculations in plugin. It's not that complicated, check Dissolve sample from SDK.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2016 Feb 08, 2016

I think I agree with that.  I'm just struggling on how to get started.  Is there any good lessons online for Photoshop plugin creation? 

I can't seem to find much documentation at all on plugin creation.  I'm not a C++ expert by any means.  However, I think I could easily write some simple code to get values from an array, run them through an algorithm and then create a new array of RGB data.  I just need to figure out how to get the RGB values from photoshop into the plugin and then how to export the new values from the plugin back into photoshop.

Also, I don't need a UI for the plugin.  The JSX script will be the UI.  The JSX UI managers about 20 layers.  There is just one particular layer that I want for the plugin to be able to manipulate.  The script would need to run the plugin and send a few variables to it. The plugin would then update the single layer in Photoshop.

Also, I did look through the Dissolve sample you mentioned.  However, that is actual rather complicated for me to figure out. I think what I want to do is actually much less complicated..............if I can just figure out how to get started.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 08, 2016 Feb 08, 2016

Dissolve is pretty simple

check out Dissolve.cpp in common, function DoFilter() does pixel processing in the for loop at the end of function - start changing it.

SDK documentation describes how filter plugin works, btw

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2016 Feb 08, 2016

OK, thanks. I just found the docs you are referring to and they answer a lot of questions I have.   Also, the Adobe SDK says that Microsoft Visual Studio Professional is required.  Can a different (free) C++ compiler be used instead or is there a reason that Visual Studio must be used to compile?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Feb 08, 2016 Feb 08, 2016

There was free Visual Studio Express before (I suppose it's still there), and I used it to compile plugins succesfully

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 10, 2016 Feb 10, 2016
LATEST

Thanks, I'll give that a try,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 07, 2016 Feb 07, 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;

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines