Page 2 of 2

Posted: 2006-12-07T18:32:30-07:00
by anthony
Interesting script. Though Cristy may be looking into implementing your request on the weekend, no promises however.

I noticed that you use -bias {number} -convolve 1

Can you eaplain exactly what this does, so it can be documented in IM Examples.

Is it like a -evaluate subtract but using pixel values, rather than a normalized color range?

Could the -convolve operator also be used for -evaluate multiply and merge the two operators in your example?

ActuallyI know so little about -convolve (as I haven't used it myself) that I would love input on how to explain it in IM Examples.

Posted: 2006-12-08T08:01:41-07:00
by cra3y
anthony wrote: I noticed that you use -bias {number} -convolve 1

Can you eaplain exactly what this does, so it can be documented in IM Examples.


this trick cause move histogram to left, when bias below zero or to right, when bias is above zero.
-convolve 1 - value 1 in convolve kernel cause no operation to surrounding pixels, but only to pixel which is processed.

with multiply below 1 I shrink histogram from right side to left, then with positive bias (in 1 to 65535) i move histogram to middle, controlling this process manually - command +contrast perform similar way, but with unknown multiplier and bias

with more complex convolution kernels You can do sharpening, blurring, embos images.

look at links below, i learned convolution process from this links:
http://www.gamedev.net/reference/progra ... /page2.asp
http://www.dfanning.com/ip_tips/sharpen.html

blurring using kernel

Code: Select all

0,1,0
1,1,1
0,1,0

Code: Select all

convert source.tif -bias 0 -convolve 0,1,0,1,1,1,0,1,0 -quality 96 blur.jpg
sharpening using laplacian kernel

Code: Select all

-1,-1,-1
-1,9,-1
-1,-1,-1

Code: Select all

convert source.tif -bias 0 -convolve -1,-1,-1,-1,9,-1,-1,-1,-1 -quality 96 sharpening.jpg
sharpening using laplacian kernel - extracting sharpening mask

Code: Select all

-1,-1,-1
-1,8,-1
-1,-1,-1

Code: Select all

convert source.tif -bias 32767 -convolve -1,-1,-1,-1,8,-1,-1,-1,-1 -quality 96 sharpening-mask.jpg
emboss using kernel

Code: Select all

-1,-1,0
-1,0,1
0,1,1

Code: Select all

convert source.tif -bias 0 -bias 32767 -convolve -1,-1,0,-1,0,1,0,1,1 -quality 96 blur.jpg
emboss using kernel, then darkening using bias (move histogram to left)

Code: Select all

-1,-1,0
-1,0,1
0,1,1

Code: Select all

convert source.tif -bias 0 -bias 10000 -convolve -1,-1,0,-1,0,1,0,1,1 -quality 96 blur.jpg

Posted: 2006-12-10T18:39:47-07:00
by anthony
Thankyou for the info. Hopefully I can now write up a n introduction to the general 'convolve' operator in IM for IM Examples.


Question: do you think
convolve 0,0,0,0,.5,0,0,0,0
should produce a 'dark' image, or should it be automatically normalized.

This was a bug report I put in last time I was looking at all this (about 6 months ago). I don't think it should, and asked that aspect be removed.

Posted: 2006-12-10T18:46:34-07:00
by anthony
Download the very LATEST IM beta. (dated Dec 9 or later) and check the addition Cristy made. -linear-stretch 10%-90%

My own test was inconclusive, Better check what -contrast-stretch is now doing.

Posted: 2006-12-12T08:08:44-07:00
by cra3y
anthony wrote: Download the very LATEST IM beta. (dated Dec 9 or later) and check the addition Cristy made. -linear-stretch 10%-90%


hmm, i tested 6.3.1-1 version from 10 Dec, both linear-stretch and contrast-stretch perform the same way - as linear-stretch before (not as my script)

Posted: 2006-12-12T08:12:51-07:00
by magick
The -linear-stretch option is experimental. You/Anthony can discuss how it should behave and we'll make changes as needed.

Posted: 2006-12-12T08:25:26-07:00
by cra3y
magick wrote: The -linear-stretch option is experimental. You/Anthony can discuss how it should behave and we'll make changes as needed.


ok, i think, it should behave as my script in previous page.
it would necessary two parameters - how much (percent?) discard in dark/highlight, then adjust -levels to obtain poper normalization effect (like in Gimp in previous page)

Posted: 2006-12-12T12:12:27-07:00
by magick
The linear stretch is in fact linear stretch with saturation which pushes the bottom and top colors into black or white. All colors in between are then linearly interpolated. If you want it to behave differently we need a precise algorithm.

Posted: 2006-12-12T13:16:18-07:00
by cra3y
magick wrote: The linear stretch is in fact linear stretch with saturation which pushes the bottom and top colors into black or white. All colors in between are then linearly interpolated. If you want it to behave differently we need a precise algorithm.


ok, let's go
passed parameters is number of pixels to discard in low and high threshold (for original image converted into 1mpix)

convert in.tif -linear-stretch 160x260 +compress out.tif

where first describes, how much pixels (from converted source into 1mpix) we will discard below bottom level (0 - zero- black)
where second describes, how much pixels (from converted cource into 1mpix) we will discard above top level (65536 - white)

Code: Select all

1) resize into 1mpix (1280x900) and convert image into greyscale - this step show real luminance of the picture

