Page 1 of 1

convert -normalize , ignore edges without crop

Posted: 2016-04-18T04:26:27-07:00
by pet
hello all...,

give it a solution tu use [convert -normalize] but ignore any edges of a image ?

for example:
only calculate 85% (yellow part) of the image and ignore 15% of the edges.
the result have to be like my image out.jpg, (but with the edges !!) .

my example image in.jpg , white or black areas (edges) can significantly skew the calculation of color balance if not ignored.
the wrong output is the same like the in-file :?

Image

greetings from Switzerland

pet

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T06:20:03-07:00
by snibgo
"-normalize" builds a histogram and calculates from that what "-level" is required, and applies that "-level". (Internally, it doesn't use "-level", but takes a short cut to do the same thing.)

You want to crop your image for the "-normalize", but apply the "-level" to the entire image.

Sadly, the "-normalize" command can't tell you what "-level" is uses.

I think the best way is as follows:

1. Crop the image.
2. Normalize the crop.
3. Use the technique I show on my "Gain and Bias" page to find what "-level" was applied.
4. Apply that "-level" to the entire image.

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T07:01:28-07:00
by pet
many thanks for the help.
i understand the point 1. and 2.
and i think i understand the way from 3. and 4.
on the hompage "Gain and Bias" i can see that i have to read the infos of the image, but i dont understand, how i can do it with (-level)
can you give me a example ?
or is necessary to develop a great script ?

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T07:31:16-07:00
by snibgo
Yes, it needs a script. My scripts are for Windows BAT. What do you use? BAT? Bash? Something else?

My scripts are quite complex because they cope with transparency in the input image, and they process the colour channels separately (to adjust colour balance). They can be simplified when the image is entirely opaque, and when you want to apply the same transformation to all three channels. Something like:

Code: Select all

convert in.png -format "%[fx:mean] %[fx:standard_deviation]" info:
Do this for the crop, and for the normalized crop. These four numbers can be used to calculate the numbers for "-level".

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T08:37:08-07:00
by snibgo
Here is a complete Windows BAT script. Adjust SRC and sCROP as required. The output is written to out.png. The line

Code: Select all

+write x.png ^
... isn't required, and can be removed. It may be useful to check you are cropping the correct area, and that it normalizes well.

"-function Polynomial" takes parameters that are more convenient than "-level", but it has the same effect.

Code: Select all

set SRC=toes.png

set sCROP=-gravity Center -crop 50%%x50%%+0+0 +repage

for /F "usebackq" %%L in (`%IM%convert ^
  %SRC% ^
  %sCROP% ^
  -format "MN0=%%[fx:mean]\nSD0=%%[fx:standard_deviation]\n" ^
  +write info: ^
  -normalize ^
+write x.png ^
  -format "MN1=%%[fx:mean]\nSD1=%%[fx:standard_deviation]\n" ^
  info:`) do set %%L

for /F "usebackq" %%L in (`%IM%identify ^
  -format "GAIN=%%[fx:%SD1%/%SD0%]\nBIAS=%%[fx:%MN1%-%MN0%*%SD1%/%SD0%]"
  xc:`) do set %%L

%IM%convert %SRC% -function Polynomial %GAIN%,%BIAS% out.png

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T08:48:00-07:00
by pet
wow... thank for the script-example.
i work with linux (bash) but i think i can translate the windows- to the shell-bash script.
and try a picture :)

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T09:18:39-07:00
by snibgo
Translating to bash is trivial:

Code: Select all

SRC=toes.png

sCROP="-gravity Center -crop 50%%x50%%+0+0 +repage"

declare `convert \
  $SRC \
  $sCROP \
  -format "MN0=%[fx:mean]\nSD0=%[fx:standard_deviation]\n" \
  +write info: \
  -normalize \
+write x.png \
  -format "MN1=%[fx:mean]\nSD1=%[fx:standard_deviation]\n" \
  info:`

declare `identify \
  -format "GAIN=%[fx:$SD1/$SD0]\nBIAS=%[fx:$MN1-$MN0*$SD1/$SD0]" \
  xc:`

convert $SRC -function Polynomial $GAIN,$BIAS g.png

Re: convert -normalize , ignore edges without crop

Posted: 2016-04-18T09:50:26-07:00
by pet
thanks, it works perfect for me !
does exactly what I need :D :D

another question: can you make little 'IM' jobs for me ?
I still have some work where I have no solutions ....
I like to pay for good solutions
or you know who make it


pet