Different results manually & batch

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
xover5

Different results manually & batch

Post by xover5 »

I´m really absolutely confused. Using mogrify or a single convert produces different results all the time, i know. But even if i run a script (bat or cmd, Windows 7), that´s opening a new cmd for each convert-process, the result is not nearly as good as a convert command manually invoked in cmd.exe.

The command I´m using is "convert <source> -channel RGBA -contrast-stretch 1% -quality 100 <destination>" which delivers amazing results used with underwater-pictures. But, as I already mentioned, only if it´s invoked manually.

I already thought about differences using ' or " (I´m running a german version of windows) etc. But I don´t get it.

To show what it´s about (original, manually invoked, invoked via batch):

Image

Any idea/suggestion/explanation would absolutely be appreciated, thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different results manually & batch

Post by fmw42 »

I am not a windows user nor understand Batch files, but you might post your command so others can examine it.

also see http://www.imagemagick.org/Usage/windows/
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Different results manually & batch

Post by GreenKoopa »

The % symbol has special meaning in Windows batch files and needs to be escaped to %%.
xover5

Re: Different results manually & batch

Post by xover5 »

Thanks for replying.
I tried many different ways of invoking. For example a simple singlePic.cmd containing just

Code: Select all

convert <filename> -channel RGBA -contrast-stretch 1% -quality 100 <targetFilename>
. If i just copy this and invoke manually the result is perfect. Ran by double-clicking it´s awful.

After testing different solutions my script actually looks like this

Code: Select all

for %%i in (*) do if not "%%i"=="%~nx0" cmd.exe /C convert %%~i %order% %%~ni%suffix%
where order=-channel RGBA -contrast-stretch 1% -quality 100 and suffix=-edited.png. "cmd.exe /C" because there might be differences while executing many pics in a single shell.
% is used like it´s meant to be (i guess). And the script works quite well at all. It´s just the different result I´m wondering about.
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Different results manually & batch

Post by GreenKoopa »

Did you try
convert source_filename -channel RGBA -contrast-stretch 1%% -quality 100 destination_filename
xover5

Re: Different results manually & batch

Post by xover5 »

OMG...Many, many thanks pal. I was just 2 blind 2 see, using -contrast-stretch 1%% is the clue.

If someone is interested in the whole script (All files in the folder, except the script itself, are converted with parameter from sourcefile to <sourcename>-edited.png:

Code: Select all

@echo off
echo.
title TauchbildConverter
set suffix=-edited.png
set filename=%cd%
:cutname
set testname=%filename%
set filename=%filename:*\=%
set parameter=-channel RGBA -contrast-stretch 1%% -quality 100
if not "%filename%"=="%testname%" goto :cutname
if "%cd:*\=%"=="" set /p filename=Name to add: && echo.
echo.List of new filenames:
echo.
for %%i in (*) do if not "%%i"=="%~nx0" echo."%%~ni%suffix%"
echo.
echo.
echo.Press any key to start converting
pause >nul
for %%i in (*) do if not "%%i"=="%~nx0" cmd.exe /C convert %%~i %parameter% %%~ni%suffix%
echo.
echo.Press any key to end
pause >nul
goto :eof
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: Different results manually & batch

Post by GreenKoopa »

Sorry I wasn't more clear about escaping %s in my first post. When oddness happens in a batch file, it helps to pause at the end or redirect the output so that you are able to examine what command was actually executed after all substitutions were made. You are not the first person to stumble over this. In fact, there was a post earlier this week and I have wasted an embarrassing amount of time on it. The side effects of forgetting to escape a % can be subtle since no hard error is thrown. A Windows developer might have have chosen the format -contrast-stretch 0.01 over -contrast-stretch 1%.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Different results manually & batch

Post by fmw42 »

convert <filename> -channel RGBA -contrast-stretch 1% -quality 100 <targetFilename>
As you have included -channel RGBA (or even -channel RGB), then -contrast stretch will stretch each channel separately. It appears you need to stretch all the channels in concert. To do that leave off the -channel RGBA. Try that.

This seems to give me something close to what you want, you may want a higher percent on the -contrast-stretch

convert scuba.jpg -contrast-stretch 1% scuba_cs1.jpg


You can use -level or -brightness-contrast to get similar results to what you want.
Post Reply