Copy link to clipboard
Copied
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!!!
Copy link to clipboard
Copied
You will need scripting for such functionality. Ask in the respective PS scripting forum.
Mylenium
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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();
Find more inspiration, events, and resources on the new Adobe Community
Explore Now