Skip to main content
August 4, 2010
Question

Analyzing binary image - quick way to determine number of consecutive white pixels?

  • August 4, 2010
  • 5 replies
  • 2075 views

Using ESTK and ExtendScript.

I want to determine the length of each white area intercepted by a 1px wide line through a grayscale image following a threshold operation.  Currently stepping through each pixel and checking the histogram count at intensity[0], but it's slower than my limited patience can tolerate.  Is there a good chord length or similar algorithm or a faster method to evaluate individual pixels than a for or while loop?

Thanks for any help...

This topic has been closed for replies.

5 replies

August 12, 2010

For what it's worth, I solved my problem with a script and a plugin from Reindeer Graphics.  Saved the image as a tab delimited text file, opened the file, parsed the lines and stepped through the intensities.  Works like a champ.

Thanks for the responses and the help.

Participating Frequently
August 12, 2010

Hi could someone point me how to script the measurements log, i do have an action that records the log but am having difficulty outputing the log.

Thanks

Inspiring
August 12, 2010

var f = new File('~/Desktop/measurement.log');

exportMeasurement( f );

function exportMeasurement( fileObject ) {
    var desc = new ActionDescriptor();
    desc.putPath( charIDToTypeID('File'), fileObject );
    executeAction( stringIDToTypeID('exportMeasurements'), desc, DialogModes.NO );
};

Participating Frequently
August 12, 2010

Thanks for the script, I'm on a Mac would this matter? Or does this script only work in windows

Participating Frequently
August 4, 2010

Another way to quickly get the number of white pixels in a selection is

to use the Analysis tools in PS Extended. The workflow is something like this:

1. Analysis > Set Measurement Scale = Default, to make sure pixels is the measurement logical unit

2. Analysis > Select Data Points > Custom: click on Deselect All, then under Selections, select Area

3. create selections from your white areas

4. Analysis > Record Measurements: this will show the Measurement Log panel, with the area values of each selection, which represent the number of pixels you want to count.

An extra number which is the sum of all areas will also show in this log.

Hope this works for you, give it a try.

Inspiring
August 4, 2010

The Measurement Log may work. There is limited script access to the log. But if that works for you in the GUI we can try to come up with a scripting solution.

For the plug-in and SDK questions you might be better off asking in the SDK forum. http://forums.adobe.com/community/photoshop/photoshop_sdk

Participating Frequently
August 4, 2010

To script the log, you can export the measurement data, which is scriptable, then read back the export file and parse it.

Domnita Petri

Photoshop QE

Participating Frequently
August 4, 2010

Photoshop Extended has a MATLAB interface, which allows image analysis & processing at the binary level. The specific function to get the pixels values is psgetpixels(), which returns the pixels values. You can then easily browse through these values and do your analysis.

The only setback is that you need MATLAB, which is not a trivial program, very expensive and well-guarded by MathWorks.

August 4, 2010

I'm afraid throwing third party software into the mix is not going to fly; need to have a stand alone solution preferably in Photoshop.

Downloaded the Photoshop SDK and wading through trying to write a plugin w/ VS2010 C++ Express edition.  If there's a script solution, I'd prefer it...

Thanks and please keep commenting...

Inspiring
August 4, 2010

A sample image might help but for the most part scripting is just not suitable for this type of analytical processing.

August 4, 2010

So I'm guessing a plugin would be a route?  Do you know if the Photoshop API is exposed to the Express version of MS Visual Studio?