Convert contrast stretch option

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
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Convert contrast stretch option

Post by diaadi »

Hi all,
Is there a difference between "normalize" and
"contrast-stretch" option?
What does the % value mean in contrast-stretch?
For e.g. If I say convert -contrast-stretch 5% inp.tiff output.tiff , what does 5 mean here??
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert contrast stretch option

Post by fmw42 »

Normalize is contrast-stretch with specific arguments. In contrast-stretch the values are either % counts from either side of the histogram or without the %, actual count values.

So normalize is contrast-stretch 2%x1%, which means clip the bottom 2% of the histogram (at the black side) and clip 1% of the histogram (at the white side). This means count from each end of the histogram that % of counts and get the bin (gray level) at that value and stretch the histogram such that the bottom value goes to black and the top value goes to white.
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Re: Convert contrast stretch option

Post by diaadi »

fmw42,
Could you elaborate a litte more ?
What is getting "bin" ? Also if I simple give single number like just 5% (and not 5%x1% or 5%x2%) what would be the default value for 2nd number ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert contrast stretch option

Post by fmw42 »

A histogram is divided into bins that may contain more than one graylevel. So a bin is a group of 1 or more consecutive graylevels for which all the counts are combined. Lets say your image has 1024 graylevels (colors), then for a 256 bin histogram, each bin would accumulate counts from 4 successive graylevels. Please read up on histograms.

If you only provide one value, it is used for both the low and high ends of the histogram. So if you provide 2% only, then it is like 2%x2%.
diaadi
Posts: 7
Joined: 2015-05-07T01:56:45-07:00
Authentication code: 6789

Re: Convert contrast stretch option

Post by diaadi »

Thanks for the reply fmw42.
Post Reply