2) generate histogram into table in format:
   value of pixel, number of pixels with this value 
   (something like result from:convert in.tif -format %c histogram:info:- | sort -k2)

   for example:
    21:2
    25:8
    27:40
    30:128
    .
    .
    230:12380
    233:8003
    234:523
    245:12

3)find low threshold by this algorithm:

   $total_discard_low=0;$user_discard_low=160; //first parameter
   get_first_pair_from_histogram_table($current_pixel_value,$current_number_pixels); //(ouutch! ;-) )

   while($total_discard_low<$user_discard_low){

      $cut_low_value=$current_pixel_value;

      $total_discard_low+=$current_number_pixels;

      get_next_pair_from_histogram_table($current_pixel_value,$current_number_pixels);

   }

4)find high threshold by this algorithm:

   $total_discard_high=0;$user_discard_high=260; //second parameter
   get_last_pair_from_histogram_table($current_pixel_value,$current_number_pixels); //(ouutch! ;-) )

   while($total_discard_high<$user_discard_high){

      $cut_high_value=$current_pixel_value;

      $total_discard_high+=$current_number_pixels;

      get_prev_pair_from_histogram_table($current_pixel_value,$current_number_pixels);

   }

5) perform normalize to source image by:

    -level $cut_low_value*256,$cut_high_value*256 //because level get 16bit values
that's all, this algorithm works well like one in previous page of this thread

maybe i should use percents or promils of total pixels of source image, therefore downsize is not necessary , for example: -linear-stretch 0.0002x0.0008

Re: Problem with normalizing channels in concert

Posted: 2007-02-09T06:25:47-07:00
by Scott.Prog
Sorry to revive a stale topic but did this ever get implemented? I've checked the latest IM build (6.3.2) and the operators discussed don't appear to be incorporated.

Re: Problem with normalizing channels in concert

Posted: 2007-02-09T06:38:01-07:00
by cra3y
yes, it still not implemented ... :-(

Re: little extra note

Posted: 2007-06-25T05:01:15-07:00
by JoaCHIP
anthony wrote:Okay in sumary you desire is...

Where -contrast-stretch is expands from the point a percentage inward from the highest 'peak' colors, a -histogram-stretch would expand the points given by having a percentage of pixels (histogram)

EG: -histogram-stretch 5% would strecth the colors so as to peg the 5% brightest pixels and 5% darkest pixels to white and black.
That would be great. But please be aware that the values needed here are very small, so you should allow values like 0.05% and 0.2% etc.

Playing around with the the Levels menu (Ctrl-L) in Photoshop and the auto-function (press Ctrl and click on Auto) should reveal to you how sensitive this value is on certain images.

A good default value would probably be 0.5% for both black-point and white-point. Currently i tried -normalize and it sometimes blows out highlights a little bit more than i like.

PS: If you do manage to implement this nice feature, please elaborate a little bit more on the differences between -normalize, -contrast-stretch and -linear-stretch in the documentation web page, as this is currently not explained at all.

Re: Problem with normalizing channels in concert

Posted: 2007-06-25T18:19:44-07:00
by anthony
The whole area and concepts of these functions needs to be looked at and improved (Volunters welcome). I have only given some minor writeup and examples in IM Examples, Color modifications http://www.imagemagick.org/Usage/color/#normalize
but did not go further as the concepts are so ill-defined, badly named, and un-useful.

Comments?

The inputs are floating point so .05% should work fine. You can even use absolute values like 5 (meaning dependant on if you are using IM Q8 or IM Q16) rather than a normalized percentage of the color range.