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

Does anyone know of a script clear the histogram cache and copy its data to the clipboard?

Community Beginner ,
Jan 20, 2015 Jan 20, 2015

I find myself manually copying pixel counts from my histogram into excel and am wondering if there is an existing script that allows the user to copy the histogram data onto the clipboard. 

From a QA standpoint alone this would be a huge advantage! 

TOPICS
Actions and scripting
1.1K
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

correct answers 1 Correct answer

Community Expert , Jan 21, 2015 Jan 21, 2015

Does this work for you – you only want the total number of the pixels in the Selection in the Clipboard, right?

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

  var myDocument = app.activeDocument;

  var theName = myDocument.name;

  try {var theName = theName.match(/(.*)\.[^\.]+$/)[1]} catch (e) {};

  try {var thePath = myDocument.path}

  catch (e) {var thePath = "~/Desktop"};

  if (myDocument.mode == DocumentMode.MULTICHANNEL || myDocument.mode ==

...
Translate
Adobe
Community Expert ,
Jan 21, 2015 Jan 21, 2015

Why involve the clipboard at all, might not a txt file be more convenient?

What are you doing exactly anyway?

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 ,
Jan 21, 2015 Jan 21, 2015

I think you would need to use some system screen capture feature like Prtscrn to get the histogram into the clipboard and that it would be an image and not text data.  I do not see any interface in the histogram palette to copy histogram data to the clipboard.

However if you look at pager 74 in the Photoshop javascript reference guide you will fnd that you can get at the histogram data  and write a text file.  There is an example script for doing that there.....

Capture.jpg

Page 74 Channels sample script

The following script opens a file if one is not already open, and then writes a histogram report

(histogram.log) for the channels in the active document.

Note: This script contains a switch construction that uses a break statement. The break statement

requires an ending semicolon (;), as in the following sample:

break;

Histogram.jsx

JJMack
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 ,
Jan 21, 2015 Jan 21, 2015

Histogram Export

How to get text into the clipboard would probably have to be platform dependent.

What is your OS?

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 Beginner ,
Jan 21, 2015 Jan 21, 2015

I'm on Windows 8. 

I've played around with the histogram.jsx that was included in Photoshop CS4(?). 

It receives its total pixel count from imageH * imageW so it only works on rectangular selections.

My specific application involves creating a new layer from an irregular shape selected in an image and then measuring the total pixels present in that shape which are then copied into an excel spreadsheet.  We have a constant that we multiply our pixel count by in order to determine the area in centimeters of our irregular selection.  For example if our layer contains 1109078px and we know that our images scales at 255.53 pixels/cm then we can calculate our selected area to be 21.84 sq cm.


Because we make measurements twice on each of the hundreds of images spanning dozens of sites I end up copying the pixel count from the histogram by hand an huge number of times.  Hand copying means the possibility for transcription error which has the potential to alter our data.  Just to give you a baseline, I've made 733 transcriptions of that readout on the current site I'm analyzing. 

Getting at the histogram and copying directly to the clipboard would be the most efficient and sound way to copy the data.

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 ,
Jan 21, 2015 Jan 21, 2015
Getting at the histogram and copying directly to the clipboard would be the most efficient and sound way to copy the data.

Are you sure?

A Script could handle many files, so one could store the Selection as a Channel for a bunch of them, have the Script work through that, do the math and then create a txt file listing the results per image.

And are you familiar with Measurement Log?

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 ,
Jan 21, 2015 Jan 21, 2015
I'm on Windows 8.

I’m a Mac user, so I don’t know how to pass a string to the Clipboard on Windows.

Have you down a Forum search for that yet? (Maybe also try http://ps-scripts.com/bb/)

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 Beginner ,
Jan 21, 2015 Jan 21, 2015

I found this posting on Stack Overflow.

Photoshop 13.1 (the latest Creative Cloud release of Photoshop CS6) now has a hook allowing you to do this directly. Here's a sample function:

function copyTextToClipboard( txt )

{

     const keyTextData = app.charIDToTypeID('TxtD');

     const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

     var textStrDesc = new ActionDescriptor();

     textStrDesc.putString( keyTextData, txt );

     executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );

}

Please note this won't work in versions of Photoshop prior to 13.1

I haven't had any luck implementing it though.

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 ,
Jan 21, 2015 Jan 21, 2015

What do you know, it can be done non-platform dependent after all it seems … works for me.

What is the complete code wherein it fails for you?

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 ,
Jan 21, 2015 Jan 21, 2015

Does this work for you – you only want the total number of the pixels in the Selection in the Clipboard, right?

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

  var myDocument = app.activeDocument;

  var theName = myDocument.name;

  try {var theName = theName.match(/(.*)\.[^\.]+$/)[1]} catch (e) {};

  try {var thePath = myDocument.path}

  catch (e) {var thePath = "~/Desktop"};

  if (myDocument.mode == DocumentMode.MULTICHANNEL || myDocument.mode == DocumentMode.GRAYSCALE) {

  var theHistogram = myDocument.channels[0].histogram

  };

  else {var theHistogram = myDocument.histogram};

// get total number of histogram:

  var theNumber = 0;

  for (var m = 0; m < theHistogram.length; m++) {theNumber = theNumber + theHistogram};

  copyTextToClipboard (theNumber);

/* var theText = new File(thePath+"/"+theName+"_histo.txt");

  theText.open("w");

  for (a = 0; a < theHistogram.length; a++){

// this line adds the number of the histogram-level;

  theText.write(bufferNumberWithZeros(a,3)+"_");

// this line adds the number pixels of the respective histogram-level;

  theText.write(theHistogram);

  theText.write("\n")

  }

  theText.close();*/

  }

else {

  alert ("no open document")

  };

////// buffer number with zeros //////

function bufferNumberWithZeros (number, places) {

  var theNumberString = String(number);

  for (var o = 0; o < (places - String(number).length); o++) {

  theNumberString = String("0" + theNumberString)

  };

  return theNumberString

  };

//////

function copyTextToClipboard( txt ) {

const keyTextData = app.charIDToTypeID('TxtD');

const ktextToClipboardStr = app.stringIDToTypeID( "textToClipboard" );

var textStrDesc = new ActionDescriptor();

textStrDesc.putString( keyTextData, txt );

executeAction( ktextToClipboardStr, textStrDesc, DialogModes.NO );

};

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 Beginner ,
Jan 21, 2015 Jan 21, 2015

Well that certainly did the trick!  I was going about it a little differently and only able to copy a rectangular boundary around my layer.  This works perfectly. 

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 ,
Jan 21, 2015 Jan 21, 2015

Better do a few tests before you start trusting that code, though.

Feathering and soft edges of the Selection would affect the result, so that may deserve some attention spending on the way you create the Seletcions.

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 Beginner ,
Jan 21, 2015 Jan 21, 2015

We arrive at one of our measurable layers through a Color Range selection which does create a soft edge.  The diffuse portion of that selection is usually considered an artifact of our photography process so dropping a few pixels in that region is really not a problem.

I've been running a some tests with it and so far any discrepancy between the manual entry and the script seem pretty minimal, accounting for ~.1mm average difference.

Thanks again for the assistance here.  I can't even tell you how much more efficient this has been so far!

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 ,
Jan 21, 2015 Jan 21, 2015
LATEST

Maybe you could edit the Selection (in Quick Mask mode for example) with Threshold or Levels to include the semi-transparent pixels.

Quick Mask Mode might offer a different approach in that one could assess the Histogram of that channel itself.

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