I have limited experience with programming and Linux and I need your help.
The situation I am in is that I have a stack of black and white .tiff images (approx. 400 of 10 Mb each one) which I need to convert into xyz coordinates plus grayscale values and to compile all those in ONLY a single text file with x,y,z,grayscale (the z coordinates, this way: first image of the folder z=0000, second image 0001...as many z coordinates as images in the folder).
I have a script (that I am pretty unfamiliar with, but I think it is done with Image Magick) which can do it but only for a single image at a time, and adds only the x, y coordinates and a value in grayscale, but no z.
The script is:
The exact format of the TXT image is defined by the convert command, then 'tail' is used to junk the header, 'tr' to character replace every non-number character with a single space, so that the later 'while' can read it easily, junking any comment numbers that may have been left.
convert -depth 8 -colorspace RGB $1 txt:- | tail -n +2 | tr -cs '0-9.\n' ' ' | while read x y Gray junk; do if [ "$Gray" -eq 0 ]; then echo "$x,$y $Gray" done
To run it I put in the Linux terminal:
chmod +x img.sh
And after that (I selected the same name as the image but with .txt as filename):
./img.sh pic0000.tif > pic0000.txt
Also I tried to change it to do it all at once, replacing the line
convert -depth 8 -colorspace RGB $1 txt:- |
convert -depth 8 -colorspace RGB $* txt:- |
and putting this in the terminal
chmod +x ./img.sh ./img.sh *.tif > *.txt
And now it puts all the files in one with x y Grayscale, but I cannot add the z values.
By the way,it takes a long time to create the txt file.
The first lines of the final XYZ file must be, for example:
0 0 0 value in greyscale 1 0 0 value in greyscale `
and the last:
3095 2951 400 value in greyscale
Would you give me any clues, ideas or solutions to do it? Any help would be sincerely appreciated.