Copy link to clipboard
Copied
I need a profile of density in a line across part of an image, for example, crossing a text character. How bright is it to the left of the letter I, in I, and to the right of I?
It's a pain having to use the eyedropper to capture the value of one pixel at a time, successively left to right, writing them down, and then plotting them manually.
Is there a way to capture the values in a long narrow selection and have CS6 display them, value vs position?
Note that this not a histogram, which will only tell me how many of each value exists overall in such a selection.
Thanks,
Nick
Sorry, but this is how Google translated.
Since you asked a question in the Photoshop scripting forum, I thought that you know how to create and run scripts.
Just in case a new script.
You select a zone as in the picture.
Run the script. Get the result as shown in the other picture.
...app.preferences.rulerUnits = Units.PIXELS;
var points = new Array();
try { var b = activeDocument.selection.bounds; } catch(e) { alert("No selection"); throw(e); }
var x0 = Number(b[0].value);
var y0 = Number(b[
Copy link to clipboard
Copied
Hi
I've moved your post to the Photoshop Scripting forum where you are more likely to get a response to your question
Dave
Copy link to clipboard
Copied
Some custom C++ plugin could handle it.
Maybe PixelBender could do it. This plugin is discontinued. It should work for CS5 I am not sure about CS6
more here: Pixelbender
Copy link to clipboard
Copied
Thanks, but pixelbender is not applicable and not compatible with CS6.
A similar unanswered question is
Copy link to clipboard
Copied
And what does not like scanning with eyedropper?
The following code using a moving selection of 1x1 pixels is suitable?
app.preferences.rulerUnits = Units.PIXELS;
var ret = new Array();
try { var b = activeDocument.selection.bounds; } catch(e) { alert("No selection"); throw(e); }
var x0 = Number(b[0]);
var x1 = Number(b[2]);
activeDocument.selection.select([ [b[0],b[1]], [b[0]+1,b[1]], [b[0]+1,b[1]+1], [b[0],b[1]+1] ]);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference( charIDToTypeID( "null" ), r );
var d2 = new ActionDescriptor();
d2.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Pxl" ), 1 );
d2.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Pxl" ), 0 );
d.putObject( charIDToTypeID( "T " ), charIDToTypeID( "Ofst" ), d2 );
for (var i = x0; i < x1; i++)
{
var h = activeDocument.histogram;
for (var n = 0; n < 256; n++) if (h
) { ret.push([i,n]); break; } if (n == 256) ret.push([i, undefined]); // if photoshop bug
executeAction( charIDToTypeID( "move" ), d, DialogModes.NO );
}
// array of [pixel_offset_x, pixel_value];
alert(ret.toSource())
Copy link to clipboard
Copied
Your "And what does not like scanning with eyedropper?"
Sorry, I do not understand this question.
1. Eyedropper does not scan.
2. As stated in my original question, "It's a pain having to use the eyedropper to capture the value of one pixel at a time, successively left to right, writing them down, and then plotting them manually."
3. Repetitively, for many slices the eyedropper, writing, and plotting manually takes too much time and effort.
Thank you for trying to help, but I can't use your reply. I'm not a programmer. I don't even know that language or which program could use it. Also, retrieving one pixel at a time (I'm guessing that's what you intend) is what the eyedropper does, which is not satisfactory. I need a plot of the pixel values in a line selection.
Meanwhile, I have found the program ImageJ and am trying to see if it will do the job.
Nick
Copy link to clipboard
Copied
Sorry, but this is how Google translated.
Since you asked a question in the Photoshop scripting forum, I thought that you know how to create and run scripts.
Just in case a new script.
You select a zone as in the picture.
Run the script. Get the result as shown in the other picture.
app.preferences.rulerUnits = Units.PIXELS;
var points = new Array();
try { var b = activeDocument.selection.bounds; } catch(e) { alert("No selection"); throw(e); }
var x0 = Number(b[0].value);
var y0 = Number(b[1].value);
var x1 = Number(b[2].value);
activeDocument.selection.select([ [b[0],b[1]], [b[0]+1,b[1]], [b[0]+1,b[1]+1], [b[0],b[1]+1] ]);
var d = new ActionDescriptor();
var r = new ActionReference();
r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
d.putReference( charIDToTypeID( "null" ), r );
var d2 = new ActionDescriptor();
d2.putUnitDouble( charIDToTypeID( "Hrzn" ), charIDToTypeID( "#Pxl" ), 1 );
d2.putUnitDouble( charIDToTypeID( "Vrtc" ), charIDToTypeID( "#Pxl" ), 0 );
d.putObject( charIDToTypeID( "T " ), charIDToTypeID( "Ofst" ), d2 );
var rez = 72/activeDocument.resolution;
var _p = new PathPointInfo();
with (_p)
{
kind = PointKind.CORNERPOINT;
anchor = leftDirection = rightDirection = [x0*rez, y0*rez];
}
points.push(_p);
for (var i = x0; i < x1; i++)
{
var h = activeDocument.histogram;
for (var n = 0; n < 256; n++)
{
if (h
) {
var p0 = new PathPointInfo();
var p1 = new PathPointInfo();
with (p0)
{
kind = PointKind.CORNERPOINT;
anchor = leftDirection = rightDirection = [i*rez, (y0-n)*rez];
}
with (p1)
{
kind = PointKind.CORNERPOINT;
anchor = leftDirection = rightDirection = [(i+1)*rez, (y0-n)*rez];
}
points.push(p0);
points.push(p1);
break;
}
}
executeAction( charIDToTypeID( "move" ), d, DialogModes.NO );
}
var _p = new PathPointInfo();
with (_p)
{
kind = PointKind.CORNERPOINT;
anchor = leftDirection = rightDirection = [x1*rez, y0*rez];
}
points.push(_p);
activeDocument.selection.deselect();
var pth = new Array();
pth[0] = new SubPathInfo();
pth[0].operation = ShapeOperation.SHAPEADD;
pth[0].closed = false;
pth[0].entireSubPath = points;
activeDocument.pathItems.add("Plot"+Math.random().toString().substr(2), pth);
P.S. I can not help you with anything else.
Copy link to clipboard
Copied
r-bin,
The images in your example show exactly what I want, so I tried to use your script with one of my images.
However, this is my first try with Script Editor. (My post was originally in forum CS6 and was moved by its moderator to forum Scripts, which would be more likely to find help.) I hope my failure that I describe below isn't too tedious or out of place in this forum. This may even be a useful example of the detail required for successful communication.
First, I copied the Applescript Hello World example from APPLESCRIPT CS6 SCRIPTING GUIDE into the Script Editor app. It ran correctly.
Next, I made a selection in the Background Layer of a .jpg image in Photoshop CS6.
Then I tried your script. It keeps throwing
error "The variable t is not defined." number -2753 from "t"
I pasted your script and Ran it.
It erred at the first . highlighted in
app.preferences.rulerUnits = Units.PIXELS;
Then, I added
tell application "Adobe Photoshop CS6"
at the beginning and
end tell
at the end. It still erred at the first . highlighted in
app.preferences.rulerUnits = Units.PIXELS;
Next, I added
set set current document to docRef
set set current layer of current document to layer “Layer 1” of current document
It erred at the first " highlighted in
set current layer of current document to layer “Layer 1” of current document
I couldn't find any help with this error in Google. Clearly, I need the statements and/or instructions that are necessary to make your script run, which I would like very much to do.
Can anyone please point me to some help?
Nick
tel
Copy link to clipboard
Copied
Unfortunately I never had access to a computer with Mac OS. Also I do not have any experience on launching AppleSrcipt, as well as VBScript from Photoshop. Just try to design your script as a file with the extension ".jsx" and run it from Photoshop.
To help Scripting in Photoshop
Copy link to clipboard
Copied
Progress! I followed your recommendation. I copied and pasted the script into ExtendScript Toolkit CS6 4.2.12 (in the Adobe Photoshop CS6 folder) and saved it with .jsx in Adobe Photoshop CS6>Presets>Scripts.
After making a narrow horizontal selection in my image, I ran it through Photoshop>File>Browse>Scripts.
It runs through to line 17,
r.puyosemitetProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
It generates this Photoshop error:
Error 24: r.puyosemitetProperty is not a function.
and removes the selection dots from the image.
Being totally ignorant of java, I don't know what this means. Perhaps the function was omitted from the forum copy? Or comes from another script (I use OSX Yosemite 10.10.5)? I hope this is a trivial error in copying from the source that can be corrected easily. We're so close!
Please check the script in this forum against your source. Also, there may be more errors beyond line 17 that haven't been reached yet.
Thanks,
Nick
Copy link to clipboard
Copied
r-bin should help you, but for now I see there is something what shouldn't be in:
r.puyosemitetProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));
Copy link to clipboard
Copied
Yes! This made it work.
Your script was correct and your suggestion made it run.
I have no idea how "Yosemite" got into that line and caused the Photoshop error. I only copied and pasted the whole script.
You both made it successful. Thank you very much.
Nick
P.S. This summary might be helpful to others:
In Macintosh,
1. Copy and paste the script into any word processor or editor and save it by name.jsx in Adobe Photoshop CS6>Presets>Scripts.
2. Make a narrow horizontal selection in your image. (Optional: stroke the selection for reference.)
3. In Photoshop>File>Browse>Scripts, select your .script.
4. Click Open.
5. Look at your image. The plot is there (above the strokes, if you made them).