Hi Constandinos,
This can be done very easily in PixInsight. Take a look at the following script:
/*
* A script to obtain raw image histogram data as a text file in PixInsight.
*/
#include <pjsr/StdIcon.jsh>
#include <pjsr/StdButton.jsh>
function HistogramToTextFile( filePath, img, n )
{
if ( n == undefined || n < 2 )
n = 65536;
var H = new Histogram( n );
H.generate( img );
var A = H.toArray();
var f = new File;
f.createForWriting( filePath );
for ( var i in A )
f.outTextLn( A[i].toString() );
f.close();
}
function main()
{
var window = ImageWindow.activeWindow;
if ( window.isNull )
{
(new MessageBox( "There is no active image window.",
"HistogramAsTextFile Script",
StdIcon_Error, StdButton_Ok )).execute();
return;
}
HistogramToTextFile( "/tmp/my-test-histogram.txt", window.currentView.image );
}
main();
To use the script, save it anywhere on your filesystem and load it with PixInsight's Script Editor. First you have to edit the script to specify the output file name you want. On line 34 of the script you have the following:
HistogramToTextFile( "/tmp/my-test-histogram.txt", window.currentView.image );
Just change the text between double quotes to meet your needs. The default file name will work for any Linux/UNIX system, including Mac OS X. On Windows, there is no "/tmp" system folder so you could use something like "C:/histogram.txt".
Open an image and run the script (from the Script Editor window, select Execute > Compile and Run, or press the corresponding key (F9 on Linux/UNIX and Windows; ^R on Mac OS X)). Note that the script generates a text file with as many lines as histogram levels have been defined (65536 by default). Each line contains the number of pixels that have the corresponding value in the image.
The script works for the first image channel only. This is OK for grayscale images but not ideal for color images. The script can be modified very easily to loop over all channels, if required.
Hope this helps.