Page 4 of 4

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T10:32:21-07:00
by NicolasRobidoux
Fred:

Unlike Ligthen/Darken which in and by themselves can be done with greyscale versions of the images (thanks Anthony!), I don't think that clamp-locally can. The problem is similar to what happens with transparency: Suppose that the negative lobes of the resampling filter cause a pixel values to be (0,0,0) (in RGB, say). How do you lighten that? You have no colour information!

So, if you want to use the intensity, you have no choice but to convert to an image format with an "intensity" channel. (And then, live with the side effects, which are mild, basically non-existent if you compute in floating point.)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T10:36:05-07:00
by NicolasRobidoux
I have looked some more and I am more opimistic RE: the usefulness of the channel by channel (and the luminance channel) version of clamp-locally.

As it turns out, the flat plateaus created by the clamping are a bit too obvious to my taste.

However, blending with the plain resampled image (by taking the average of the clamped enlargement (say) and the "plain" enlargement) makes these plateaus unobstrusive.

Of course, the clamping effect is lessened, but nonetheles the worst over/undershoots are dampened, and a feeling of slight sharpening is actually created (because, sometimes, the halos/ripples can be perceived as a kind of blur).

Certainly not a "jump in your face effect," at least with the rose test picture, but nonetheless an improvement.

It is just that you need to remember not to drink it straight.

-----

The other good news is that it does not appear that using something more sophisticated than linear to resample the min and max values is needed. LBB is likely to improve matters, but probably in an unnoticeable way. (I am not particularly fond of Hermite...)

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T12:06:08-07:00
by NicolasRobidoux
Fred:

Let's let go of using the intensity and stick to channel by channel.

Would you be able to take the min/max over a 3x3 cross (the center and the closest four pixels, for a total of five pixels) instead of a 3x3 square?

nicolas

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T14:18:53-07:00
by NicolasRobidoux
Right now, I like this. It is mild, but it takes the "edge" off the haloing.

I think that "pure" clamp-locally may be better if one is using JPEG compression, but this remains to be seen.

Code: Select all

input="rose:"
filt="triangle"
convert $input \
\( -clone 0 -filter lanczos -resize 1600% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize 1600% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize 1600% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
-delete 0-3 pureclamplocal.png

convert $input -filter lanczos -resize 1600% lanczos.png

composite -blend 66.66% lanczos.png pureclamplocal.png clamplocal.png

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T15:43:30-07:00
by fmw42
this should do it in one command. check to be sure I don't have the percents reversed (as I sometimes get confused by Anthony's mixing of background/overlay vs dest/source)

Code: Select all

input="rose:"
filt="triangle"
convert $input \
\( -clone 0 -filter lanczos -resize 1600% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize 1600% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize 1600% \) \
\( -clone 1 -clone 2 -compose lighten -composite \
-clone 3 -compose darken -composite \) \
\( -clone 0 -filter lanczos -resize 1600% \) \
-delete 0-3 -compose blend -define compose:args=66.67%,33.33% -composite \
clamplocal.png
see http://www.imagemagick.org/script/compose.php and http://www.imagemagick.org/Usage/compose/#blend

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T19:52:06-07:00
by fmw42
fmw42 wrote:Processing Luminance in Rec709YCbCr

Code: Select all

infile="rose:"
fact=1800
convert $infile -filter lanczos -resize ${fact}% rose_lanczos_${fact}.png
Triangle/Bilinear

Code: Select all

infile="rose:"
filt="triangle"
fact=1800
convert $infile -colorspace Rec709YCbCr -separate \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 3 -clone 4 -compose lighten -composite \
-clone 5 -compose darken -composite \) \
\( -clone 1 -filter lanczos -resize $fact% \) \
\( -clone 2 -filter lanczos -resize $fact% \) \
-delete 0-5 -set colorspace Rec709YCbCr -combine \
-colorspace RGB rose_${filt}_${fact}_clamplocal_ycbcr.png

compare -metric rmse rose_lanczos_${fact}.png rose_${filt}_${fact}_clamplocal_ycbcr.png null:
150.326 (0.00229383)


Hermite:

Code: Select all

infile="rose:"
filt="hermite"
fact=1800
convert $infile -colorspace Rec709YCbCr -separate \
\( -clone 0 -filter lanczos -resize $fact% \) \
\( -clone 0 -statistic minimum 3x3 -filter $filt -resize $fact% \) \
\( -clone 0 -statistic maximum 3x3 -filter $filt -resize $fact% \) \
\( -clone 3 -clone 4 -compose lighten -composite \
-clone 5 -compose darken -composite \) \
\( -clone 1 -filter lanczos -resize $fact% \) \
\( -clone 2 -filter lanczos -resize $fact% \) \
-delete 0-5 -set colorspace Rec709YCbCr -combine \
-colorspace RGB rose_${filt}_${fact}_clamplocal_ycbcr.png

compare -metric rmse rose_lanczos_${fact}.png rose_${filt}_${fact}_clamplocal_ycbcr.png null:
151.032 (0.0023046)

Nicolas, you may want to change the colorspace to Rec601YCbCr and give that a try. See viewtopic.php?f=2&t=18485#p71136

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T21:35:39-07:00
by NicolasRobidoux
NicolasRobidoux wrote:Fred:

Unlike Ligthen/Darken which in and by themselves can be done with greyscale versions of the images (thanks Anthony!), I don't think that clamp-locally can. The problem is similar to what happens with transparency: Suppose that the negative lobes of the resampling filter cause a pixel values to be (0,0,0) (in RGB, say). How do you lighten that? You have no colour information!

So, if you want to use the intensity, you have no choice but to convert to an image format with an "intensity" channel. (And then, live with the side effects, which are mild.)
I think that the above is completely wrong.

P.S.

Retraction of my retraction:

Actually, I am pretty sure that clamp-locally can't be done using a greyscale version of the image. You must either clamp-locally every single channel (with the possible exception of alpha, although I would not see why), or only clamp-locally the luminance channel (and possibly the alpha channel) of the image converted to a suitable image format (like YCbCr).

The reason is that otherwise you may introduce colour discontinuities. Yuck!

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-07T21:40:55-07:00
by fmw42
Nicolas,

Did you see my code variant for you above at viewtopic.php?f=22&t=18458&start=45#p71128. Just want to be sure you did not skip over that. Hope it helps.

Fred

Re: halo minimization by local min/max smooth clamping

Posted: 2011-04-09T07:57:49-07:00
by NicolasRobidoux
I need to see how this works with line drawings and the like. No time now.