Page 3 of 4

Re: Lab colorspace - clipping

Posted: 2014-07-24T12:22:05-07:00
by jwtrexler
Snibgo, I'm not having success with your suggestion and am still experiencing the looping. I would like to have the format of the bin file such that I can drag-and-drop multiple images having them all processed. I'm reading the forum and trying to utilize your suggestion in various was to make the simple command work properly, but if you would provide me a little more direction, that would be awesome.

Thanks,
Jack

Re: Lab colorspace - clipping

Posted: 2014-07-24T18:31:35-07:00
by snibgo
What bin file?

Re: Lab colorspace - clipping

Posted: 2014-07-24T22:23:58-07:00
by jwtrexler
In my previous post, I wrote: I have created a bat file with exactly the same commands that works at the command line and am not having success getting it to run by drag and drop approach; when a drop the file, the bat file opens a command window that contiuously echos the command in a continuous loop. For example, if I create a bat file having: convert -verbose *.jpg then drag/drop a file called infile.jpg, the window opens and the continuous looping begins. I have read and tried many options to no avail. Your help/suggestions would be greatly appreciated. In reality, I am converting an infile to 16 bit, ti Cielab, splitting the channels, computing some statistics and creating a text output file for the statistics for each Cielab channel. The command line works fine, so I created a bin file with that script using a wildcard for the infile and outfile name hoping I could drag and drop several files onto the bin folder. Above, I indicated it was getting hung in a loop and you suggested "I might want to process 1%" instead". I'm not sure what you meant by this.

Re: Lab colorspace - clipping

Posted: 2014-07-24T22:58:41-07:00
by snibgo
jwtrexler wrote:... so I created a bin file with that script ...
Perhaps you mean you created a BAT file. Not a "bin" file.
jwtrexler wrote:... using a wildcard for the infile and outfile name hoping I could drag and drop several files onto the bin folder.
Not "bin folder", I hope.

The first argument to a BAT file is %1. Not a wildcard. A wildcard, as in "*.jpg", stands for all jpeg files. So you loop through all the jpeg files, and ignore the input argument.
jwtrexler wrote:... you suggested "I might want to process 1%" instead"
Not "1%" but "%1", the first argument to the BAT script file. I suggest you use %1 instead of *.jpg. This will process a single file that you drag-and-drop onto the BAT file.

If you want to process multiple files, these will appear to the BAT file as %2, %3 etc. Your BAT file will have a loop with the "shift" command to move each argument, one by one, to the %1 position.

I suggest you pick up a book on writing Windows BAT scripts. Once upon a time, Windows computers came with such books. Sadly, no longer.

Re: Lab colorspace - clipping

Posted: 2014-07-30T12:29:23-07:00
by jwtrexler
I have attempted to utilize you "SHIFT" suggestion in the following script on a Windows 7 machine. The script is generating output files as I hoped for using drag and drop, however it appears the script is not exactly right, as I never get to the PAUSE. Do you see any obvious errors? Also, I would like to add the mathematical transformation to the line so as to convert the %Lab values to their absolute values; my plan is to try utilizing the fx script, any suggestions would be appreciated. As always, thank you for you assistance.

@ECHO OFF
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
echo.
IF [%%1]==[] goto :eof
:loop
FOR %%1 IN (%*) do (convert %%1 -depth 16 -colorspace lab -separate -format "%%[fx:mean] \n" info:%%~dpn1.txt)
SHIFT
IF NOT [%%1]==[] GOTO loop
:eof
echo at end
PAUSE

Re: Lab colorspace - clipping

Posted: 2014-07-30T13:05:58-07:00
by snibgo
1. Don't do "@echo off" until you have finished debugging.

2. "%%1" is wrong. It should be "%1".

3. You are looping through all the inputs with your "GOTO loop". Fine. Each time round, you then loop through all the inputs again, with that "FOR" command. Why? You need one loop or the other, but not both. You can replace the "FOR ..." with:

Code: Select all

convert %1 -depth 16 -colorspace lab -separate -format "%%[fx:mean] \n" info:%~dpn1.txt
Now you do exactly one "convert" per input file.

Re: Lab colorspace - clipping

Posted: 2014-07-30T14:06:43-07:00
by jwtrexler
Yes Snibgo, that worked perfectly. As to why I was using a loop within a loop, I tried everything including (apparently mistakenly) your last input. Now I'll try adding commands to (1) mathematically convert from percent Lab values to the absolute and (2) create a histogram of the 3 respective values. As always, I do appreciate your help.

Re: Lab colorspace - clipping

Posted: 2014-07-30T14:15:19-07:00
by jwtrexler
I meant to "create a histogram of the three respective channels.

Re: Lab colorspace - clipping

Posted: 2014-07-31T16:20:21-07:00
by jwtrexler
My goal of the script below is to separate each channel to determine the mean value; my plan is to build on this to convert to a Cielab colorspace and expand the fx:mean function so as to output the absolute Lab values into the table rather than the percentage values. If only one of the convert commands are included in the script, the script will work fine when dragging and dropping a file onto the bat file. A couple questions: (1) do you see what is causing the script to fail when the three command lines, rather than one, are included and (2) am I overlooking a simpler means of separating the individual channel values so as to do the colorspace and mathematical transformation? Thanks in advance for the help.

REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
echo.
IF [%1]==[] goto :eof
:loop
convert %1 -colorspace rgb -channel r -separate -format "%%[fx: mean] \n"
convert %1 -colorspace rgb -channel g -separate -format "%%[fx: mean] \n"
convert %1 -colorspace rgb -channel b -separate -format "%%[fx: mean]" info:%~dpn1.txt
SHIFT
IF NOT [%1]==[] GOTO loop
:eof
echo at end
PAUSE

Re: Lab colorspace - clipping

Posted: 2014-07-31T16:48:02-07:00
by fmw42
Try adding info: and redirect to file for each command. (Also +channel after -separate in each channel command). The info: is needed and probably the issue. Not sure if +channel is really the issue, but it should not hurt and sometime is needed.

convert %1 -colorspace rgb -channel r -separate +channel -format "%%[fx: mean] info: > txtfile.txt \n"
convert %1 -colorspace rgb -channel g -separate +channel -format "%%[fx: mean] info: >> txtfile.txt \n"
convert %1 -colorspace rgb -channel b -separate +channel -format "%%[fx: mean] info: >> txtfile.txt \n"

Not sure about > and >> to redirect to file in Windows

You may also need to add 2>&1 after info: if IM is sending the text to std error rather than stdout. Not sure if this is what is used in Windows.

(I know very little about Windows and its scripting or command syntax)

Re: Lab colorspace - clipping

Posted: 2014-07-31T16:57:43-07:00
by fmw42
NOTE: edits above

You can write it all in one command if you want a list of each channel. For example:

Code: Select all

convert rose: -colorspace sRGB -separate +channel -format "%[mean]\n" info:
37448
22939.9
20680.4

If you have lab image, why are you converting to sRGB? I have not followed this whole thread. Just puzzled here.

Also depending upon your IM version, -colorspace RGB may be converting to linear RGB rather than perceptual sRGB.

Re: Lab colorspace - clipping

Posted: 2014-08-01T08:59:34-07:00
by jwtrexler
To fmw42: The file I am starting with is indeed a digital image of RGB format. In the script above, I was attempting to identify a simplified yet correctly functioning script to split channels independantly. When I'm able to do this, my intent is to convert the image using the -colorspace command, then incorporating the different mathematical operations within the fx:mean function to convert the L and the a & b percentages output by colorspace to absolute L*, a*, and b* values. Subsequently, I then want to write the L*, a*, and b* on separate lines to a txt ouput file.

With respect to the script, I am getting an error when I include all three lines that says:
convert.exc: missing an image file name %[fx: mean] \n' @ error/convert.c/ConvertImageCommand/3184.
The routine does pass through the PAUSE.

Thanks for your input and I'll keep trying.

Re: Lab colorspace - clipping

Posted: 2014-08-01T09:20:26-07:00
by fmw42
I missed one more thing. You need a closing " on each "%%[fx: mean]"

convert %1 -colorspace rgb -channel r -separate +channel -format "%%[fx: mean]" info: > txtfile.txt \n"
convert %1 -colorspace rgb -channel g -separate +channel -format "%%[fx: mean]" info: >> txtfile.txt \n"
convert %1 -colorspace rgb -channel b -separate +channel -format "%%[fx: mean]" info: >> txtfile.txt \n"

Re: Lab colorspace - clipping

Posted: 2014-08-01T09:30:52-07:00
by fmw42
You can still do it in one command as

Code: Select all

convert rose: -colorspace RGB -format "%[fx:mean.r] %[fx:mean.g] %[fx:mean.b]\n" info:
0.376896 0.148546 0.133416

values are in the range 0 to 1

or you can scale them to 255 or quantumrange by multiplying the mean

Code: Select all

convert rose: -colorspace RGB -format "%[fx:round(quantumrange*mean.r)] %[fx:round(quantumrange*mean.g)] %[fx:round(quantumrange*mean.b)]\n" info:
24700 9735 8743

Code: Select all

convert rose: -colorspace RGB -format "%[fx:round(255*mean.r)] %[fx:round(255*mean.g)] %[fx:round(255*mean.b)]\n" info:
96 38 34

If you want to keep fractional values, remove the round()

Re: Lab colorspace - clipping

Posted: 2014-08-01T10:48:22-07:00
by jwtrexler
Fmw42,
Update: I haven't been successful yet running the three line script you suggested in the post before last under Windows 7, but your single line suggestion in the last note looks much "cleaner", so I tried it. When I process a color swatch I created using Microsoft Paint having the rgb colors 104, 114, 114 using the last single line suggestion, the output does not reflect those respective values (i.e., 104,114,114); I did check using identify -verbose filename and it does give me the correct respective values. Also previously, I have been able to get the correct values when I'd reduce the 3-line script to 1 line. Any thoughts?

This bat script I'm using with drag and drop is:
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
echo.
IF [%1]==[] goto :eof
:loop
convert %1 -colorspace rgb -format " R = %%[fx:round(255*mean.r)]\n g = %%[fx:round(255*mean.g)]\n b = %%[fx:round(255*mean.b)] \n" info:%~dpn1.txt
SHIFT
IF NOT [%1]==[] GOTO loop
:eof
echo at end
PAUSE

The output is:
R = 35
g = 43
b = 44