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

How can I export the number of pixels of each layer into an excel file?

New Here ,
Aug 11, 2013 Aug 11, 2013

I would like to export the number of pixels that each layer of an image contains into excel. How can I do this?

Secondly, as I need to do this with several images, is there any way to name the layers so that all layers with let's say for example the name "yellow" appear in the same column in excel?

Some background information on why I need to do this... I would like to know how many percent of an image are yellow and have therefore created  layers of one image for each color it contains.

Thanks for your help!!!

TOPICS
Actions and scripting
1.4K
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
LEGEND ,
Aug 12, 2013 Aug 12, 2013

You will need scripting for such functionality. Ask in the respective PS scripting forum.

Mylenium

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
New Here ,
Aug 13, 2013 Aug 13, 2013

I posted my question in the scripting forum but dind't get any answers. Does nobody have an idea on how I can export the number of pixels of a layer into excel?

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
Guru ,
Aug 13, 2013 Aug 13, 2013

Does nobody have an idea on how I can export the number of pixels of a layer into excel?

You can record number of pixels/layer  into the Measurement Log, then export data to Excel. But I'm not sure how to automate that without scripting.

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
Guru ,
Aug 13, 2013 Aug 13, 2013

For normal artLayers it is somewhat easy to get the number of pixels in the layer. But that is just how many pixels are in the layer. There really isn't a good way to determine things like the percentage of yellow in the layer with a script.

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
Guru ,
Aug 13, 2013 Aug 13, 2013

And "yellow" is a bit of a subjective term. In Photoshop pure Yellow is a mix of colors: pixels 255 Red and 255 Green. Do you want to include 254 Red and 253 Green?  Or 253 Red 249 Green and 10 Blue?

It is difficult for quantification purposes to pull out "only Yellow". You can use Color Range selection, but that is not exact enough IMO for data analysis, unless you have very controlled parameters.

Scripting may help with selecting/identifying pixels containing both Red and Green but no Blue data. But that is way above my pay-grade.

Can you give more detail for your request? Is it to quantify areas of double-labeling in cell photo-microscopy?

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
Guru ,
Aug 13, 2013 Aug 13, 2013

charles badland wrote:

And "yellow" is a bit of a subjective term...

Yes, that is what I meant when I said there really isn't a good way to determine the number of pixels of a color in a layer. Unless you are very specific and only need to deal with a limited range so you can use something like a color range selection.

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
Guru ,
Aug 13, 2013 Aug 13, 2013

What i was thinking... if the OP is using confocal images from a microscope. Those will only have data in the Red and Green channels if he is looking at double-labeled cells. (this is a big assumption on my part)

There may be a way using Image>Calculations to select only pixels sharing data in both the Red and Green channels that could be scripted?

double-trouble.jpg

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
New Here ,
Aug 13, 2013 Aug 13, 2013

Maybe my question was a bit unclear. I do not want to find out the number of pixels of a color in a layer but the number of pixels of the complete layer.
What color these layers are is a different question. I am using images with a very limited range of colors (sort of like the image above but with about 10 colors). I have seperated these colors into layers and now need to count the pixels of each layer and export them.
You can record number of pixels/layer  into the Measurement Log, then export data to Excel. But I'm not sure how to automate that without scripting.
Does anyone know how to do this?
For normal artLayers it is somewhat easy to get the number of pixels in the layer. But that is just how many pixels are in the layer.
But that is exactly what I need to know, how many pixels are in the layer. I know how to find this out by looking at the histogram of the selection. But I want to export this information of all layers at once into an excel or text file. Any ideas on how to automate this with or without scripting?
|



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
Guru ,
Aug 14, 2013 Aug 14, 2013

If you have the same number of layers in each file, with the same names, you can record an Action to automatically select pixels in each layer and record in the Memory Log then export to Excel. Like I said, it could probably be scripted too, but I don't script. Playing an Action on each file may be the next best thing.

What version of Photoshop are you running?

And can you post an screen shoot example showing the Layers Panel?

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
Guru ,
Aug 14, 2013 Aug 14, 2013
LATEST

The Measurement Log is an Extended feature so you can only use it if you have an Extended version of Photoshop. And it is not needed for this task.

Array.prototype.sum = function(){

    for (var i = 0, sum = 0 ; i != this.length; ++i) {

    var n = this;

    if(!isNaN(n)) {

    sum += n;

    }

    }

    return sum;

};

function layerPixels2Selection(){

    if(app.activeDocument.activeLayer.isBackgroundLayer){

        return;

        }

    var desc = new ActionDescriptor();

    var ref = new ActionReference();

    ref.putProperty( charIDToTypeID( "Chnl" ), charIDToTypeID( "fsel" ) );

    desc.putReference( charIDToTypeID( "null" ), ref );

    var ref = new ActionReference();

    ref.putEnumerated( charIDToTypeID( "Chnl" ), charIDToTypeID( "Chnl" ), charIDToTypeID( "Trsp" ) );

    desc.putReference( charIDToTypeID( "T   " ), ref );

    executeAction( charIDToTypeID( "setd" ), desc, DialogModes.NO );

};

var csvString = '';

csvString = csvString + 'layer,pixels\r';

var doc = app.activeDocument;

for(var layerIndex=0;layerIndex<doc.artLayers.length;layerIndex++){

    doc.activeLayer = doc.artLayers[layerIndex];

    layerPixels2Selection();

    csvString = csvString + doc.activeLayer.name+','+doc.histogram.sum()+'\r';

    doc.selection.deselect();

}

var csvFile = new File('~/desktop/layerData.csv');

csvFile.open('w');

csvFile.write(csvString);

csvFile.close();

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